diff --git a/compiler-core/src/format/tests.rs b/compiler-core/src/format/tests.rs index 7ea0d1c6cd1..880d557c7ef 100644 --- a/compiler-core/src/format/tests.rs +++ b/compiler-core/src/format/tests.rs @@ -6,6 +6,7 @@ mod bit_array; mod blocks; mod cases; mod conditional_compilation; +mod custom_type; mod external_fn; mod external_types; mod function; @@ -257,85 +258,6 @@ type Many(a) = ); } -#[test] -fn custom_types() { - assert_format!( - "type WowThisTypeHasJustTheLongestName( - some_long_type_variable, - and_another, - and_another_again, -) { - Make -} -" - ); - - assert_format!( - "type Result(a, e) { - Ok(a) - Error(e) -} -" - ); - - assert_format!( - "type Result(a, e) { - Ok(value: a) - Error(error: e) -} -" - ); - - assert_format!( - "type SillyResult(a, e) { - Ok( - first_value_with_really_long_name: a, - second_value_with_really_long_name: a, - ) - Error(error: e) -} -" - ); - - assert_format!( - "type SillyResult(a, e) { - Ok( - first_value_with_really_long_name: a, - second_value_with_really_long_name: List( - #(Int, fn(a, a, a, a, a, a, a) -> List(a)), - ), - ) - Error(error: e) -} -" - ); - - assert_format!( - "type X { - X( - start: fn() -> a_reall_really_long_name_goes_here, - stop: fn() -> a_reall_really_long_name_goes_here, - ) -} -" - ); - - assert_format!( - "pub opaque type X { - X -} -" - ); - - assert_format!( - "/// -pub type Option(a) { - None -} -" - ); -} - #[test] fn expr_fn() { assert_format!( @@ -3325,49 +3247,6 @@ type Whatever = ); } -#[test] -fn doc_comments_7_test() { - assert_format!( - r#"import one - -/// one -///two -type Whatever { - Whatever -} -"# - ); -} - -#[test] -fn comments1() { - assert_format!( - r#"import one - -// one -//two -type Whatever { - Whatever -} -"# - ); -} - -#[test] -fn comments2() { - assert_format!( - r#"import one - -// one -//two -/// three -type Whatever { - Whatever -} -"# - ); -} - #[test] fn comments3() { assert_format!( @@ -3402,38 +3281,6 @@ fn whatever() -> Nil ); } -#[test] -fn comments6() { - assert_format!( - r#"// one -//two -type Thingy -"# - ); -} - -#[test] -fn comments7() { - assert_format!( - r#"// one -//two -type Thingy -"# - ); -} - -#[test] -fn comments8() { - assert_format!( - r#"// one -//two -type Whatever { - Whatever -} -"# - ); -} - #[test] fn comments9() { assert_format!( @@ -3445,29 +3292,6 @@ type Whatever = ); } -#[test] -fn comments10() { - assert_format!( - r#"// zero -import one - -// one -//two -type Whatever { - Whatever -} -"# - ); - - assert_format!( - "fn main() { - // Hello - \"world\" -} -" - ); -} - #[test] fn comment23() { assert_format!( @@ -4936,24 +4760,6 @@ pub fn main() { ); } -// https://github.com/gleam-lang/gleam/issues/1757 -#[test] -fn multiple_line_custom_type_constructor_field_doc_comments() { - assert_format!( - r#"pub type Thingy { - Thingy( - /// One? - /// One! - one: One, - /// Two? - /// Two! - two: Two, - ) -} -"# - ); -} - // https://github.com/gleam-lang/gleam/issues/1872 #[test] fn multiple_line_spread_list_comments() { @@ -5361,17 +5167,6 @@ fn comment_at_end_of_type() { ); } -#[test] -fn deprecated_custom_type() { - assert_format!( - r#"@deprecated("Deprecated type") -pub type One { - One -} -"# - ); -} - #[test] fn deprecated_type_alias() { assert_format!( diff --git a/compiler-core/src/format/tests/custom_type.rs b/compiler-core/src/format/tests/custom_type.rs new file mode 100644 index 00000000000..64518732551 --- /dev/null +++ b/compiler-core/src/format/tests/custom_type.rs @@ -0,0 +1,354 @@ +use crate::assert_format; + +#[test] +fn custom_type_0() { + assert_format!( + "type WowThisTypeHasJustTheLongestName( + some_long_type_variable, + and_another, + and_another_again, +) { + Make +} +" + ); +} +#[test] +fn custom_type_1() { + assert_format!( + "type Result(a, e) { + Ok(a) + Error(e) +} +" + ); +} +#[test] +fn custom_type_2() { + assert_format!( + "type Result(a, e) { + Ok(value: a) + Error(error: e) +} +" + ); +} +#[test] +fn custom_type_3() { + assert_format!( + "type SillyResult(a, e) { + Ok( + first_value_with_really_long_name: a, + second_value_with_really_long_name: a, + ) + Error(error: e) +} +" + ); +} +#[test] +fn custom_type_4() { + assert_format!( + "type SillyResult(a, e) { + Ok( + first_value_with_really_long_name: a, + second_value_with_really_long_name: List( + #(Int, fn(a, a, a, a, a, a, a) -> List(a)), + ), + ) + Error(error: e) +} +" + ); +} +#[test] +fn custom_type_5() { + assert_format!( + "type X { + X( + start: fn() -> a_reall_really_long_name_goes_here, + stop: fn() -> a_reall_really_long_name_goes_here, + ) +} +" + ); +} +#[test] +fn custom_type_6() { + assert_format!( + "pub opaque type X { + X +} +" + ); +} +#[test] +fn custom_type_7() { + assert_format!( + "/// +pub type Option(a) { + None +} +" + ); +} + +// https://github.com/gleam-lang/gleam/issues/1757 +#[test] +fn multiple_line_custom_type_constructor_field_doc_comments() { + assert_format!( + r#"pub type Thingy { + Thingy( + /// One? + /// One! + one: One, + /// Two? + /// Two! + two: Two, + ) +} +"# + ); +} + +#[test] +fn deprecated_custom_type() { + assert_format!( + r#"@deprecated("Deprecated type") +pub type One { + One +} +"# + ); +} + +#[test] +fn doc_comments_7_test() { + assert_format!( + r#"import one + +/// one +///two +type Whatever { + Whatever +} +"# + ); +} + +#[test] +fn comments1() { + assert_format!( + r#"import one + +// one +//two +type Whatever { + Whatever +} +"# + ); +} + +#[test] +fn comments2() { + assert_format!( + r#"import one + +// one +//two +/// three +type Whatever { + Whatever +} +"# + ); +} + +#[test] +fn comments6() { + assert_format!( + r#"// one +//two +type Thingy +"# + ); +} + +#[test] +fn comments7() { + assert_format!( + r#"// one +//two +type Thingy +"# + ); +} + +#[test] +fn comments8() { + assert_format!( + r#"// one +//two +type Whatever { + Whatever +} +"# + ); +} + +#[test] +fn comments10() { + assert_format!( + r#"// zero +import one + +// one +//two +type Whatever { + Whatever +} +"# + ); +} + +#[test] +fn comments11() { + assert_format!( + "fn main() { + // Hello + \"world\" +} +" + ); +} + +#[test] +fn comment21() { + assert_format!( + "pub type Spec { + Spec( + // Hello + hello: Int, + // World + world: Int, + ) +} +" + ); +} + +#[test] +fn commented_constructors() { + assert_format!( + "pub type Number { + // 1 + One + // 2 + Two + // 3 + Three + // ??? + More +} +" + ); +} + +#[test] +fn commented_constructors1() { + assert_format!( + "pub type Number { + /// 1 + One + /// 2 + Two + /// 3 + Three + /// ??? + More +} +" + ); +} + +#[test] +fn commented_constructors2() { + assert_format!( + "pub type Number { + // a + /// 1 + One + // b + /// 2 + Two + // c + /// 3 + Three + // defg + /// ??? + More +} +" + ); +} + +#[test] +fn commented_constructors3() { + assert_format!( + "pub type Number { + /// 1 + One(value: Int) + /// > 1 + Many(value: Int) +} +" + ); +} + +#[test] +fn deprecated_variant_1() { + assert_format!( + r#"pub type One { + @deprecated("Deprecated type") + One +} +"# + ); +} + +#[test] +fn deprecated_variant_2() { + assert_format!( + r#"pub type One { + @deprecated("Deprecated type") + One(Int, Int, Int, Int, Int, Int, Int) +} +"# + ); +} + +#[test] +fn deprecated_variant_3() { + assert_format!( + r#"pub type One { + @deprecated("Deprecated type with a very long message") + One(Int, Int, Int, Int, Int, Int, Int) +} +"# + ); +} + +#[test] +fn deprecated_variant_4() { + assert_format!( + r#"pub type One { + @deprecated("Deprecated type with a very long message + +It even has multiple lines! +") + One(Int, Int, Int, Int, Int, Int, Int) +} +"# + ); +}