From 007033109ddf5da7844bd032b53941cb6a2613f0 Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Fri, 13 Jun 2025 16:16:13 -0700 Subject: [PATCH] Only mark tests non-text if they actually depend on line ending. Some test files were included, where only their data actually depended on line endings. Some tests didn't actually depend on line ending at all. (They may date back to a time where multiline strings didn't normalize their newlines.) Fix some syntax tests that had been formatted, and exempt all files depending on line endings from formatting. Change-Id: I6c003e9c4f03d3b2af102bfca59d4a7bc8e6d63f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434380 Reviewed-by: Devon Carew Commit-Queue: Lasse Nielsen --- .gitattributes | 7 - .../language/string/multiline_newline_cr.dart | 26 +- .../string/multiline_strings_test.dart | 22 +- tests/language/string/raw_string_test.dart | 64 ++- .../literal_string_juxtaposition_test.dart | 452 +++--------------- .../string_interpolation_dynamic_test.dart | 2 - tests/web/string_interpolation_test.dart | 2 - 7 files changed, 116 insertions(+), 459 deletions(-) diff --git a/.gitattributes b/.gitattributes index 04c8368aa74..f3093ab053e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16,20 +16,13 @@ # File that should not be converted. tests/web/eof_line_ending_test.dart -text -tests/web/string_interpolation_test.dart -text -tests/web/string_interpolation_dynamic_test.dart -text -tests/web/literal_string_juxtaposition_test.dart -text -tests/language/string/raw_string_test.dart -text -tests/language/string/multiline_strings_test.dart -text tests/language/string/multiline_newline_cr.dart -text tests/language/string/multiline_newline_crlf.dart -text tests/language/string/multiline_newline_lf.dart -text tests/lib/mirrors/method_mirror_source_line_ending_cr.dart -text tests/lib/mirrors/method_mirror_source_line_ending_crlf.dart -text tests/lib/mirrors/method_mirror_source_line_ending_lf.dart -text -tests/lib/mirrors/method_mirror_source_line_ending_test.dart -text tests/lib/mirrors/method_mirror_source_other.dart -text -tests/lib/mirrors/method_mirror_source_test.dart -text # Files to leave alone and not diff. *.png binary diff --git a/tests/language/string/multiline_newline_cr.dart b/tests/language/string/multiline_newline_cr.dart index 1b0627a8d50..a299735e541 100644 --- a/tests/language/string/multiline_newline_cr.dart +++ b/tests/language/string/multiline_newline_cr.dart @@ -2,24 +2,16 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -library multiline_newline_cr; +// Test depends on specific line endings, +// and requires an entry in the .gitattributes file. -const constantMultilineString = """ -a -b -"""; +// dart format off -var nonConstantMultilineString = """ -a -b -"""; +// All line endings inside string literals are Carriage Return, U+000D +const constantMultilineString = """ a b """; -const constantRawMultilineString = r""" -\a -\b -"""; +var nonConstantMultilineString = """ a b """; -var nonConstantRawMultilineString = r""" -\a -\b -"""; +const constantRawMultilineString = r""" \a \b """; + +var nonConstantRawMultilineString = r""" \a \b """; diff --git a/tests/language/string/multiline_strings_test.dart b/tests/language/string/multiline_strings_test.dart index 8795014d32e..9fa8b04ae5a 100644 --- a/tests/language/string/multiline_strings_test.dart +++ b/tests/language/string/multiline_strings_test.dart @@ -2,24 +2,29 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Note: This test relies on LF line endings in the source file. - import "package:expect/expect.dart"; -main() { +void main() { + // Spaces after '''. Expect.equals('foo', ''' foo'''); + // Tab characters after '''. + Expect.equals('foo', ''' +foo'''); + Expect.equals('\\\nfoo', '''\\ foo'''); Expect.equals('\t\nfoo', '''\t foo'''); + // Backslash just before newline. Expect.equals('foo', '''\ foo'''); - Expect.equals('foo', '''\ \ + // Backslash before space, tab and newline. + Expect.equals('foo', '''\ \ \ foo'''); Expect.equals(' \nfoo', '''\x20 @@ -29,18 +34,25 @@ foo'''); Expect.equals(' \nfoo', '''$x foo'''); + /// Spaces after '''. Expect.equals('foo', r''' foo'''); + /// Tab characters after '''. + Expect.equals('foo', r''' +foo'''); + Expect.equals('\\\\\nfoo', r'''\\ foo'''); Expect.equals('\\t\nfoo', r'''\t foo'''); + // Backslash before newline. Expect.equals('foo', r'''\ foo'''); - Expect.equals('foo', r'''\ \ + // Backslash before space, tab and newline. + Expect.equals('foo', r'''\ \ \ foo'''); } diff --git a/tests/language/string/raw_string_test.dart b/tests/language/string/raw_string_test.dart index f509678a82b..4b83384cb70 100644 --- a/tests/language/string/raw_string_test.dart +++ b/tests/language/string/raw_string_test.dart @@ -2,48 +2,40 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Note: This test relies on LF line endings in the source file. - import "package:expect/expect.dart"; -class RawStringTest { - static testMain() { - Expect.equals("abcd", r"abcd"); - Expect.equals("", r""); - Expect.equals("", r''); - Expect.equals("", r""""""); - Expect.equals("", r''''''); - Expect.equals("''''", r"''''"); - Expect.equals('""""', r'""""'); - Expect.equals("1\n2\n3", r"""1 +void main() { + Expect.equals("abcd", r"abcd"); + Expect.equals("", r""); + Expect.equals("", r''); + Expect.equals("", r""""""); + Expect.equals("", r''''''); + Expect.equals("''''", r"''''"); + Expect.equals('""""', r'""""'); + Expect.equals("1\n2\n3", r"""1 2 3"""); - Expect.equals("1\n2\n3", r'''1 + Expect.equals("1\n2\n3", r'''1 2 3'''); - Expect.equals("1", r""" + Expect.equals("1", r""" 1"""); - Expect.equals("1", r''' + Expect.equals("1", r''' 1'''); - Expect.equals("'", r"'"); - Expect.equals('"', r'"'); - Expect.equals("1", r"1"); - Expect.equals("1", r"1"); - Expect.equals("\$", r"$"); - Expect.equals("\\", r"\"); - Expect.equals("\\", r'\'); - Expect.equals("\${12}", r"${12}"); - Expect.equals( - "\\a\\b\\c\\d\\e\\f\\g\\h\\i\\j\\k\\l\\m", - r"\a\b\c\d\e\f\g\h\i\j\k\l\m", - ); - Expect.equals( - "\\n\\o\\p\\q\\r\\s\\t\\u\\v\\w\\x\\y\\z", - r"\n\o\p\q\r\s\t\u\v\w\x\y\z", - ); - } -} - -main() { - RawStringTest.testMain(); + Expect.equals("'", r"'"); + Expect.equals('"', r'"'); + Expect.equals("1", r"1"); + Expect.equals("1", r"1"); + Expect.equals("\$", r"$"); + Expect.equals("\\", r"\"); + Expect.equals("\\", r'\'); + Expect.equals("\${12}", r"${12}"); + Expect.equals( + "\\a\\b\\c\\d\\e\\f\\g\\h\\i\\j\\k\\l\\m", + r"\a\b\c\d\e\f\g\h\i\j\k\l\m", + ); + Expect.equals( + "\\n\\o\\p\\q\\r\\s\\t\\u\\v\\w\\x\\y\\z", + r"\n\o\p\q\r\s\t\u\v\w\x\y\z", + ); } diff --git a/tests/web/literal_string_juxtaposition_test.dart b/tests/web/literal_string_juxtaposition_test.dart index f99ad3cbe74..5ec80fc65c3 100644 --- a/tests/web/literal_string_juxtaposition_test.dart +++ b/tests/web/literal_string_juxtaposition_test.dart @@ -2,7 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Note: This test relies on LF line endings in the source file. +// dart format off +// Note: This test relies on specific formatting of adjacent expressions. import "package:expect/expect.dart"; @@ -10,32 +11,10 @@ main() { { // Generates identical compile time constants. var s1 = "abcdefgh"; - var s2 = - "abcd" - "efgh"; - var s3 = - "ab" - "cd" - "ef" - "gh"; - var s4 = - "a" - "b" - "c" - "d" - "e" - "f" - "g" - "h"; - var s5 = - "a" - 'b' - r"c" - r'd' - """e""" - '''f''' - r"""g""" - r'''h'''; + var s2 = "abcd" "efgh"; + var s3 = "ab" "cd" "ef" "gh"; + var s4 = "a" "b" "c" "d" "e" "f" "g" "h"; + var s5 = "a" 'b' r"c" r'd' """e""" '''f''' r"""g""" r'''h'''; Expect.isTrue(identical(s1, s2)); Expect.isTrue(identical(s1, s3)); Expect.isTrue(identical(s1, s4)); @@ -44,105 +23,42 @@ main() { { // Separating whitespace isn't necessary for the tokenizer. var s1 = "abcdefgh"; - var s2 = - "abcd" - "efgh"; - var s3 = - "ab" - "cd" - "ef" - "gh"; - var s4 = - "a" - "b" - "c" - "d" - "e" - "f" - "g" - "h"; - var s5 = - "a" - 'b' - r"c" - r'd' - """e""" - '''f''' - r"""g""" - r'''h'''; + var s2 = "abcd""efgh"; + var s3 = "ab""cd""ef""gh"; + var s4 = "a""b""c""d""e""f""g""h"; + var s5 = "a"'b'r"c"r'd'"""e"""'''f'''r"""g"""r'''h'''; Expect.isTrue(identical(s1, s2)); Expect.isTrue(identical(s1, s3)); Expect.isTrue(identical(s1, s4)); Expect.isTrue(identical(s1, s5)); // "a""""""b""" should be tokenized as "a" """""b""", aka. "a" '""b'. - Expect.isTrue( - identical( - 'a""b', - "a" - """""b""", - ), - ); + Expect.isTrue(identical('a""b', "a""""""b""")); // """a""""""""b""" is 'a' '""b'. - Expect.isTrue( - identical( - 'a""b', - """a""" - """""b""", - ), - ); + Expect.isTrue(identical('a""b', """a""""""""b""")); // Raw strings. - Expect.isTrue( - identical( - 'ab', - "a" - r"b", - ), - ); - Expect.isTrue( - identical( - 'ab', - r"a" - "b", - ), - ); - Expect.isTrue( - identical( - 'ab', - r"a" - r"b", - ), - ); + Expect.isTrue(identical('ab', "a"r"b")); + Expect.isTrue(identical('ab', r"a""b")); + Expect.isTrue(identical('ab', r"a"r"b")); } // Newlines are just whitespace. - var ms1 = - "abc" - "def" - "ghi" - "jkl"; + var ms1 = "abc" + "def" + "ghi" + "jkl"; Expect.isTrue(identical("abcdefghijkl", ms1)); // Works with multiline strings too. - var ms2 = - """abc + var ms2 = """abc def""" - """ + """ ghi jkl """; - Expect.isTrue( - identical("abc\n def ghi\n jkl\n ", ms2), - "Multiline: $ms2", - ); + Expect.isTrue(identical("abc\n def ghi\n jkl\n ", ms2), "Multiline: $ms2"); // Binds stronger than property access (it's considered one literal). - Expect.equals( - 5, - "ab" - "cde" - .length, - "Associativity", - ); + Expect.equals(5, "ab" "cde".length, "Associativity"); // Check that interpolations are handled correctly. { @@ -150,295 +66,51 @@ main() { var y = 42; var z = true; String e1 = "$x$y$z"; - Expect.equals( - e1, - "$x" - "$y$z", - ); - Expect.equals( - e1, - "$x$y" - "$z", - ); - Expect.equals( - e1, - "$x" - "$y" - "$z", - ); + Expect.equals(e1, "$x" "$y$z"); + Expect.equals(e1, "$x$y" "$z"); + Expect.equals(e1, "$x" "$y" "$z"); String e2 = "-$x-$y-$z-"; - Expect.equals( - e2, - "-" - "$x" - "-" - "$y" - "-" - "$z" - "-", - "a", - ); - Expect.equals( - e2, - "-$x" - "-" - "$y" - "-" - "$z" - "-", - "b", - ); - Expect.equals( - e2, - "-" - "$x-" - "$y" - "-" - "$z" - "-", - "c", - ); - Expect.equals( - e2, - "-" - "$x" - "-$y" - "-" - "$z" - "-", - "d", - ); - Expect.equals( - e2, - "-" - "$x" - "-" - "$y-" - "$z" - "-", - "e", - ); - Expect.equals( - e2, - "-" - "$x" - "-" - "$y" - "-$z" - "-", - "f", - ); - Expect.equals( - e2, - "-" - "$x" - "-" - "$y" - "-" - "$z-", - "g", - ); - Expect.equals( - e2, - "-" - "$x-$y" - "-" - "$z" - "-", - "h", - ); - Expect.equals( - e2, - "-" - "$x-$y-$z" - "-", - "i", - ); + Expect.equals(e2, "-" "$x" "-" "$y" "-" "$z" "-", "a"); + Expect.equals(e2, "-$x" "-" "$y" "-" "$z" "-", "b"); + Expect.equals(e2, "-" "$x-" "$y" "-" "$z" "-", "c"); + Expect.equals(e2, "-" "$x" "-$y" "-" "$z" "-", "d"); + Expect.equals(e2, "-" "$x" "-" "$y-" "$z" "-", "e"); + Expect.equals(e2, "-" "$x" "-" "$y" "-$z" "-", "f"); + Expect.equals(e2, "-" "$x" "-" "$y" "-" "$z-", "g"); + Expect.equals(e2, "-" "$x-$y" "-" "$z" "-", "h"); + Expect.equals(e2, "-" "$x-$y-$z" "-", "i"); - Expect.equals( - "-$x-$y-", - "-" - "$x" - "-" - "$y" - "-", - ); - Expect.equals( - "-$x-$y", - "-" - "$x" - "-" - "$y", - ); - Expect.equals( - "-$x$y-", - "-" - "$x" - "$y" - "-", - ); - Expect.equals( - "$x-$y-", - "$x" - "-" - "$y" - "-", - ); + Expect.equals("-$x-$y-", "-" "$x" "-" "$y" "-"); + Expect.equals("-$x-$y", "-" "$x" "-" "$y"); + Expect.equals("-$x$y-", "-" "$x" "$y" "-"); + Expect.equals("$x-$y-", "$x" "-" "$y" "-"); - Expect.equals( - "$x$y", - "$x" - "$y", - ); - Expect.equals( - "$x$y", - "$x" - "" - "$y", - ); - Expect.equals( - "$x$y", - "$x" - "" - "" - "$y", - ); - Expect.equals( - "$x-$y", - "$x" - "-" - "$y", - ); - Expect.equals( - "$x-$y", - "$x" - "-" - "" - "$y", - ); - Expect.equals( - "$x-$y", - "$x" - "" - "-" - "$y", - ); - Expect.equals( - "$x-$y", - "$x" - "" - "-" - "" - "$y", - ); + Expect.equals("$x$y", "$x" "$y"); + Expect.equals("$x$y", "$x" "" "$y"); + Expect.equals("$x$y", "$x" "" "" "$y"); + Expect.equals("$x-$y", "$x" "-" "$y"); + Expect.equals("$x-$y", "$x" "-" "" "$y"); + Expect.equals("$x-$y", "$x" "" "-" "$y"); + Expect.equals("$x-$y", "$x" "" "-" "" "$y"); - Expect.equals( - "$x--$y", - "$x" - "-" - "-" - "$y", - ); - Expect.equals( - "$x--$y", - "$x" - "-" - "-" - "" - "$y", - ); - Expect.equals( - "$x--$y", - "$x" - "-" - "" - "-" - "$y", - ); - Expect.equals( - "$x--$y", - "$x" - "" - "-" - "-" - "$y", - ); + Expect.equals("$x--$y", "$x" "-" "-" "$y"); + Expect.equals("$x--$y", "$x" "-" "-" "" "$y"); + Expect.equals("$x--$y", "$x" "-" "" "-" "$y"); + Expect.equals("$x--$y", "$x" "" "-" "-" "$y"); - Expect.equals( - "$x---$y", - "$x" - "-" - "-" - "-" - "$y", - ); - Expect.equals( - "$x---", - "$x" - "-" - "-" - "-", - ); - Expect.equals( - "---$y", - "-" - "-" - "-" - "$y", - ); + Expect.equals("$x---$y", "$x" "-" "-" "-" "$y"); + Expect.equals("$x---", "$x" "-" "-" "-"); + Expect.equals("---$y", "-" "-" "-" "$y"); - Expect.equals( - "$x-$y-$z", - "${'$x' - '-' - '$y'}" - "-" - "$z", - ); + Expect.equals("$x-$y-$z", "${'$x' '-' '$y'}" "-" "$z"); - Expect.equals( - r"-foo-42-true-", - r"-" - "$x" - r"""-""" - """$y""" - r'-' - '$z' - r'''-''', - "j", - ); - Expect.equals( - r"-$x-42-true-", - r"-" - r"$x" - r"""-""" - """$y""" - r'-' - '$z' - r'''-''', - "k", - ); - Expect.equals( - r"-foo-$y-true-", - r"-" - "$x" - r"""-""" - r"""$y""" - r'-' - '$z' - r'''-''', - "l", - ); - Expect.equals( - r"-foo-42-$z-", - r"-" - "$x" - r"""-""" - """$y""" - r'-' - r'$z' - r'''-''', - "m", - ); + Expect.equals(r"-foo-42-true-", + r"-" "$x" r"""-""" """$y""" r'-' '$z' r'''-''', "j"); + Expect.equals(r"-$x-42-true-", + r"-" r"$x" r"""-""" """$y""" r'-' '$z' r'''-''', "k"); + Expect.equals(r"-foo-$y-true-", + r"-" "$x" r"""-""" r"""$y""" r'-' '$z' r'''-''', "l"); + Expect.equals(r"-foo-42-$z-", + r"-" "$x" r"""-""" """$y""" r'-' r'$z' r'''-''', "m"); } } diff --git a/tests/web/string_interpolation_dynamic_test.dart b/tests/web/string_interpolation_dynamic_test.dart index 1a475d8b3d5..1e9c491b0d5 100644 --- a/tests/web/string_interpolation_dynamic_test.dart +++ b/tests/web/string_interpolation_dynamic_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Note: This test relies on LF line endings in the source file. - import "package:expect/expect.dart"; import 'dart:math'; diff --git a/tests/web/string_interpolation_test.dart b/tests/web/string_interpolation_test.dart index efc738842dd..1c1125af984 100644 --- a/tests/web/string_interpolation_test.dart +++ b/tests/web/string_interpolation_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Note: This test relies on LF line endings in the source file. - import "package:expect/expect.dart"; // Test that String interpolation works in the code generated by the leg