diff --git a/compiler-core/src/format/tests.rs b/compiler-core/src/format/tests.rs index 063ae63c779..e36c613ee19 100644 --- a/compiler-core/src/format/tests.rs +++ b/compiler-core/src/format/tests.rs @@ -6435,3 +6435,220 @@ fn big_grapheme_cluster() { "# ); } + +#[test] +fn echo() { + assert_format!( + "fn main() { + echo +} +" + ); +} + +#[test] +fn echo_with_value() { + assert_format!( + r#"fn main() { + echo value +} +"# + ); +} + +#[test] +fn echo_with_big_value_that_needs_to_be_split() { + assert_format!( + r#"fn main() { + echo [ + this_is_a_long_list_and_requires_splitting, + wibble_wobble_woo, + multiple_lines, + ] +} +"# + ); +} + +#[test] +fn echo_inside_a_pipeline() { + assert_format!( + r#"fn main() { + wibble + |> echo + |> wobble +} +"# + ); +} + +#[test] +fn echo_with_value_inside_a_pipeline() { + assert_format!( + r#"fn main() { + wibble + |> echo value + |> wobble +} +"# + ); +} + +#[test] +fn echo_with_long_value_inside_a_pipeline() { + assert_format_rewrite!( + r#"fn main() { + wibble + |> echo this_is_a_looooooooong_value(that_get_split_on_multiple_lines, i_wonder_how_this_will_look) + |> wobble +} +"#, + r#"fn main() { + wibble + |> echo this_is_a_looooooooong_value( + that_get_split_on_multiple_lines, + i_wonder_how_this_will_look, + ) + |> wobble +} +"#, + ); +} + +#[test] +fn echo_inside_a_single_line_pipeline() { + assert_format!( + r#"fn main() { + wibble |> echo |> wobble +} +"# + ); +} + +#[test] +fn echo_with_value_inside_a_single_line_pipeline() { + assert_format!( + r#"fn main() { + wibble |> echo value |> wobble +} +"# + ); +} + +#[test] +fn echo_with_long_value_inside_a_single_line_pipeline() { + assert_format_rewrite!( + r#"fn main() { + wibble |> echo this_is_a_looooooooong_value(that_get_split_on_multiple_lines, i_wonder_how_this_will_look) |> wobble +} +"#, + r#"fn main() { + wibble + |> echo this_is_a_looooooooong_value( + that_get_split_on_multiple_lines, + i_wonder_how_this_will_look, + ) + |> wobble +} +"# + ); +} + +#[test] +fn echo_as_last_item_of_pipeline() { + assert_format!( + r#"fn main() { + wibble |> wobble |> echo +} +"# + ); +} + +#[test] +fn echo_with_value_as_last_item_of_pipeline() { + assert_format!( + r#"fn main() { + wibble |> wobble |> echo value +} +"# + ); +} + +#[test] +fn echo_with_long_value_as_last_item_of_pipeline() { + assert_format_rewrite!( + r#"fn main() { + wibble |> wobble |> echo this_is_a_looooooooong_value(that_get_split_on_multiple_lines, i_wonder_how_this_will_look) +} +"#, + r#"fn main() { + wibble + |> wobble + |> echo this_is_a_looooooooong_value( + that_get_split_on_multiple_lines, + i_wonder_how_this_will_look, + ) +} +"# + ); +} + +#[test] +fn echo_as_last_item_of_multiline_pipeline() { + assert_format!( + r#"fn main() { + wibble + |> wobble + |> echo +} +"# + ); +} + +#[test] +fn echo_with_value_as_last_item_of_multiline_pipeline() { + assert_format!( + r#"fn main() { + wibble + |> wobble + |> echo value +} +"# + ); +} + +#[test] +fn echo_with_long_value_as_last_item_of_multiline_pipeline() { + assert_format_rewrite!( + r#"fn main() { + wibble + |> wobble + |> echo this_is_a_looooooooong_value(that_get_split_on_multiple_lines, i_wonder_how_this_will_look) +} +"#, + r#"fn main() { + wibble + |> wobble + |> echo this_is_a_looooooooong_value( + that_get_split_on_multiple_lines, + i_wonder_how_this_will_look, + ) +} +"# + ); +} + +#[test] +fn echo_with_related_expression_on_following_line() { + assert_format_rewrite!( + r#"fn main() { + panic as echo + "wibble" +} +"#, + r#"fn main() { + panic as echo "wibble" +} +"# + ); +}