Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

gleam / format / src / tests / pipeline.rs
2.4 kB 137 lines
1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2024 The Gleam contributors 3 4use crate::{assert_format, assert_format_rewrite}; 5 6#[test] 7pub fn single_line_pipeline_longer_than_line_limit_gets_split() { 8 assert_format_rewrite!( 9 r#"pub fn main() { 10 wibble |> wobble |> loooooooooooooooooooooooooooooooooooooooooooong_function_name 11} 12"#, 13 r#"pub fn main() { 14 wibble 15 |> wobble 16 |> loooooooooooooooooooooooooooooooooooooooooooong_function_name 17} 18"#, 19 ); 20} 21 22#[test] 23pub fn single_line_pipeline_shorter_than_line_limit_is_kept_on_a_single_line() { 24 assert_format!( 25 r#"pub fn main() { 26 wibble(1) |> wobble 27} 28"# 29 ); 30} 31 32#[test] 33pub fn multi_line_pipeline_is_split_no_matter_the_length() { 34 assert_format!( 35 r#"pub fn main() { 36 wibble(1) 37 |> wobble 38} 39"# 40 ); 41} 42 43#[test] 44pub fn adding_a_newline_to_a_pipeline_splits_all() { 45 assert_format_rewrite!( 46 r#"pub fn main() { 47 wibble |> wobble 48 |> wabble 49} 50"#, 51 r#"pub fn main() { 52 wibble 53 |> wobble 54 |> wabble 55} 56"#, 57 ); 58} 59 60#[test] 61pub fn multiline_function_inside_pipeline_function_argument_is_indented_properly() { 62 assert_format!( 63 r#"pub fn main() { 64 function( 65 arg0, 66 thing 67 |> string.replace( 68 "{something something}", 69 date.month_to_string(month, config.l10n.context), 70 ), 71 ) 72} 73"#, 74 ); 75} 76 77#[test] 78pub fn multiline_function_inside_pipeline_in_list_is_indented_properly() { 79 assert_format!( 80 r#"pub fn main() { 81 [ 82 item1, 83 thing 84 |> string.replace( 85 "{something something}", 86 date.month_to_string(month, config.l10n.context), 87 ), 88 ] 89} 90"#, 91 ); 92} 93 94#[test] 95pub fn multiline_function_inside_pipeline_in_tuple_is_indented_properly() { 96 assert_format!( 97 r#"pub fn main() { 98 #( 99 item1, 100 thing 101 |> string.replace( 102 "{something something}", 103 date.month_to_string(month, config.l10n.context), 104 ), 105 ) 106} 107"#, 108 ); 109} 110 111#[test] 112fn pipe_with_labelled_first_argument_capture() { 113 assert_format!( 114 "fn wibble(label1 a, label2 b, lots c, of d, labels e) { 115 a + b * c - d / e 116} 117 118fn main() { 119 1 |> wibble(label1: _, label2: 2, lots: 3, of: 4, labels: 5) 120} 121" 122 ); 123} 124 125#[test] 126fn pipe_with_labelled_only_argument_capture() { 127 assert_format!( 128 "fn wibble(descriptive_label value) { 129 value 130} 131 132fn main() { 133 42 |> wibble(descriptive_label: _) 134} 135" 136 ); 137}