diff --git a/.gitattributes b/.gitattributes index 3b5895d3c45..6455c329463 100644 --- a/.gitattributes +++ b/.gitattributes @@ -22,6 +22,11 @@ tests/dart2js_2/eof_line_ending_test.dart -text tests/dart2js_2/string_interpolation_test.dart -text tests/dart2js_2/string_interpolation_dynamic_test.dart -text tests/dart2js_2/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/language_2/string/raw_string_test.dart -text tests/language_2/string/multiline_strings_test.dart -text tests/language_2/string/multiline_newline_cr.dart -text diff --git a/tests/language/string/adjacent_const_string_literals_test.dart b/tests/language/string/adjacent_const_string_literals_test.dart new file mode 100644 index 00000000000..0af09ba311b --- /dev/null +++ b/tests/language/string/adjacent_const_string_literals_test.dart @@ -0,0 +1,117 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +class Conster { + const Conster(this.value); + + final value; + + toString() { + return value.toString(); + } +} + +main() { + testEmpty(); + testInterpolation(); + testMultiline(); +} + +testEmpty() { + Expect.equals("", (const Conster("" "" "")).toString()); + Expect.equals("", (const Conster("" '' "")).toString()); + Expect.equals("", (const Conster("" "" r"")).toString()); + + Expect.equals("a", (const Conster("a" "")).toString()); + Expect.equals("a", (const Conster("a" '')).toString()); + Expect.equals("a", (const Conster("a" r'')).toString()); + + Expect.equals("b", (const Conster('b' "")).toString()); + Expect.equals("b", (const Conster('b' '')).toString()); + Expect.equals("b", (const Conster('b' r'')).toString()); + + Expect.equals("c", (const Conster(r'c' "")).toString()); + Expect.equals("c", (const Conster(r'c' '')).toString()); + Expect.equals("c", (const Conster(r'c' r'')).toString()); + + Expect.equals("a", (const Conster("" "a")).toString()); + Expect.equals("a", (const Conster("" 'a')).toString()); + Expect.equals("a", (const Conster("" r'a')).toString()); + + Expect.equals("b", (const Conster('' "b")).toString()); + Expect.equals("b", (const Conster('' 'b')).toString()); + Expect.equals("b", (const Conster('' r'b')).toString()); + + Expect.equals("c", (const Conster(r'' "c")).toString()); + Expect.equals("c", (const Conster(r'' 'c')).toString()); + Expect.equals("c", (const Conster(r'' r'c')).toString()); +} + +const s = "a"; + +testInterpolation() { + Expect.equals(r"ab", (const Conster("$s" "b")).toString()); + Expect.equals(r"ab", (const Conster('$s' "b")).toString()); + Expect.equals(r"$sb", (const Conster(r'$s' "b")).toString()); + + Expect.equals(r"-a-b", (const Conster("-$s-" "b")).toString()); + Expect.equals(r"-a-b", (const Conster('-$s-' "b")).toString()); + Expect.equals(r"-$s-b", (const Conster(r'-$s-' "b")).toString()); + + Expect.equals(r"ba", (const Conster('b' "$s")).toString()); + Expect.equals(r"ba", (const Conster('b' '$s')).toString()); + Expect.equals(r"b$s", (const Conster('b' r'$s')).toString()); + + Expect.equals(r"b-a-", (const Conster('b' "-$s-")).toString()); + Expect.equals(r"b-a-", (const Conster('b' '-$s-')).toString()); + Expect.equals(r"b-$s-", (const Conster('b' r'-$s-')).toString()); +} + +testMultiline() { + Expect.equals( + "abe", + (const Conster("a" + "b" + "e")) + .toString()); + Expect.equals( + "a b e", + (const Conster("a " + "b " + "e")) + .toString()); + Expect.equals( + "a b e", + (const Conster("a" + " b" + " e")) + .toString()); + + Expect.equals( + "abe", + (const Conster(""" +a""" + "b" + "e")) + .toString()); + Expect.equals( + "a b e", + (const Conster(""" +a""" + " b" + " e")) + .toString()); + + Expect.equals( + "abe", + (const Conster(""" +a""" + """ +b""" + """ +e""")) + .toString()); +} diff --git a/tests/language/string/adjacent_string_literals_test.dart b/tests/language/string/adjacent_string_literals_test.dart new file mode 100644 index 00000000000..48f8ba2bd1c --- /dev/null +++ b/tests/language/string/adjacent_string_literals_test.dart @@ -0,0 +1,100 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +main() { + testEmpty(); + testInterpolation(); + testMultiline(); +} + +testEmpty() { + Expect.equals("", "" "" ""); + Expect.equals("", "" '' ""); + Expect.equals("", "" "" r""); + + Expect.equals("a", "a" ""); + Expect.equals("a", "a" ''); + Expect.equals("a", "a" r''); + + Expect.equals("b", 'b' ""); + Expect.equals("b", 'b' ''); + Expect.equals("b", 'b' r''); + + Expect.equals("c", r'c' ""); + Expect.equals("c", r'c' ''); + Expect.equals("c", r'c' r''); + + Expect.equals("a", "" "a"); + Expect.equals("a", "" 'a'); + Expect.equals("a", "" r'a'); + + Expect.equals("b", '' "b"); + Expect.equals("b", '' 'b'); + Expect.equals("b", '' r'b'); + + Expect.equals("c", r'' "c"); + Expect.equals("c", r'' 'c'); + Expect.equals("c", r'' r'c'); +} + +testInterpolation() { + var s = "a"; + Expect.equals(r"ab", "$s" "b"); + Expect.equals(r"ab", '$s' "b"); + Expect.equals(r"$sb", r'$s' "b"); + + Expect.equals(r"-a-b", "-$s-" "b"); + Expect.equals(r"-a-b", '-$s-' "b"); + Expect.equals(r"-$s-b", r'-$s-' "b"); + + Expect.equals(r"ba", 'b' "$s"); + Expect.equals(r"ba", 'b' '$s'); + Expect.equals(r"b$s", 'b' r'$s'); + + Expect.equals(r"b-a-", 'b' "-$s-"); + Expect.equals(r"b-a-", 'b' '-$s-'); + Expect.equals(r"b-$s-", 'b' r'-$s-'); +} + +testMultiline() { + Expect.equals( + "abe", + "a" + "b" + "e"); + Expect.equals( + "a b e", + "a " + "b " + "e"); + Expect.equals( + "a b e", + "a" + " b" + " e"); + + Expect.equals( + "abe", + """ +a""" + "b" + "e"); + Expect.equals( + "a b e", + """ +a""" + " b" + " e"); + + Expect.equals( + "abe", + """ +a""" + """ +b""" + """ +e"""); +} diff --git a/tests/language/string/bad_raw_string_runtime_test.dart b/tests/language/string/bad_raw_string_runtime_test.dart new file mode 100644 index 00000000000..4046aa54ede --- /dev/null +++ b/tests/language/string/bad_raw_string_runtime_test.dart @@ -0,0 +1,26 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file +// 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. + +main() { + // Raw String may not contain newline (may not be multi-line). + String x = '' + + + + + // Test that a raw string containing just one character, a \n char, fails. + // Enclose the test string in a bigger multiline string, except in case 03: + + """ + + r' +' + + """ + + ; +} diff --git a/tests/language/string/bad_raw_string_test.dart b/tests/language/string/bad_raw_string_test.dart new file mode 100644 index 00000000000..7091ebae6ad --- /dev/null +++ b/tests/language/string/bad_raw_string_test.dart @@ -0,0 +1,45 @@ +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file +// 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. + +main() { + // Raw String may not contain newline (may not be multi-line). + String x = '' + r' +// ^ +// [cfe] String starting with r' must end with '. +// ^ +// [analyzer] SYNTACTIC_ERROR.UNTERMINATED_STRING_LITERAL +' +// [error line 13, column 1, length 1] +// [analyzer] SYNTACTIC_ERROR.UNTERMINATED_STRING_LITERAL +// [cfe] String starting with ' must end with '. + r" +// ^ +// [cfe] String starting with r" must end with ". +// ^ +// [analyzer] SYNTACTIC_ERROR.UNTERMINATED_STRING_LITERAL +" +// [error line 22, column 1, length 1] +// [analyzer] SYNTACTIC_ERROR.UNTERMINATED_STRING_LITERAL +// [cfe] String starting with " must end with ". + + // Test that a raw string containing just one character, a \n char, fails. + // Enclose the test string in a bigger multiline string, except in case 03: + ''' + """ + ''' + r' +// ^ +// [cfe] String starting with r' must end with '. +// ^ +// [analyzer] SYNTACTIC_ERROR.UNTERMINATED_STRING_LITERAL +' +// [error line 37, column 1, length 1] +// [analyzer] SYNTACTIC_ERROR.UNTERMINATED_STRING_LITERAL +// [cfe] String starting with ' must end with '. + ''' + """ + ''' + ; +} diff --git a/tests/language/string/char_escape_test.dart b/tests/language/string/char_escape_test.dart new file mode 100644 index 00000000000..7b87fbeeb7d --- /dev/null +++ b/tests/language/string/char_escape_test.dart @@ -0,0 +1,533 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. +// Dart test for reading escape sequences in string literals + +import "package:expect/expect.dart"; + +class CharEscapeTest { + static testMain() { + var x00 = "\x00"; + var u0000 = "\u0000"; + var v0 = "\u{0}"; + var v00 = "\u{00}"; + var v000 = "\u{000}"; + var v0000 = "\u{0000}"; + var v00000 = "\u{00000}"; + var v000000 = "\u{000000}"; + Expect.equals(1, x00.length); + Expect.equals(1, u0000.length); + Expect.equals(1, v0.length); + Expect.equals(1, v00.length); + Expect.equals(1, v000.length); + Expect.equals(1, v0000.length); + Expect.equals(1, v00000.length); + Expect.equals(1, v000000.length); + Expect.equals(0, x00.codeUnitAt(0)); + Expect.equals(0, u0000.codeUnitAt(0)); + Expect.equals(0, v0.codeUnitAt(0)); + Expect.equals(0, v00.codeUnitAt(0)); + Expect.equals(0, v000.codeUnitAt(0)); + Expect.equals(0, v0000.codeUnitAt(0)); + Expect.equals(0, v00000.codeUnitAt(0)); + Expect.equals(0, v000000.codeUnitAt(0)); + Expect.equals("\x00", new String.fromCharCodes([0])); + Expect.equals("\u0000", new String.fromCharCodes([0])); + Expect.equals("\u{0}", new String.fromCharCodes([0])); + Expect.equals("\u{00}", new String.fromCharCodes([0])); + Expect.equals("\u{000}", new String.fromCharCodes([0])); + Expect.equals("\u{0000}", new String.fromCharCodes([0])); + Expect.equals("\u{00000}", new String.fromCharCodes([0])); + Expect.equals("\u{000000}", new String.fromCharCodes([0])); + + var x01 = "\x01"; + var u0001 = "\u0001"; + var v1 = "\u{1}"; + var v01 = "\u{01}"; + var v001 = "\u{001}"; + var v0001 = "\u{0001}"; + var v00001 = "\u{00001}"; + var v000001 = "\u{000001}"; + Expect.equals(1, x01.length); + Expect.equals(1, u0001.length); + Expect.equals(1, v1.length); + Expect.equals(1, v01.length); + Expect.equals(1, v001.length); + Expect.equals(1, v0001.length); + Expect.equals(1, v00001.length); + Expect.equals(1, v000001.length); + Expect.equals(1, x01.codeUnitAt(0)); + Expect.equals(1, u0001.codeUnitAt(0)); + Expect.equals(1, v1.codeUnitAt(0)); + Expect.equals(1, v01.codeUnitAt(0)); + Expect.equals(1, v001.codeUnitAt(0)); + Expect.equals(1, v0001.codeUnitAt(0)); + Expect.equals(1, v00001.codeUnitAt(0)); + Expect.equals(1, v000001.codeUnitAt(0)); + Expect.equals("\x01", new String.fromCharCodes([1])); + Expect.equals("\u0001", new String.fromCharCodes([1])); + Expect.equals("\u{1}", new String.fromCharCodes([1])); + Expect.equals("\u{01}", new String.fromCharCodes([1])); + Expect.equals("\u{001}", new String.fromCharCodes([1])); + Expect.equals("\u{0001}", new String.fromCharCodes([1])); + Expect.equals("\u{00001}", new String.fromCharCodes([1])); + Expect.equals("\u{000001}", new String.fromCharCodes([1])); + + var x55 = "\x55"; + var u0055 = "\u0055"; + var v55 = "\u{55}"; + var v055 = "\u{055}"; + var v0055 = "\u{0055}"; + var v00055 = "\u{00055}"; + var v000055 = "\u{000055}"; + Expect.equals(1, x55.length); + Expect.equals(1, u0055.length); + Expect.equals(1, v55.length); + Expect.equals(1, v055.length); + Expect.equals(1, v0055.length); + Expect.equals(1, v00055.length); + Expect.equals(1, v000055.length); + Expect.equals(0x55, x55.codeUnitAt(0)); + Expect.equals(0x55, u0055.codeUnitAt(0)); + Expect.equals(0x55, v55.codeUnitAt(0)); + Expect.equals(0x55, v055.codeUnitAt(0)); + Expect.equals(0x55, v0055.codeUnitAt(0)); + Expect.equals(0x55, v00055.codeUnitAt(0)); + Expect.equals(0x55, v000055.codeUnitAt(0)); + Expect.equals("\x55", new String.fromCharCodes([0x55])); + Expect.equals("\u0055", new String.fromCharCodes([0x55])); + Expect.equals("\u{55}", new String.fromCharCodes([0x55])); + Expect.equals("\u{055}", new String.fromCharCodes([0x55])); + Expect.equals("\u{0055}", new String.fromCharCodes([0x55])); + Expect.equals("\u{00055}", new String.fromCharCodes([0x55])); + Expect.equals("\u{000055}", new String.fromCharCodes([0x55])); + + var x7F = "\x7F"; + var u007F = "\u007F"; + var v7F = "\u{7F}"; + var v07F = "\u{07F}"; + var v007F = "\u{007F}"; + var v0007F = "\u{0007F}"; + var v00007F = "\u{00007F}"; + Expect.equals(1, x7F.length); + Expect.equals(1, u007F.length); + Expect.equals(1, v7F.length); + Expect.equals(1, v07F.length); + Expect.equals(1, v007F.length); + Expect.equals(1, v0007F.length); + Expect.equals(1, v00007F.length); + Expect.equals(0x7F, x7F.codeUnitAt(0)); + Expect.equals(0x7F, u007F.codeUnitAt(0)); + Expect.equals(0x7F, v7F.codeUnitAt(0)); + Expect.equals(0x7F, v07F.codeUnitAt(0)); + Expect.equals(0x7F, v007F.codeUnitAt(0)); + Expect.equals(0x7F, v0007F.codeUnitAt(0)); + Expect.equals(0x7F, v00007F.codeUnitAt(0)); + Expect.equals("\x7F", new String.fromCharCodes([0x7F])); + Expect.equals("\u007F", new String.fromCharCodes([0x7F])); + Expect.equals("\u{7F}", new String.fromCharCodes([0x7F])); + Expect.equals("\u{07F}", new String.fromCharCodes([0x7F])); + Expect.equals("\u{007F}", new String.fromCharCodes([0x7F])); + Expect.equals("\u{0007F}", new String.fromCharCodes([0x7F])); + Expect.equals("\u{00007F}", new String.fromCharCodes([0x7F])); + + var x80 = "\x80"; + var u0080 = "\u0080"; + var v80 = "\u{80}"; + var v080 = "\u{080}"; + var v0080 = "\u{0080}"; + var v00080 = "\u{00080}"; + var v000080 = "\u{000080}"; + Expect.equals(1, x80.length); + Expect.equals(1, u0080.length); + Expect.equals(1, v80.length); + Expect.equals(1, v080.length); + Expect.equals(1, v0080.length); + Expect.equals(1, v00080.length); + Expect.equals(1, v000080.length); + Expect.equals(0x80, x80.codeUnitAt(0)); + Expect.equals(0x80, u0080.codeUnitAt(0)); + Expect.equals(0x80, v80.codeUnitAt(0)); + Expect.equals(0x80, v080.codeUnitAt(0)); + Expect.equals(0x80, v0080.codeUnitAt(0)); + Expect.equals(0x80, v00080.codeUnitAt(0)); + Expect.equals(0x80, v000080.codeUnitAt(0)); + Expect.equals("\x80", new String.fromCharCodes([0x80])); + Expect.equals("\u0080", new String.fromCharCodes([0x80])); + Expect.equals("\u{80}", new String.fromCharCodes([0x80])); + Expect.equals("\u{080}", new String.fromCharCodes([0x80])); + Expect.equals("\u{0080}", new String.fromCharCodes([0x80])); + Expect.equals("\u{00080}", new String.fromCharCodes([0x80])); + Expect.equals("\u{000080}", new String.fromCharCodes([0x80])); + + var xAA = "\xAA"; + var u00AA = "\u00AA"; + var vAA = "\u{AA}"; + var v0AA = "\u{0AA}"; + var v00AA = "\u{00AA}"; + var v000AA = "\u{000AA}"; + var v0000AA = "\u{0000AA}"; + Expect.equals(1, xAA.length); + Expect.equals(1, u00AA.length); + Expect.equals(1, vAA.length); + Expect.equals(1, v0AA.length); + Expect.equals(1, v00AA.length); + Expect.equals(1, v000AA.length); + Expect.equals(1, v0000AA.length); + Expect.equals(0xAA, xAA.codeUnitAt(0)); + Expect.equals(0xAA, u00AA.codeUnitAt(0)); + Expect.equals(0xAA, vAA.codeUnitAt(0)); + Expect.equals(0xAA, v0AA.codeUnitAt(0)); + Expect.equals(0xAA, v00AA.codeUnitAt(0)); + Expect.equals(0xAA, v000AA.codeUnitAt(0)); + Expect.equals(0xAA, v0000AA.codeUnitAt(0)); + Expect.equals("\xAA", new String.fromCharCodes([0xAA])); + Expect.equals("\u00AA", new String.fromCharCodes([0xAA])); + Expect.equals("\u{AA}", new String.fromCharCodes([0xAA])); + Expect.equals("\u{0AA}", new String.fromCharCodes([0xAA])); + Expect.equals("\u{00AA}", new String.fromCharCodes([0xAA])); + Expect.equals("\u{000AA}", new String.fromCharCodes([0xAA])); + Expect.equals("\u{0000AA}", new String.fromCharCodes([0xAA])); + + var xFE = "\xFE"; + var u00FE = "\u00FE"; + var vFE = "\u{FE}"; + var v0FE = "\u{0FE}"; + var v00FE = "\u{00FE}"; + var v000FE = "\u{000FE}"; + var v0000FE = "\u{0000FE}"; + Expect.equals(1, xFE.length); + Expect.equals(1, u00FE.length); + Expect.equals(1, vFE.length); + Expect.equals(1, v0FE.length); + Expect.equals(1, v00FE.length); + Expect.equals(1, v000FE.length); + Expect.equals(1, v0000FE.length); + Expect.equals(0xFE, xFE.codeUnitAt(0)); + Expect.equals(0xFE, u00FE.codeUnitAt(0)); + Expect.equals(0xFE, vFE.codeUnitAt(0)); + Expect.equals(0xFE, v0FE.codeUnitAt(0)); + Expect.equals(0xFE, v00FE.codeUnitAt(0)); + Expect.equals(0xFE, v000FE.codeUnitAt(0)); + Expect.equals(0xFE, v0000FE.codeUnitAt(0)); + Expect.equals("\xFE", new String.fromCharCodes([0xFE])); + Expect.equals("\u00FE", new String.fromCharCodes([0xFE])); + Expect.equals("\u{FE}", new String.fromCharCodes([0xFE])); + Expect.equals("\u{0FE}", new String.fromCharCodes([0xFE])); + Expect.equals("\u{00FE}", new String.fromCharCodes([0xFE])); + Expect.equals("\u{000FE}", new String.fromCharCodes([0xFE])); + Expect.equals("\u{0000FE}", new String.fromCharCodes([0xFE])); + + var xFF = "\xFF"; + var u00FF = "\u00FF"; + var vFF = "\u{FF}"; + var v0FF = "\u{0FF}"; + var v00FF = "\u{00FF}"; + var v000FF = "\u{000FF}"; + var v0000FF = "\u{0000FF}"; + Expect.equals(1, xFF.length); + Expect.equals(1, u00FF.length); + Expect.equals(1, vFF.length); + Expect.equals(1, v0FF.length); + Expect.equals(1, v00FF.length); + Expect.equals(1, v000FF.length); + Expect.equals(1, v0000FF.length); + Expect.equals(0xFF, xFF.codeUnitAt(0)); + Expect.equals(0xFF, u00FF.codeUnitAt(0)); + Expect.equals(0xFF, vFF.codeUnitAt(0)); + Expect.equals(0xFF, v0FF.codeUnitAt(0)); + Expect.equals(0xFF, v00FF.codeUnitAt(0)); + Expect.equals(0xFF, v000FF.codeUnitAt(0)); + Expect.equals(0xFF, v0000FF.codeUnitAt(0)); + Expect.equals("\xFF", new String.fromCharCodes([0xFF])); + Expect.equals("\u00FF", new String.fromCharCodes([0xFF])); + Expect.equals("\u{FF}", new String.fromCharCodes([0xFF])); + Expect.equals("\u{0FF}", new String.fromCharCodes([0xFF])); + Expect.equals("\u{00FF}", new String.fromCharCodes([0xFF])); + Expect.equals("\u{000FF}", new String.fromCharCodes([0xFF])); + Expect.equals("\u{0000FF}", new String.fromCharCodes([0xFF])); + + var u1000 = "\u1000"; + var v1000 = "\u{1000}"; + var v01000 = "\u{01000}"; + var v001000 = "\u{001000}"; + Expect.equals(1, u1000.length); + Expect.equals(1, v1000.length); + Expect.equals(1, v01000.length); + Expect.equals(1, v001000.length); + Expect.equals(0x1000, u1000.codeUnitAt(0)); + Expect.equals(0x1000, v1000.codeUnitAt(0)); + Expect.equals(0x1000, v01000.codeUnitAt(0)); + Expect.equals(0x1000, v001000.codeUnitAt(0)); + Expect.equals("\u1000", new String.fromCharCodes([0x1000])); + Expect.equals("\u{1000}", new String.fromCharCodes([0x1000])); + Expect.equals("\u{01000}", new String.fromCharCodes([0x1000])); + Expect.equals("\u{001000}", new String.fromCharCodes([0x1000])); + + var u5555 = "\u5555"; + var v5555 = "\u{5555}"; + var v05555 = "\u{05555}"; + var v005555 = "\u{005555}"; + Expect.equals(1, u5555.length); + Expect.equals(1, v5555.length); + Expect.equals(1, v05555.length); + Expect.equals(1, v005555.length); + Expect.equals(0x5555, u5555.codeUnitAt(0)); + Expect.equals(0x5555, v5555.codeUnitAt(0)); + Expect.equals(0x5555, v05555.codeUnitAt(0)); + Expect.equals(0x5555, v005555.codeUnitAt(0)); + Expect.equals("\u5555", new String.fromCharCodes([0x5555])); + Expect.equals("\u{5555}", new String.fromCharCodes([0x5555])); + Expect.equals("\u{05555}", new String.fromCharCodes([0x5555])); + Expect.equals("\u{005555}", new String.fromCharCodes([0x5555])); + + var u7FFF = "\u7FFF"; + var v7FFF = "\u{7FFF}"; + var v07FFF = "\u{07FFF}"; + var v007FFF = "\u{007FFF}"; + Expect.equals(1, u7FFF.length); + Expect.equals(1, v7FFF.length); + Expect.equals(1, v07FFF.length); + Expect.equals(1, v007FFF.length); + Expect.equals(0x7FFF, u7FFF.codeUnitAt(0)); + Expect.equals(0x7FFF, v7FFF.codeUnitAt(0)); + Expect.equals(0x7FFF, v07FFF.codeUnitAt(0)); + Expect.equals(0x7FFF, v007FFF.codeUnitAt(0)); + Expect.equals("\u7FFF", new String.fromCharCodes([0x7FFF])); + Expect.equals("\u{7FFF}", new String.fromCharCodes([0x7FFF])); + Expect.equals("\u{07FFF}", new String.fromCharCodes([0x7FFF])); + Expect.equals("\u{007FFF}", new String.fromCharCodes([0x7FFF])); + + var u8000 = "\u8000"; + var v8000 = "\u{8000}"; + var v08000 = "\u{08000}"; + var v008000 = "\u{008000}"; + Expect.equals(1, u8000.length); + Expect.equals(1, v8000.length); + Expect.equals(1, v08000.length); + Expect.equals(1, v008000.length); + Expect.equals(0x8000, u8000.codeUnitAt(0)); + Expect.equals(0x8000, v8000.codeUnitAt(0)); + Expect.equals(0x8000, v08000.codeUnitAt(0)); + Expect.equals(0x8000, v008000.codeUnitAt(0)); + Expect.equals("\u8000", new String.fromCharCodes([0x8000])); + Expect.equals("\u{8000}", new String.fromCharCodes([0x8000])); + Expect.equals("\u{08000}", new String.fromCharCodes([0x8000])); + Expect.equals("\u{008000}", new String.fromCharCodes([0x8000])); + + var uAAAA = "\uAAAA"; + var vAAAA = "\u{AAAA}"; + var v0AAAA = "\u{0AAAA}"; + var v00AAAA = "\u{00AAAA}"; + Expect.equals(1, uAAAA.length); + Expect.equals(1, vAAAA.length); + Expect.equals(1, v0AAAA.length); + Expect.equals(1, v00AAAA.length); + Expect.equals(0xAAAA, uAAAA.codeUnitAt(0)); + Expect.equals(0xAAAA, vAAAA.codeUnitAt(0)); + Expect.equals(0xAAAA, v0AAAA.codeUnitAt(0)); + Expect.equals(0xAAAA, v00AAAA.codeUnitAt(0)); + Expect.equals("\uAAAA", new String.fromCharCodes([0xAAAA])); + Expect.equals("\u{AAAA}", new String.fromCharCodes([0xAAAA])); + Expect.equals("\u{0AAAA}", new String.fromCharCodes([0xAAAA])); + Expect.equals("\u{00AAAA}", new String.fromCharCodes([0xAAAA])); + + var uFFFE = "\uFFFE"; + var vFFFE = "\u{FFFE}"; + var v0FFFE = "\u{0FFFE}"; + var v00FFFE = "\u{00FFFE}"; + Expect.equals(1, uFFFE.length); + Expect.equals(1, vFFFE.length); + Expect.equals(1, v0FFFE.length); + Expect.equals(1, v00FFFE.length); + Expect.equals(0xFFFE, uFFFE.codeUnitAt(0)); + Expect.equals(0xFFFE, vFFFE.codeUnitAt(0)); + Expect.equals(0xFFFE, v0FFFE.codeUnitAt(0)); + Expect.equals(0xFFFE, v00FFFE.codeUnitAt(0)); + Expect.equals("\uFFFE", new String.fromCharCodes([0xFFFE])); + Expect.equals("\u{FFFE}", new String.fromCharCodes([0xFFFE])); + Expect.equals("\u{0FFFE}", new String.fromCharCodes([0xFFFE])); + Expect.equals("\u{00FFFE}", new String.fromCharCodes([0xFFFE])); + + var uFFFF = "\uFFFF"; + var vFFFF = "\u{FFFF}"; + var v0FFFF = "\u{0FFFF}"; + var v00FFFF = "\u{00FFFF}"; + Expect.equals(1, uFFFF.length); + Expect.equals(1, vFFFF.length); + Expect.equals(1, v0FFFF.length); + Expect.equals(1, v00FFFF.length); + Expect.equals(0xFFFF, uFFFF.codeUnitAt(0)); + Expect.equals(0xFFFF, vFFFF.codeUnitAt(0)); + Expect.equals(0xFFFF, v0FFFF.codeUnitAt(0)); + Expect.equals(0xFFFF, v00FFFF.codeUnitAt(0)); + Expect.equals("\uFFFF", new String.fromCharCodes([0xFFFF])); + Expect.equals("\u{FFFF}", new String.fromCharCodes([0xFFFF])); + Expect.equals("\u{0FFFF}", new String.fromCharCodes([0xFFFF])); + Expect.equals("\u{00FFFF}", new String.fromCharCodes([0xFFFF])); + + var v10000 = "\u{10000}"; + var v010000 = "\u{010000}"; + Expect.equals(2, v10000.length); + Expect.equals(2, v010000.length); + Expect.equals("\u{10000}", new String.fromCharCodes([0x10000])); + Expect.equals("\u{010000}", new String.fromCharCodes([0x10000])); + + var v1FFFF = "\u{1FFFF}"; + var v01FFFF = "\u{01FFFF}"; + Expect.equals(2, v1FFFF.length); + Expect.equals(2, v01FFFF.length); + Expect.equals("\u{1FFFF}", new String.fromCharCodes([0x1FFFF])); + Expect.equals("\u{01FFFF}", new String.fromCharCodes([0x1FFFF])); + + var v105555 = "\u{105555}"; + Expect.equals(2, v105555.length); + Expect.equals("\u{105555}", new String.fromCharCodes([0x105555])); + + var v10FFFF = "\u{10FFFF}"; + Expect.equals(2, v10FFFF.length); + Expect.equals("\u{10FFFF}", new String.fromCharCodes([0x10FFFF])); + + var bs = "\b"; + Expect.isTrue(bs != "b"); + Expect.equals(1, bs.length); + Expect.equals(0x08, bs.codeUnitAt(0)); + Expect.equals(bs, new String.fromCharCodes([0x08])); + Expect.equals("\x08", bs); + Expect.equals("\u0008", bs); + Expect.equals("\u{8}", bs); + Expect.equals("\u{08}", bs); + Expect.equals("\u{008}", bs); + Expect.equals("\u{0008}", bs); + Expect.equals("\u{00008}", bs); + Expect.equals("\u{000008}", bs); + + var ht = "\t"; + Expect.isTrue(ht != "t"); + Expect.equals(1, ht.length); + Expect.equals(0x09, ht.codeUnitAt(0)); + Expect.equals(ht, new String.fromCharCodes([0x09])); + Expect.equals("\x09", ht); + Expect.equals("\u0009", ht); + Expect.equals("\u{9}", ht); + Expect.equals("\u{09}", ht); + Expect.equals("\u{009}", ht); + Expect.equals("\u{0009}", ht); + Expect.equals("\u{00009}", ht); + Expect.equals("\u{000009}", ht); + + var lf = "\n"; + Expect.isTrue(lf != "n"); + Expect.equals(1, lf.length); + Expect.equals(0x0A, lf.codeUnitAt(0)); + Expect.equals(lf, new String.fromCharCodes([0x0A])); + Expect.equals("\x0A", lf); + Expect.equals("\u000A", lf); + Expect.equals("\u{A}", lf); + Expect.equals("\u{0A}", lf); + Expect.equals("\u{00A}", lf); + Expect.equals("\u{000A}", lf); + Expect.equals("\u{0000A}", lf); + Expect.equals("\u{00000A}", lf); + + var vt = "\v"; + Expect.isTrue(vt != "v"); + Expect.equals(1, vt.length); + Expect.equals(0x0B, vt.codeUnitAt(0)); + Expect.equals(vt, new String.fromCharCodes([0x0B])); + Expect.equals("\x0B", vt); + Expect.equals("\u000B", vt); + Expect.equals("\u{B}", vt); + Expect.equals("\u{0B}", vt); + Expect.equals("\u{00B}", vt); + Expect.equals("\u{000B}", vt); + Expect.equals("\u{0000B}", vt); + Expect.equals("\u{00000B}", vt); + + var ff = "\f"; + Expect.isTrue(ff != "f"); + Expect.equals(1, ff.length); + Expect.equals(0x0C, ff.codeUnitAt(0)); + Expect.equals(ff, new String.fromCharCodes([0x0C])); + Expect.equals("\x0C", ff); + Expect.equals("\u000C", ff); + Expect.equals("\u{C}", ff); + Expect.equals("\u{0C}", ff); + Expect.equals("\u{00C}", ff); + Expect.equals("\u{000C}", ff); + Expect.equals("\u{0000C}", ff); + Expect.equals("\u{00000C}", ff); + + var cr = "\r"; + Expect.isTrue(cr != "r"); + Expect.equals(1, cr.length); + Expect.equals(0x0D, cr.codeUnitAt(0)); + Expect.equals(cr, new String.fromCharCodes([0x0D])); + Expect.equals("\x0D", cr); + Expect.equals("\u000D", cr); + Expect.equals("\u{D}", cr); + Expect.equals("\u{0D}", cr); + Expect.equals("\u{00D}", cr); + Expect.equals("\u{000D}", cr); + Expect.equals("\u{0000D}", cr); + Expect.equals("\u{00000D}", cr); + + Expect.equals("\a", "a"); + // \b U+0006 BS + Expect.equals("\c", "c"); + Expect.equals("\d", "d"); + Expect.equals("\e", "e"); + // \f U+000C FF + Expect.equals("\g", "g"); + Expect.equals("\h", "h"); + Expect.equals("\i", "i"); + Expect.equals("\j", "j"); + Expect.equals("\k", "k"); + Expect.equals("\l", "l"); + Expect.equals("\m", "m"); + // \n U+000A LF + Expect.equals("\o", "o"); + Expect.equals("\p", "p"); + Expect.equals("\q", "q"); + // \r U+000D CR + Expect.equals("\s", "s"); + // \t U+0009 HT + // \u code point escape + // \v U+000B VT + Expect.equals("\w", "w"); + // \x code point escape + Expect.equals("\y", "y"); + Expect.equals("\z", "z"); + + Expect.equals("\A", "A"); + Expect.equals("\B", "B"); + Expect.equals("\C", "C"); + Expect.equals("\D", "D"); + Expect.equals("\E", "E"); + Expect.equals("\F", "F"); + Expect.equals("\G", "G"); + Expect.equals("\H", "H"); + Expect.equals("\I", "I"); + Expect.equals("\J", "J"); + Expect.equals("\K", "K"); + Expect.equals("\L", "L"); + Expect.equals("\M", "M"); + Expect.equals("\N", "N"); + Expect.equals("\O", "O"); + Expect.equals("\P", "P"); + Expect.equals("\Q", "Q"); + Expect.equals("\R", "R"); + Expect.equals("\S", "S"); + Expect.equals("\T", "T"); + Expect.equals("\U", "U"); + Expect.equals("\V", "V"); + Expect.equals("\W", "W"); + Expect.equals("\X", "X"); + Expect.equals("\Y", "Y"); + Expect.equals("\Z", "Z"); + } +} + +main() { + CharEscapeTest.testMain(); +} diff --git a/tests/language/string/charcode_test.dart b/tests/language/string/charcode_test.dart new file mode 100644 index 00000000000..89061a4ffd3 --- /dev/null +++ b/tests/language/string/charcode_test.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file +// 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. +// VMOptions=--optimization-counter-threshold=10 --no-use-osr + +import "package:expect/expect.dart"; + +main() { + for (int i = 0; i < 20; i++) { + Expect.isTrue(moo("x")); + Expect.isFalse(moo("X")); + Expect.isFalse(moo("xx")); + Expect.isTrue(mooRev("x")); + Expect.isFalse(mooRev("X")); + Expect.isFalse(mooRev("xx")); + Expect.isTrue(goo("Hello", "e")); + Expect.isFalse(goo("Hello", "E")); + Expect.isFalse(goo("Hello", "ee")); + Expect.isTrue(gooRev("Hello", "e")); + Expect.isFalse(gooRev("Hello", "E")); + Expect.isFalse(gooRev("Hello", "ee")); + Expect.isTrue(hoo("HH")); + Expect.isFalse(hoo("Ha")); + Expect.isTrue(hooRev("HH")); + Expect.isFalse(hooRev("Ha")); + } + Expect.isFalse(moo(12)); + Expect.isFalse(mooRev(12)); + Expect.isTrue(goo([1, 2], 2)); + Expect.isTrue(gooRev([1, 2], 2)); + Expect.throwsRangeError(() => hoo("H")); + Expect.throwsRangeError(() => hooRev("H")); +} + +moo(j) { + return "x" == j; +} + +goo(a, j) { + return a[1] == j; +} + +// Check constant folding. +hoo(a) { + return a[1] == ("Hello")[0]; +} + +mooRev(j) { + return j == "x"; +} + +gooRev(a, j) { + return j == a[1]; +} + +// Check constant folding. +hooRev(a) { + return ("Hello")[0] == a[1]; +} diff --git a/tests/language/string/const_interpolation2_test.dart b/tests/language/string/const_interpolation2_test.dart new file mode 100644 index 00000000000..78912b703cc --- /dev/null +++ b/tests/language/string/const_interpolation2_test.dart @@ -0,0 +1,103 @@ +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +// Regression test for issue #24839 - http://dartbug.com/24839 + +const u1 = null; +const int? u2 = null; +const List? u3 = null; +const u4 = const bool.hasEnvironment("XXXXX") + ? const String.fromEnvironment("XXXXX") + : null; +const u5 = const bool.hasEnvironment("XXXXX") + ? const int.fromEnvironment("XXXXX") + : null; +const u6 = bool.hasEnvironment("XXXXX") + ? const bool.fromEnvironment("XXXXX") + : null; +const n1 = 42; +const n2 = 3.1415; +const int n3 = 37; +const double n4 = 4.6692; +const num n5 = b3 ? 1 : 2.71828; +const n6 = const int.fromEnvironment("XXXXX", defaultValue: 87); +const s1 = "s1"; +const String s2 = "s2"; +const String s3 = "$s1$s2"; +const s4 = const String.fromEnvironment("XXXXX", defaultValue: "s4"); +const b1 = true; +const b2 = false; +const b3 = b1 && (b2 || !b1); +const b4 = const bool.fromEnvironment("XXXXX", defaultValue: true); + +// Individually +const su1 = "$u1"; +const su2 = "$u2"; +const su3 = "$u3"; +const su4 = "$u4"; +const su5 = "$u5"; +const su6 = "$u6"; +const sn1 = "$n1"; +const sn2 = "$n2"; +const sn3 = "$n3"; +const sn4 = "$n4"; +const sn5 = "$n5"; +const sn6 = "$n6"; +const ss1 = "$s1"; +const ss2 = "$s2"; +const ss3 = "$s3"; +const ss4 = "$s4"; +const sb1 = "$b1"; +const sb2 = "$b2"; +const sb3 = "$b3"; +const sb4 = "$b4"; + +// Constant variables in interpolation. +const interpolation1 = + "$u1 $u2 $u3 $u4 $u5 $u6 $n1 $n2 $n3 $n4 $n5 $n6 $s1 $s2 $s3 $s4 $b1 $b2 $b3 $b4"; +// Constant expressions in interpolation. +// (Single string, the linebreak to fit this into 80 chars is inside an +// interpolation, which is allowed, even for single-line strings). +const interpolation2 = + "${u1} ${u2} ${u3} ${u4} ${u5} ${u6} ${n1} ${n2} ${n3} ${n4} ${n5} ${n6} ${ + s1} ${s2} ${s3} ${s4} ${b1} ${b2} ${b3} ${b4}"; +// Adjacent string literals are combined. +const interpolation3 = "$u1 $u2 $u3 $u4 $u5 " + '$u6 $n1 $n2 $n3 $n4 ' + """$n5 $n6 $s1 $s2 $s3 """ + '''$s4 $b1 $b2 $b3 $b4'''; +// Nested interpolations. +const interpolation4 = "${"$u1 $u2 $u3 $u4 $u5 " '$u6 $n1 $n2 $n3 $n4'} ${ + """$n5 $n6 $s1 $s2 $s3 """ '''$s4 $b1 $b2 $b3 $b4'''}"; + +main() { + Expect.equals(u1.toString(), su1); + Expect.equals(u2.toString(), su2); + Expect.equals(u3.toString(), su3); + Expect.equals(u4.toString(), su4); + Expect.equals(u5.toString(), su5); + Expect.equals(u6.toString(), su6); + Expect.equals(n1.toString(), sn1); + Expect.equals(n2.toString(), sn2); + Expect.equals(n3.toString(), sn3); + Expect.equals(n4.toString(), sn4); + Expect.equals(n5.toString(), sn5); + Expect.equals(n6.toString(), sn6); + Expect.equals(s1.toString(), ss1); + Expect.equals(s2.toString(), ss2); + Expect.equals(s3.toString(), ss3); + Expect.equals(s4.toString(), ss4); + Expect.equals(b1.toString(), sb1); + Expect.equals(b2.toString(), sb2); + Expect.equals(b3.toString(), sb3); + Expect.equals(b4.toString(), sb4); + var expect = "null null null null null null 42 3.1415 37 4.6692 2.71828 87 " + "s1 s2 s1s2 s4 true false false true"; + Expect.equals(expect, interpolation1); + Expect.equals(expect, interpolation2); + Expect.equals(expect, interpolation3); + Expect.equals(expect, interpolation4); +} diff --git a/tests/language/string/const_interpolation_constant_string_interpolation_test.dart b/tests/language/string/const_interpolation_constant_string_interpolation_test.dart new file mode 100644 index 00000000000..16121c9515f --- /dev/null +++ b/tests/language/string/const_interpolation_constant_string_interpolation_test.dart @@ -0,0 +1,31 @@ +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file +// 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. +// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation + +import "package:expect/expect.dart"; + +main() { + final a = new A(); + for (int i = 0; i < 20; i++) { + final r = interpolIt(a); + Expect.stringEquals("hello home", r); + } + final b = new B(); + // Deoptimize "interpolIt". + final r = interpolIt(b); + Expect.stringEquals("hello world", r); +} + +String interpolIt(v) { + // String interpolation will be constant folded. + return "hello ${v.foo()}"; +} + +class A { + foo() => "home"; +} + +class B { + foo() => "world"; +} diff --git a/tests/language/string/escape4_test.dart b/tests/language/string/escape4_test.dart new file mode 100644 index 00000000000..6f4efba9469 --- /dev/null +++ b/tests/language/string/escape4_test.dart @@ -0,0 +1,31 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// 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. + +// Test that newlines cannot be escaped in strings. + +main() { + // Note: The newline inside a string literal doesn't play nice with the + // static error updater tool, so if you need to tweak the static error + // expectations in this test, you may need to do so manually. + print('Hello, World!\ +'); +// [error line 11, column 8, length 1] +// [cfe] Can't find ')' to match '('. +// [error line 11, column 9, length 1] +// [cfe] String starting with ' must end with '. +// [error line 11, column 23, length 1] +// [analyzer] SYNTACTIC_ERROR.INVALID_UNICODE_ESCAPE +// [cfe] An escape sequence starting with '\u' must be followed by 4 hexadecimal digits or from 1 to 6 digits between '{' and '}'. +// [error line 11, column 23, length 1] +// [analyzer] SYNTACTIC_ERROR.UNTERMINATED_STRING_LITERAL +// [error line 12, column 1, length 3] +// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN +// [cfe] Expected ';' after this. +// [error line 12, column 1] +// [cfe] String starting with ' must end with '. +// [error line 12, column 3, length 1] +// [analyzer] SYNTACTIC_ERROR.UNTERMINATED_STRING_LITERAL +} +// [error line 29, column 1, length 1] +// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN diff --git a/tests/language/string/escapes_test.dart b/tests/language/string/escapes_test.dart new file mode 100644 index 00000000000..78808a74eee --- /dev/null +++ b/tests/language/string/escapes_test.dart @@ -0,0 +1,66 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +class StringEscapesTest { + static testMain() { + testDelimited(); + testFixed2(); + testFixed4(); + testEscapes(); + testLiteral(); + } + + static testDelimited() { + String str = "Foo\u{1}Bar\u{000001}Baz\u{D7FF}Boo"; + Expect.equals(15, str.length); + Expect.equals(1, str.codeUnitAt(3)); + Expect.equals(1, str.codeUnitAt(7)); + Expect.equals(0xD7FF, str.codeUnitAt(11)); + Expect.equals('B'.codeUnitAt(0), str.codeUnitAt(12)); + } + + static testEscapes() { + String str = "Foo\fBar\vBaz\bBoo"; + Expect.equals(15, str.length); + Expect.equals(12, str.codeUnitAt(3)); + Expect.equals('B'.codeUnitAt(0), str.codeUnitAt(4)); + Expect.equals(11, str.codeUnitAt(7)); + Expect.equals('z'.codeUnitAt(0), str.codeUnitAt(10)); + Expect.equals(8, str.codeUnitAt(11)); + Expect.equals('o'.codeUnitAt(0), str.codeUnitAt(14)); + str = "Abc\rDef\nGhi\tJkl"; + Expect.equals(15, str.length); + Expect.equals(13, str.codeUnitAt(3)); + Expect.equals('D'.codeUnitAt(0), str.codeUnitAt(4)); + Expect.equals(10, str.codeUnitAt(7)); + Expect.equals('G'.codeUnitAt(0), str.codeUnitAt(8)); + Expect.equals(9, str.codeUnitAt(11)); + Expect.equals('J'.codeUnitAt(0), str.codeUnitAt(12)); + } + + static testFixed2() { + String str = "Foo\xFFBar"; + Expect.equals(7, str.length); + Expect.equals(255, str.codeUnitAt(3)); + Expect.equals('B'.codeUnitAt(0), str.codeUnitAt(4)); + } + + static testFixed4() { + String str = "Foo\u0001Bar"; + Expect.equals(7, str.length); + Expect.equals(1, str.codeUnitAt(3)); + Expect.equals('B'.codeUnitAt(0), str.codeUnitAt(4)); + } + + static testLiteral() { + String str = "\a\c\d\e\g\h\i\j\k\l\$\{\}\""; + Expect.equals(r'acdeghijkl${}"', str); + } +} + +main() { + StringEscapesTest.testMain(); +} diff --git a/tests/language/string/interpolate1_test.dart b/tests/language/string/interpolate1_test.dart new file mode 100644 index 00000000000..1bc80c0458d --- /dev/null +++ b/tests/language/string/interpolate1_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// 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. + +/// The interpolated identifier can't start with '$'. + +main() { + var $x = 1; + var s = "eins und $$x macht zwei."; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + // ^ + // [analyzer] STATIC_WARNING.UNDEFINED_IDENTIFIER + // [cfe] Getter not found: 'x'. +} diff --git a/tests/language/string/interpolate2_test.dart b/tests/language/string/interpolate2_test.dart new file mode 100644 index 00000000000..bb49ba519d5 --- /dev/null +++ b/tests/language/string/interpolate2_test.dart @@ -0,0 +1,57 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. +// Dart test program testing string interpolation of expressions. + +import "package:expect/expect.dart"; + +class StringInterpolate2Test { + static var F1; + + static void testMain() { + F1 = "1 + 5 = ${1+5}"; + + Expect.equals("1 + 5 = 6", F1); + + var fib = [1, 1, 2, 3, 5, 8, 13, 21]; + + var i = 5; + var s = "${i}"; + Expect.equals("5", s); + + s = "fib(${i}) = ${fib[i]}"; + Expect.equals("fib(5) = 8", s); + + i = 5; + s = "$i squared is ${((x) => x*x)(i)}"; + Expect.equals("5 squared is 25", s); + + Expect.equals("8", "${fib.length}"); + // test single quote + Expect.equals("8", '${fib.length}'); + // test multi-line + Expect.equals( + "8", + '${fib. + length}'); + + var map = {"red": 1, "green": 2, "blue": 3}; + s = "green has value ${map["green"]}"; + Expect.equals("green has value 2", s); + + i = 0; + b() => "${++i}"; + s = "aaa ${"bbb ${b()} bbb"} aaa ${b()}"; + Expect.equals("aaa bbb 1 bbb aaa 2", s); + + // test multiple levels of nesting, including changing quotes and + // multiline string types + s = "a ${(){ return 'b ${(){ return """ +c""";}()}'; }()} d"; + Expect.equals("a b c d", s); + } +} + +main() { + StringInterpolate2Test.testMain(); +} diff --git a/tests/language/string/interpolate3_test.dart b/tests/language/string/interpolate3_test.dart new file mode 100644 index 00000000000..ada7879fe31 --- /dev/null +++ b/tests/language/string/interpolate3_test.dart @@ -0,0 +1,13 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// 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. + +/// The interpolated identifier must start with an identifier start character. + +main() { + var x = 1; + var s = "eins und $-x macht zwei."; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). +} diff --git a/tests/language/string/interpolate_null_test.dart b/tests/language/string/interpolate_null_test.dart new file mode 100644 index 00000000000..e10b80894c4 --- /dev/null +++ b/tests/language/string/interpolate_null_test.dart @@ -0,0 +1,24 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. +// Dart test program testing NPE within string interpolation. + +import "package:expect/expect.dart"; + +class A { + A(String this.name) {} + String name; +} + +main() { + dynamic a = new A("Kermit"); + var s = "Hello Mr. ${a.name}"; + Expect.stringEquals("Hello Mr. Kermit", s); + a = null; + try { + s = "Hello Mr. ${a.name}"; + } on NoSuchMethodError catch (e) { + return; + } + Expect.fail("NoSuchMethodError not thrown"); +} diff --git a/tests/language/string/interpolate_test.dart b/tests/language/string/interpolate_test.dart new file mode 100644 index 00000000000..5c25f42e18f --- /dev/null +++ b/tests/language/string/interpolate_test.dart @@ -0,0 +1,266 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. +// Dart test program testing string interpolation. + +import "package:expect/expect.dart"; + +class WhatchamaCallIt { + WhatchamaCallIt() {} + + String foo() { + // Test $this and Field name is defined in subclass. + dynamic self = this; + dynamic name = self.name; + return "$this and $name"; + } +} + +class ThingamaBob extends WhatchamaCallIt { + ThingamaBob(String s) + : name = s, + super(); + String name; + toString() => "Hansel"; +} + +const String A = "svin"; +const String B = "hest"; +const int N = 1 + 1; +late String Printers; +late String AAR_Printers; + +main() { + Printers = "Printers: $A and $B"; + AAR_Printers = "AAR has $N $Printers."; + + var x = 1; + var s = "eins und \$x macht zwei."; + print(s); + Expect.equals(r"eins und $x macht zwei.", s); + + s = "eins und $x macht zwei."; + print(s); + Expect.equals(r"eins und 1 macht zwei.", s); + + print(AAR_Printers); + Expect.equals(r"AAR has 2 Printers: svin and hest.", AAR_Printers); + + var s$eins = "eins"; + var $1 = 1; + var zw = "zw"; + var ei = "ei"; + var zw$ei = "\"Martini, dry? Nai zwai.\""; + s = "${s$eins} und ${$1} macht $zw$ei."; + print(s); + Expect.equals(r"eins und 1 macht zwei.", s); + + dynamic t = new ThingamaBob("Gretel"); + print(t.foo()); + Expect.equals(t.foo(), "Hansel and Gretel"); + + testStringVariants(); +} + +class Stringable { + final String value; + Stringable(this.value); + String toString() => value; + operator *(int count) => new Stringable(value * count); +} + +void testStringVariants() { + String latin = "ab\x00\xff"; + String nonLatin = "\u2000\u{10000}\ufeff"; + dynamic oLatin = new Stringable(latin); + dynamic oNonLatin = new Stringable(nonLatin); + + // ASCII. + Expect.equals(latin * 3, "$latin$latin$latin"); + Expect.equals( + latin * 64, + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin"); + Expect.equals( + latin * 64, + "${latin * 4}${latin * 4}${latin * 4}${latin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${latin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${latin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${latin * 4}"); + // Non-ASCII. + Expect.equals(nonLatin * 3, "$nonLatin$nonLatin$nonLatin"); + Expect.equals( + nonLatin * 64, + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$nonLatin$nonLatin$nonLatin$nonLatin"); + Expect.equals( + nonLatin * 64, + "${nonLatin * 4}${nonLatin * 4}" + "${nonLatin * 4}${nonLatin * 4}" + "${nonLatin * 4}${nonLatin * 4}" + "${nonLatin * 4}${nonLatin * 4}" + "${nonLatin * 4}${nonLatin * 4}" + "${nonLatin * 4}${nonLatin * 4}" + "${nonLatin * 4}${nonLatin * 4}" + "${nonLatin * 4}${nonLatin * 4}"); + // Mixed. + Expect.equals(latin * 3 + nonLatin, "$latin$latin$latin$nonLatin"); + Expect.equals(nonLatin + latin * 3, "$nonLatin$latin$latin$latin"); + Expect.equals( + latin * 60 + nonLatin * 4, + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin" + "$nonLatin$nonLatin$nonLatin$nonLatin"); + Expect.equals( + nonLatin * 4 + latin * 60, + "$nonLatin$nonLatin$nonLatin$nonLatin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin$latin$latin$latin$latin" + "$latin$latin$latin$latin"); + Expect.equals( + latin * 60 + nonLatin * 4, + "${latin * 4}${latin * 4}${latin * 4}${latin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${latin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${latin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${nonLatin * 4}"); + Expect.equals( + nonLatin * 4 + latin * 60, + "${nonLatin * 4}${latin * 4}${latin * 4}${latin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${latin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${latin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${latin * 4}"); + // With objects. + Expect.equals(latin * 3, "$latin$oLatin$latin"); + Expect.equals( + latin * 64, + "$latin$latin$latin$latin$latin$latin$latin$oLatin" + "$latin$latin$latin$latin$latin$latin$latin$oLatin" + "$latin$latin$latin$latin$latin$latin$latin$oLatin" + "$latin$latin$latin$latin$latin$latin$latin$oLatin" + "$latin$latin$latin$latin$latin$latin$latin$oLatin" + "$latin$latin$latin$latin$latin$latin$latin$oLatin" + "$latin$latin$latin$latin$latin$latin$latin$oLatin" + "$latin$latin$latin$latin$latin$latin$latin$oLatin"); + Expect.equals( + latin * 64, + "${latin * 4}${latin * 4}${latin * 4}${oLatin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${oLatin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${oLatin * 4}" + "${latin * 4}${latin * 4}${latin * 4}${oLatin * 4}"); + // Non-ASCII. + Expect.equals(nonLatin * 3, "$nonLatin$oNonLatin$nonLatin"); + Expect.equals( + nonLatin * 64, + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin" + "$nonLatin$nonLatin$nonLatin$oNonLatin"); + Expect.equals( + nonLatin * 64, + "${nonLatin * 4}${oNonLatin * 4}" + "${nonLatin * 4}${oNonLatin * 4}" + "${nonLatin * 4}${oNonLatin * 4}" + "${nonLatin * 4}${oNonLatin * 4}" + "${nonLatin * 4}${oNonLatin * 4}" + "${nonLatin * 4}${oNonLatin * 4}" + "${nonLatin * 4}${oNonLatin * 4}" + "${nonLatin * 4}${oNonLatin * 4}"); + // Mixed. + Expect.equals(latin * 2 + nonLatin * 2, "$latin$oLatin$nonLatin$oNonLatin"); + Expect.equals(nonLatin * 2 + latin * 2, "$nonLatin$oNonLatin$latin$oLatin"); + Expect.equals( + (latin * 2 + nonLatin * 2) * 8, + "$latin$oLatin$nonLatin$oNonLatin" + "$latin$oLatin$nonLatin$oNonLatin" + "$latin$oLatin$nonLatin$oNonLatin" + "$latin$oLatin$nonLatin$oNonLatin" + "$latin$oLatin$nonLatin$oNonLatin" + "$latin$oLatin$nonLatin$oNonLatin" + "$latin$oLatin$nonLatin$oNonLatin" + "$latin$oLatin$nonLatin$oNonLatin"); + Expect.equals( + (nonLatin * 2 + latin * 2) * 8, + "$nonLatin$oNonLatin$latin$oLatin" + "$nonLatin$oNonLatin$latin$oLatin" + "$nonLatin$oNonLatin$latin$oLatin" + "$nonLatin$oNonLatin$latin$oLatin" + "$nonLatin$oNonLatin$latin$oLatin" + "$nonLatin$oNonLatin$latin$oLatin" + "$nonLatin$oNonLatin$latin$oLatin" + "$nonLatin$oNonLatin$latin$oLatin"); + + // All combinations + var o1 = new Stringable("x"); + var o2 = new Stringable("\ufeff"); + + Expect.equals("a\u2000x\ufeff", "${"a"}${"\u2000"}${o1}${o2}"); + Expect.equals("a\u2000\ufeffx", "${"a"}${"\u2000"}${o2}${o1}"); + Expect.equals("ax\u2000\ufeff", "${"a"}${o1}${"\u2000"}${o2}"); + Expect.equals("ax\ufeff\u2000", "${"a"}${o1}${o2}${"\u2000"}"); + Expect.equals("a\ufeffx\u2000", "${"a"}${o2}${o1}${"\u2000"}"); + Expect.equals("a\ufeff\u2000x", "${"a"}${o2}${"\u2000"}${o1}"); + + Expect.equals("\u2000ax\ufeff", "${"\u2000"}${"a"}${o1}${o2}"); + Expect.equals("\u2000a\ufeffx", "${"\u2000"}${"a"}${o2}${o1}"); + Expect.equals("xa\u2000\ufeff", "${o1}${"a"}${"\u2000"}${o2}"); + Expect.equals("xa\ufeff\u2000", "${o1}${"a"}${o2}${"\u2000"}"); + Expect.equals("\ufeffax\u2000", "${o2}${"a"}${o1}${"\u2000"}"); + Expect.equals("\ufeffa\u2000x", "${o2}${"a"}${"\u2000"}${o1}"); + + Expect.equals("\u2000xa\ufeff", "${"\u2000"}${o1}${"a"}${o2}"); + Expect.equals("\u2000\ufeffax", "${"\u2000"}${o2}${"a"}${o1}"); + Expect.equals("x\u2000a\ufeff", "${o1}${"\u2000"}${"a"}${o2}"); + Expect.equals("x\ufeffa\u2000", "${o1}${o2}${"a"}${"\u2000"}"); + Expect.equals("\ufeffxa\u2000", "${o2}${o1}${"a"}${"\u2000"}"); + Expect.equals("\ufeff\u2000ax", "${o2}${"\u2000"}${"a"}${o1}"); + + Expect.equals("\u2000x\ufeffa", "${"\u2000"}${o1}${o2}${"a"}"); + Expect.equals("\u2000\ufeffxa", "${"\u2000"}${o2}${o1}${"a"}"); + Expect.equals("x\u2000\ufeffa", "${o1}${"\u2000"}${o2}${"a"}"); + Expect.equals("x\ufeff\u2000a", "${o1}${o2}${"\u2000"}${"a"}"); + Expect.equals("\ufeffx\u2000a", "${o2}${o1}${"\u2000"}${"a"}"); + Expect.equals("\ufeff\u2000xa", "${o2}${"\u2000"}${o1}${"a"}"); +} diff --git a/tests/language/string/interpolation1_runtime_test.dart b/tests/language/string/interpolation1_runtime_test.dart new file mode 100644 index 00000000000..3ede1d84192 --- /dev/null +++ b/tests/language/string/interpolation1_runtime_test.dart @@ -0,0 +1,25 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// A dollar must be followed by a "{" or an identifier. + +class A { + final String str; + const A(this.str); +} + +class StringInterpolation1NegativeTest { + // Dollar not followed by "{" or identifier. + + static testMain() { + + } +} + +main() { + StringInterpolation1NegativeTest.testMain(); +} diff --git a/tests/language/string/interpolation1_test.dart b/tests/language/string/interpolation1_test.dart new file mode 100644 index 00000000000..7f43236fb69 --- /dev/null +++ b/tests/language/string/interpolation1_test.dart @@ -0,0 +1,29 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// A dollar must be followed by a "{" or an identifier. + +class A { + final String str; + const A(this.str); +} + +class StringInterpolation1NegativeTest { + // Dollar not followed by "{" or identifier. + static const DOLLAR = const A("$"); + // [error line 14, column 35, length 0] + // [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + // [error line 14, column 35, length 0] + // [analyzer] COMPILE_TIME_ERROR.INVALID_CONSTANT + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + static testMain() { + print(DOLLAR); + } +} + +main() { + StringInterpolation1NegativeTest.testMain(); +} diff --git a/tests/language/string/interpolation2_runtime_test.dart b/tests/language/string/interpolation2_runtime_test.dart new file mode 100644 index 00000000000..0b0a89f37d2 --- /dev/null +++ b/tests/language/string/interpolation2_runtime_test.dart @@ -0,0 +1,19 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// A dollar must be followed by a "{" or an identifier. + +class StringInterpolation2NegativeTest { + static testMain() { + // Dollar followed by "/". + + } +} + +main() { + StringInterpolation2NegativeTest.testMain(); +} diff --git a/tests/language/string/interpolation2_test.dart b/tests/language/string/interpolation2_test.dart new file mode 100644 index 00000000000..076fcc138b2 --- /dev/null +++ b/tests/language/string/interpolation2_test.dart @@ -0,0 +1,19 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// A dollar must be followed by a "{" or an identifier. + +class StringInterpolation2NegativeTest { + static testMain() { + // Dollar followed by "/". + print('C;Y1;X4;K"$/Month"'); + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + } +} + +main() { + StringInterpolation2NegativeTest.testMain(); +} diff --git a/tests/language/string/interpolation3_runtime_test.dart b/tests/language/string/interpolation3_runtime_test.dart new file mode 100644 index 00000000000..96b92fbdc80 --- /dev/null +++ b/tests/language/string/interpolation3_runtime_test.dart @@ -0,0 +1,19 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// A dollar must be followed by a "{" or an identifier. + +class StringInterpolation3NegativeTest { + static testMain() { + // Dollar followed by a number. + + } +} + +main() { + StringInterpolation3NegativeTest.testMain(); +} diff --git a/tests/language/string/interpolation3_test.dart b/tests/language/string/interpolation3_test.dart new file mode 100644 index 00000000000..0760fd9deec --- /dev/null +++ b/tests/language/string/interpolation3_test.dart @@ -0,0 +1,19 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// A dollar must be followed by a "{" or an identifier. + +class StringInterpolation3NegativeTest { + static testMain() { + // Dollar followed by a number. + print('F;P4;F$2R'); + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + } +} + +main() { + StringInterpolation3NegativeTest.testMain(); +} diff --git a/tests/language_2/string/interpolation6_runtime_test.dart b/tests/language/string/interpolation4_runtime_test.dart similarity index 79% rename from tests/language_2/string/interpolation6_runtime_test.dart rename to tests/language/string/interpolation4_runtime_test.dart index 4d4d546bcc3..e89625c0aaf 100644 --- a/tests/language_2/string/interpolation6_runtime_test.dart +++ b/tests/language/string/interpolation4_runtime_test.dart @@ -7,15 +7,13 @@ // A dollar must be followed by a "{" or an identifier. -class StringInterpolation6NegativeTest { +class StringInterpolation4NegativeTest { static testMain() { // Dollar not followed by "{" or identifier. - String regexp; - print(regexp); } } main() { - StringInterpolation6NegativeTest.testMain(); + StringInterpolation4NegativeTest.testMain(); } diff --git a/tests/language/string/interpolation4_test.dart b/tests/language/string/interpolation4_test.dart new file mode 100644 index 00000000000..740dc9a7373 --- /dev/null +++ b/tests/language/string/interpolation4_test.dart @@ -0,0 +1,19 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// A dollar must be followed by a "{" or an identifier. + +class StringInterpolation4NegativeTest { + static testMain() { + // Dollar not followed by "{" or identifier. + print("-" + "$" + "foo"); + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + } +} + +main() { + StringInterpolation4NegativeTest.testMain(); +} diff --git a/tests/language/string/interpolation5_runtime_test.dart b/tests/language/string/interpolation5_runtime_test.dart new file mode 100644 index 00000000000..acbec21dc6c --- /dev/null +++ b/tests/language/string/interpolation5_runtime_test.dart @@ -0,0 +1,19 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// A dollar must be followed by a "{" or an identifier. + +class StringInterpolation5NegativeTest { + static testMain() { + // Dollar followed by a number. + + } +} + +main() { + StringInterpolation5NegativeTest.testMain(); +} diff --git a/tests/language/string/interpolation5_test.dart b/tests/language/string/interpolation5_test.dart new file mode 100644 index 00000000000..cd04ed3198b --- /dev/null +++ b/tests/language/string/interpolation5_test.dart @@ -0,0 +1,19 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// A dollar must be followed by a "{" or an identifier. + +class StringInterpolation5NegativeTest { + static testMain() { + // Dollar followed by a number. + print("$1,000"); + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + } +} + +main() { + StringInterpolation5NegativeTest.testMain(); +} diff --git a/tests/language/string/interpolation6_test.dart b/tests/language/string/interpolation6_test.dart new file mode 100644 index 00000000000..74cfbbe6f49 --- /dev/null +++ b/tests/language/string/interpolation6_test.dart @@ -0,0 +1,21 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// A dollar must be followed by a "{" or an identifier. + +class StringInterpolation6NegativeTest { + static testMain() { + // Dollar not followed by "{" or identifier. + String regexp; + regexp = "^(\\d\\d?)[-/](\\d\\d?)$"; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + print(regexp); + } +} + +main() { + StringInterpolation6NegativeTest.testMain(); +} diff --git a/tests/language/string/interpolation7_test.dart b/tests/language/string/interpolation7_test.dart new file mode 100644 index 00000000000..77a07aa5f36 --- /dev/null +++ b/tests/language/string/interpolation7_test.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +// Dart test program testing string interpolation with toString on custom +// classes and on null. + +class A { + const A(); + String toString() { + return "A"; + } +} + +class StringInterpolation7Test { + static testMain() { + A? a = new A(); + Expect.equals("A + A", "$a + $a"); + a = null; + Expect.equals("null", "$a"); + } +} + +main() { + StringInterpolation7Test.testMain(); +} diff --git a/tests/language/string/interpolation8_test.dart b/tests/language/string/interpolation8_test.dart new file mode 100644 index 00000000000..a3c09bc5b56 --- /dev/null +++ b/tests/language/string/interpolation8_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. +// +// Allow assignment of string interpolation to a static const field + +import "package:expect/expect.dart"; + +class A { + static const x = 1; + static const y = "Two is greater than ${x}"; +} + +main() { + Expect.identical("Two is greater than 1", A.y); +} diff --git a/tests/language/string/interpolation9_runtime_test.dart b/tests/language/string/interpolation9_runtime_test.dart new file mode 100644 index 00000000000..3cf2bd10bfe --- /dev/null +++ b/tests/language/string/interpolation9_runtime_test.dart @@ -0,0 +1,38 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// 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. +// +// Almost valid string interpolation syntax. + +main() { + var x; + + + + + + + + + + + + + + + + + + + + + + + + + + return x; +} diff --git a/tests/language/string/interpolation9_test.dart b/tests/language/string/interpolation9_test.dart new file mode 100644 index 00000000000..b3166b76b60 --- /dev/null +++ b/tests/language/string/interpolation9_test.dart @@ -0,0 +1,95 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// 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. +// +// Almost valid string interpolation syntax. + +main() { + var x; + + x = "$"; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = "x$"; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = "$x$"; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = "$$x"; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = "$ "; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + + x = '$'; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = 'x$'; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = '$x$'; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = '$$x'; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = '$ '; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + + x = """$"""; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = """x$"""; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = """$x$"""; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = """$$x"""; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = """$ """; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + + x = '''$'''; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = '''x$'''; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = '''$x$'''; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = '''$$x'''; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + x = '''$ '''; + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER + // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}). + + return x; +} diff --git a/tests/language/string/interpolation_and_buffer_legacy_lib.dart b/tests/language/string/interpolation_and_buffer_legacy_lib.dart new file mode 100644 index 00000000000..c74b541ba47 --- /dev/null +++ b/tests/language/string/interpolation_and_buffer_legacy_lib.dart @@ -0,0 +1,9 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// 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. + +// @dart=2.6 + +class ToStringNull { + String toString() => null; +} diff --git a/tests/language/string/interpolation_and_buffer_legacy_test.dart b/tests/language/string/interpolation_and_buffer_legacy_test.dart new file mode 100644 index 00000000000..eb34ef20f30 --- /dev/null +++ b/tests/language/string/interpolation_and_buffer_legacy_test.dart @@ -0,0 +1,26 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// 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. + +// A null safe library cannot implement `toString()` and return `null`, but a +// legacy library, which may be called from null safe code, can. Test that that +// doesn't fail. + +// Requirements=nnbd-weak +import "package:expect/expect.dart"; + +import "interpolation_and_buffer_legacy_lib.dart"; + +void main() { + var n = ToStringNull(); + + // Throws immediately when evaluating the first interpolated expression. + Expect.throws(() => "$n${throw "unreachable"}"); + + // Throws immediately when adding object that doesn't return a String. + Expect.throws( + () => StringBuffer()..write(n)..write(throw "unreachable")); + + // Same behavior for constructor argument as if adding it to buffer later. + Expect.throws(() => StringBuffer(n)..write(throw "unreachable")); +} diff --git a/tests/language/string/interpolation_and_buffer_test.dart b/tests/language/string/interpolation_and_buffer_test.dart new file mode 100644 index 00000000000..7086276ce58 --- /dev/null +++ b/tests/language/string/interpolation_and_buffer_test.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// 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. + +// Interpolation calls `toString`. +// The evaluation of the interpolation fails if `toString` throws or returns +// null. In Dart 2, any method overriding `Object.toString` must return a +// `String` or `null`. In particular, if `object.toString()` returns null, then +// `"$object"` must not evaluate to the string `"null"`. +// +// The specification states that the expression of an interpolation is +// evaluated as follows: +// +// 1. Evaluate $e_i$ to an object $o_i$. +// 2. Invoke the `toString` method on *oi* with no arguments, +// and let *ri*$ be the returned value. +// 3. If *ri* is not an instance of the built-in type `String`, +// throw an `Error`. +// +// (Then the resulting strings are concatenated with the literal string parts). +// +// +// Adding an object to a `StringBuffer` behaves the same as evaluating +// an expression in an interpolation. It must immediately fail if the +// object's toString throws or returns `null`. +// +// This ensures that implementing interpolation via a `StringBuffer`is +// a valid implementation choice. + +import "package:expect/expect.dart"; + +class ToStringString { + String toString() => "String"; +} + +class ToStringThrows { + String toString() => throw "Throw"; +} + +void main() { + var s = ToStringString(); + var t = ToStringThrows(); + + Expect.equals("$s$s", "StringString"); + // Throws immediately when evaluating the first interpolated expression. + Expect.throws(() => "$t${throw "unreachable"}", (e) => e == "Throw"); + + // Throws immediately when adding object that doesn't return a String. + Expect.equals( + (StringBuffer()..write(s)..write(s)).toString(), "StringString"); + Expect.throws( + () => StringBuffer()..write(t)..write(throw "unreachable"), + (e) => e == "Throw"); + + // Same behavior for constructor argument as if adding it to buffer later. + Expect.equals((StringBuffer(s)..write(s)).toString(), "StringString"); + Expect.throws( + () => StringBuffer(t)..write(throw "unreachable"), (e) => e == "Throw"); +} diff --git a/tests/language/string/interpolation_newline_test.dart b/tests/language/string/interpolation_newline_test.dart new file mode 100644 index 00000000000..91ad04f5242 --- /dev/null +++ b/tests/language/string/interpolation_newline_test.dart @@ -0,0 +1,20 @@ +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file +// 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. + +/// Test of newlines in interpolated strings. + +main() { + String expected = '[[{{}: {}}]]'; + String a = "${ [ "${ [ '${ { '${ { } }' : { } } }' ] }" ] }"; + String b = "${ [ "${ [ '${ { '${ + { } }' : { } } }' ] }" ] }"; + String c = "${ [ "${ [ '${ { '${ + { + } }' : { + } } }' ] }" ] }"; + if (expected != a) throw 'expecteda: $expected != $a'; + if (a != b) throw 'ab: $a != $b'; + if (b != c) throw 'bc: $b != $c'; + print('$a$b$c'); +} diff --git a/tests/language/string/interpolation_runtime_test.dart b/tests/language/string/interpolation_runtime_test.dart new file mode 100644 index 00000000000..90623b8e31e --- /dev/null +++ b/tests/language/string/interpolation_runtime_test.dart @@ -0,0 +1,85 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +// Tests for string interpolation +class StringInterpolationTest { + StringInterpolationTest() {} + + static void m() {} + + static const int i = 1; + static const String a = ""; + + int j = -1; + int k = -1; + + static testMain(bool alwaysFalse) { + var test = new StringInterpolationTest(); + test.j = 3; + test.k = 5; + + // simple string + Expect.equals(" hi ", " hi "); + + var c1 = '1'; + var c2 = '2'; + var c3 = '3'; + var c4 = '4'; + // no chars before/after/between embedded expressions + Expect.equals(" 1", " ${c1}"); + Expect.equals("1 ", "${c1} "); + Expect.equals("1", "${c1}"); + Expect.equals("12", "${c1}${c2}"); + Expect.equals("12 34", "${c1}${c2} ${c3}${c4}"); + + // embedding static fields + Expect.equals(" hi 1 ", " hi ${i} "); + Expect.equals(" hi ", " hi ${a} "); + + // embedding method parameters + Expect.equals("param = 9", test.embedParams(9)); + + // embedding a class field + Expect.equals("j = 3", test.embedSingleField()); + + // embedding more than one (non-constant) expression + Expect.equals(" hi 1 ", " hi ${i} ${a}"); + Expect.equals("j = 3; k = 5", test.embedMultipleFields()); + + // escaping $ - doesn't start the embedded expression + Expect.equals("\$", "escaped \${3+2}"[12]); + Expect.equals("{", "escaped \${3+2}"[13]); + Expect.equals("3", "escaped \${3+2}"[14]); + Expect.equals("+", "escaped \${3+2}"[15]); + Expect.equals("2", "escaped \${3+2}"[16]); + Expect.equals("}", "escaped \${3+2}"[17]); + + if (alwaysFalse) { + + } + + Expect.equals("${m}", "$m"); + } + + String embedParams(int z) { + return "param = ${z}"; + } + + String embedSingleField() { + return "j = ${j}"; + } + + String embedMultipleFields() { + return "j = ${j}; k = ${k}"; + } +} + +main() { + StringInterpolationTest.testMain(false); +} diff --git a/tests/language/string/interpolation_test.dart b/tests/language/string/interpolation_test.dart new file mode 100644 index 00000000000..50968b09721 --- /dev/null +++ b/tests/language/string/interpolation_test.dart @@ -0,0 +1,85 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +// Tests for string interpolation +class StringInterpolationTest { + StringInterpolationTest() {} + + static void m() {} + + static const int i = 1; + static const String a = ""; + + int j = -1; + int k = -1; + + static testMain(bool alwaysFalse) { + var test = new StringInterpolationTest(); + test.j = 3; + test.k = 5; + + // simple string + Expect.equals(" hi ", " hi "); + + var c1 = '1'; + var c2 = '2'; + var c3 = '3'; + var c4 = '4'; + // no chars before/after/between embedded expressions + Expect.equals(" 1", " ${c1}"); + Expect.equals("1 ", "${c1} "); + Expect.equals("1", "${c1}"); + Expect.equals("12", "${c1}${c2}"); + Expect.equals("12 34", "${c1}${c2} ${c3}${c4}"); + + // embedding static fields + Expect.equals(" hi 1 ", " hi ${i} "); + Expect.equals(" hi ", " hi ${a} "); + + // embedding method parameters + Expect.equals("param = 9", test.embedParams(9)); + + // embedding a class field + Expect.equals("j = 3", test.embedSingleField()); + + // embedding more than one (non-constant) expression + Expect.equals(" hi 1 ", " hi ${i} ${a}"); + Expect.equals("j = 3; k = 5", test.embedMultipleFields()); + + // escaping $ - doesn't start the embedded expression + Expect.equals("\$", "escaped \${3+2}"[12]); + Expect.equals("{", "escaped \${3+2}"[13]); + Expect.equals("3", "escaped \${3+2}"[14]); + Expect.equals("+", "escaped \${3+2}"[15]); + Expect.equals("2", "escaped \${3+2}"[16]); + Expect.equals("}", "escaped \${3+2}"[17]); + + if (alwaysFalse) { + "${i.toHorse()}"; + // ^^^^^^^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_METHOD + // [cfe] The method 'toHorse' isn't defined for the class 'int'. + } + + Expect.equals("${m}", "$m"); + } + + String embedParams(int z) { + return "param = ${z}"; + } + + String embedSingleField() { + return "j = ${j}"; + } + + String embedMultipleFields() { + return "j = ${j}; k = ${k}"; + } +} + +main() { + StringInterpolationTest.testMain(false); +} diff --git a/tests/language/string/intrinsics_test.dart b/tests/language/string/intrinsics_test.dart new file mode 100644 index 00000000000..ed1521cbeba --- /dev/null +++ b/tests/language/string/intrinsics_test.dart @@ -0,0 +1,27 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// 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. +// Replace with shared test once interface issues clarified. +// Test various String intrinsics +// VMOptions=--optimization-counter-threshold=10 + +import "package:expect/expect.dart"; + +main() { + var oneByte = "Hello world"; + var empty = ""; + for (int i = 0; i < 20; i++) { + Expect.equals(11, testLength(oneByte)); + Expect.equals(0, testLength(empty)); + Expect.isFalse(testIsEmpty(oneByte)); + Expect.isTrue(testIsEmpty(empty)); + } +} + +testLength(s) { + return s.length; +} + +testIsEmpty(s) { + return s.isEmpty; +} diff --git a/tests/language/string/join_test.dart b/tests/language/string/join_test.dart new file mode 100644 index 00000000000..0cc06f837fe --- /dev/null +++ b/tests/language/string/join_test.dart @@ -0,0 +1,18 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. +// Regression test ensuring that only ObjectArrays are handed to the VM code. + +import "package:expect/expect.dart"; + +class StringJoinTest { + static testMain() { + List ga = ["a", "b"]; + Expect.equals("ab", ga.join()); + Expect.equals("ab", ga.join("")); + } +} + +main() { + StringJoinTest.testMain(); +} diff --git a/tests/language/string/literals_test.dart b/tests/language/string/literals_test.dart new file mode 100644 index 00000000000..6b4f4f50706 --- /dev/null +++ b/tests/language/string/literals_test.dart @@ -0,0 +1,38 @@ +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +main() { + var expect = new String.fromCharCodes( + [0, 0x0a, 0x0d, 0x7f, 0xff, 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff]); + test(string) { + Expect.equals(expect, string); + } + + // Plain escapes of code points. + test("\x00\x0a\x0d\x7f\xff\uffff\u{10000}\u{10ffff}"); + test("""\x00\x0a\x0d\x7f\xff\uffff\u{10000}\u{10ffff}"""); + test('\x00\x0a\x0d\x7f\xff\uffff\u{10000}\u{10ffff}'); + test('''\x00\x0a\x0d\x7f\xff\uffff\u{10000}\u{10ffff}'''); + // Plain escapes of individual code units. + test("\x00\x0a\x0d\x7f\xff\uffff\ud800\udc00\udbff\udfff"); + test("""\x00\x0a\x0d\x7f\xff\uffff\ud800\udc00\udbff\udfff"""); + test('\x00\x0a\x0d\x7f\xff\uffff\ud800\udc00\udbff\udfff'); + test('''\x00\x0a\x0d\x7f\xff\uffff\ud800\udc00\udbff\udfff'''); + // Insert newline into multiline string. + test("""\x00 +\x0d\x7f\xff\uffff\ud800\udc00\udbff\udfff"""); + test('''\x00 +\x0d\x7f\xff\uffff\ud800\udc00\udbff\udfff'''); + // Extract code points from multi-character escape string. + test("\x00\x0a\x0d\x7f\xff\uffff" + "${"\u{10000}"[0]}${"\u{10000}"[1]}" + "${"\u{10FFFF}"[0]}${"\u{10FFFF}"[1]}"); + test("\x00\x0a\x0d\x7f\xff\uffff" + "\ud800" + "\udc00\udbff" + "\udfff"); + // Single line string over multiple lines with newlines inside interpolation. + test("\x00\x0a\x0d\x7f\xff${ + "" + }\uffff\ud800\udc00\udbff\udfff"); +} diff --git a/tests/language/string/multiline_newline_cr.dart b/tests/language/string/multiline_newline_cr.dart new file mode 100644 index 00000000000..1b0627a8d50 --- /dev/null +++ b/tests/language/string/multiline_newline_cr.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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; + +const constantMultilineString = """ +a +b +"""; + +var nonConstantMultilineString = """ +a +b +"""; + +const constantRawMultilineString = r""" +\a +\b +"""; + +var nonConstantRawMultilineString = r""" +\a +\b +"""; diff --git a/tests/language/string/multiline_newline_crlf.dart b/tests/language/string/multiline_newline_crlf.dart new file mode 100644 index 00000000000..958a82c8499 --- /dev/null +++ b/tests/language/string/multiline_newline_crlf.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. +// It requires an entry in the .gitattributes file. + +library multiline_newline_crlf; + +const constantMultilineString = """ +a +b +"""; + +var nonConstantMultilineString = """ +a +b +"""; + +const constantRawMultilineString = r""" +\a +\b +"""; + +var nonConstantRawMultilineString = r""" +\a +\b +"""; \ No newline at end of file diff --git a/tests/language/string/multiline_newline_lf.dart b/tests/language/string/multiline_newline_lf.dart new file mode 100644 index 00000000000..b13fbab6a08 --- /dev/null +++ b/tests/language/string/multiline_newline_lf.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. +// It requires an entry in the .gitattributes file. + +library multiline_newline_lf; + +const constantMultilineString = """ +a +b +"""; + +var nonConstantMultilineString = """ +a +b +"""; + +const constantRawMultilineString = r""" +\a +\b +"""; + +var nonConstantRawMultilineString = r""" +\a +\b +"""; diff --git a/tests/language/string/multiline_newline_runtime_1_test.dart b/tests/language/string/multiline_newline_runtime_1_test.dart new file mode 100644 index 00000000000..0b4647a3129 --- /dev/null +++ b/tests/language/string/multiline_newline_runtime_1_test.dart @@ -0,0 +1,128 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'multiline_newline_cr.dart' as cr; +import 'multiline_newline_crlf.dart' as crlf; +import 'multiline_newline_lf.dart' as lf; + +main() { + Expect.equals(4, cr.constantMultilineString.length); + Expect.equals(4, crlf.constantMultilineString.length); + Expect.equals(4, lf.constantMultilineString.length); + + Expect.equals(6, cr.constantRawMultilineString.length); + Expect.equals(6, crlf.constantRawMultilineString.length); + Expect.equals(6, lf.constantRawMultilineString.length); + + Expect.equals(cr.constantMultilineString, crlf.constantMultilineString); + Expect.equals(crlf.constantMultilineString, lf.constantMultilineString); + Expect.equals(lf.constantMultilineString, cr.constantMultilineString); + + Expect.equals(cr.constantRawMultilineString, crlf.constantRawMultilineString); + Expect.equals(crlf.constantRawMultilineString, lf.constantRawMultilineString); + Expect.equals(lf.constantRawMultilineString, cr.constantRawMultilineString); + + Expect.equals(4, cr.nonConstantMultilineString.length); + Expect.equals(4, crlf.nonConstantMultilineString.length); + Expect.equals(4, lf.nonConstantMultilineString.length); + + Expect.equals(6, cr.nonConstantRawMultilineString.length); + Expect.equals(6, crlf.nonConstantRawMultilineString.length); + Expect.equals(6, lf.nonConstantRawMultilineString.length); + + Expect.equals(cr.nonConstantMultilineString, crlf.nonConstantMultilineString); + Expect.equals(crlf.nonConstantMultilineString, lf.nonConstantMultilineString); + Expect.equals(lf.nonConstantMultilineString, cr.nonConstantMultilineString); + + Expect.equals( + cr.nonConstantRawMultilineString, crlf.nonConstantRawMultilineString); + Expect.equals( + crlf.nonConstantRawMultilineString, lf.nonConstantRawMultilineString); + Expect.equals( + lf.nonConstantRawMultilineString, cr.nonConstantRawMultilineString); + + const c1 = + cr.constantMultilineString == crlf.constantMultilineString ? true : null; + const c2 = + crlf.constantMultilineString == lf.constantMultilineString ? true : null; + const c3 = + lf.constantMultilineString == cr.constantMultilineString ? true : null; + Expect.isTrue(c1); + Expect.isTrue(c2); + Expect.isTrue(c3); + + const c1r = cr.constantRawMultilineString == crlf.constantRawMultilineString + ? true + : null; + const c2r = crlf.constantRawMultilineString == lf.constantRawMultilineString + ? true + : null; + const c3r = lf.constantRawMultilineString == cr.constantRawMultilineString + ? true + : null; + Expect.isTrue(c1r); + Expect.isTrue(c2r); + Expect.isTrue(c3r); + + const c4 = c1 == true ? 1 : 2; + Expect.equals(1, c4); + + + + + + + + + + + + + + + + + const c7 = + cr.constantMultilineString != crlf.constantMultilineString ? true : null; + const c8 = + crlf.constantMultilineString != lf.constantMultilineString ? true : null; + const c9 = + lf.constantMultilineString != cr.constantMultilineString ? true : null; + Expect.isNull(c7); + Expect.isNull(c8); + Expect.isNull(c9); + + const c7r = cr.constantRawMultilineString != crlf.constantRawMultilineString + ? true + : null; + const c8r = crlf.constantRawMultilineString != lf.constantRawMultilineString + ? true + : null; + const c9r = lf.constantRawMultilineString != cr.constantRawMultilineString + ? true + : null; + Expect.isNull(c7r); + Expect.isNull(c8r); + Expect.isNull(c9r); + + // What's the deal with the compile-time errors below? This is to validate + // that constants are evaluated correctly at compile-time (or analysis + // time). For example, only if [c7] is evaluated correctly does it become + // null which leads to a compile-time error (as it isn't a boolean). For + // tools like dart2js, this ensures that the compile-time evaluation of + // constants is similar to the runtime evaluation tested above. For tools + // like the analyzer, this ensures that evaluation is tested (there's no + // runtime evaluation). + + + + + + + +} diff --git a/tests/language/string/multiline_newline_runtime_2_test.dart b/tests/language/string/multiline_newline_runtime_2_test.dart new file mode 100644 index 00000000000..984ee097ccf --- /dev/null +++ b/tests/language/string/multiline_newline_runtime_2_test.dart @@ -0,0 +1,128 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'multiline_newline_cr.dart' as cr; +import 'multiline_newline_crlf.dart' as crlf; +import 'multiline_newline_lf.dart' as lf; + +main() { + Expect.equals(4, cr.constantMultilineString.length); + Expect.equals(4, crlf.constantMultilineString.length); + Expect.equals(4, lf.constantMultilineString.length); + + Expect.equals(6, cr.constantRawMultilineString.length); + Expect.equals(6, crlf.constantRawMultilineString.length); + Expect.equals(6, lf.constantRawMultilineString.length); + + Expect.equals(cr.constantMultilineString, crlf.constantMultilineString); + Expect.equals(crlf.constantMultilineString, lf.constantMultilineString); + Expect.equals(lf.constantMultilineString, cr.constantMultilineString); + + Expect.equals(cr.constantRawMultilineString, crlf.constantRawMultilineString); + Expect.equals(crlf.constantRawMultilineString, lf.constantRawMultilineString); + Expect.equals(lf.constantRawMultilineString, cr.constantRawMultilineString); + + Expect.equals(4, cr.nonConstantMultilineString.length); + Expect.equals(4, crlf.nonConstantMultilineString.length); + Expect.equals(4, lf.nonConstantMultilineString.length); + + Expect.equals(6, cr.nonConstantRawMultilineString.length); + Expect.equals(6, crlf.nonConstantRawMultilineString.length); + Expect.equals(6, lf.nonConstantRawMultilineString.length); + + Expect.equals(cr.nonConstantMultilineString, crlf.nonConstantMultilineString); + Expect.equals(crlf.nonConstantMultilineString, lf.nonConstantMultilineString); + Expect.equals(lf.nonConstantMultilineString, cr.nonConstantMultilineString); + + Expect.equals( + cr.nonConstantRawMultilineString, crlf.nonConstantRawMultilineString); + Expect.equals( + crlf.nonConstantRawMultilineString, lf.nonConstantRawMultilineString); + Expect.equals( + lf.nonConstantRawMultilineString, cr.nonConstantRawMultilineString); + + const c1 = + cr.constantMultilineString == crlf.constantMultilineString ? true : null; + const c2 = + crlf.constantMultilineString == lf.constantMultilineString ? true : null; + const c3 = + lf.constantMultilineString == cr.constantMultilineString ? true : null; + Expect.isTrue(c1); + Expect.isTrue(c2); + Expect.isTrue(c3); + + const c1r = cr.constantRawMultilineString == crlf.constantRawMultilineString + ? true + : null; + const c2r = crlf.constantRawMultilineString == lf.constantRawMultilineString + ? true + : null; + const c3r = lf.constantRawMultilineString == cr.constantRawMultilineString + ? true + : null; + Expect.isTrue(c1r); + Expect.isTrue(c2r); + Expect.isTrue(c3r); + + + + + const c5 = c2 == true ? 2 : 3; + Expect.equals(2, c5); + + + + + + + + + + + + + + const c7 = + cr.constantMultilineString != crlf.constantMultilineString ? true : null; + const c8 = + crlf.constantMultilineString != lf.constantMultilineString ? true : null; + const c9 = + lf.constantMultilineString != cr.constantMultilineString ? true : null; + Expect.isNull(c7); + Expect.isNull(c8); + Expect.isNull(c9); + + const c7r = cr.constantRawMultilineString != crlf.constantRawMultilineString + ? true + : null; + const c8r = crlf.constantRawMultilineString != lf.constantRawMultilineString + ? true + : null; + const c9r = lf.constantRawMultilineString != cr.constantRawMultilineString + ? true + : null; + Expect.isNull(c7r); + Expect.isNull(c8r); + Expect.isNull(c9r); + + // What's the deal with the compile-time errors below? This is to validate + // that constants are evaluated correctly at compile-time (or analysis + // time). For example, only if [c7] is evaluated correctly does it become + // null which leads to a compile-time error (as it isn't a boolean). For + // tools like dart2js, this ensures that the compile-time evaluation of + // constants is similar to the runtime evaluation tested above. For tools + // like the analyzer, this ensures that evaluation is tested (there's no + // runtime evaluation). + + + + + + + +} diff --git a/tests/language/string/multiline_newline_runtime_3_test.dart b/tests/language/string/multiline_newline_runtime_3_test.dart new file mode 100644 index 00000000000..8208eeae74b --- /dev/null +++ b/tests/language/string/multiline_newline_runtime_3_test.dart @@ -0,0 +1,128 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'multiline_newline_cr.dart' as cr; +import 'multiline_newline_crlf.dart' as crlf; +import 'multiline_newline_lf.dart' as lf; + +main() { + Expect.equals(4, cr.constantMultilineString.length); + Expect.equals(4, crlf.constantMultilineString.length); + Expect.equals(4, lf.constantMultilineString.length); + + Expect.equals(6, cr.constantRawMultilineString.length); + Expect.equals(6, crlf.constantRawMultilineString.length); + Expect.equals(6, lf.constantRawMultilineString.length); + + Expect.equals(cr.constantMultilineString, crlf.constantMultilineString); + Expect.equals(crlf.constantMultilineString, lf.constantMultilineString); + Expect.equals(lf.constantMultilineString, cr.constantMultilineString); + + Expect.equals(cr.constantRawMultilineString, crlf.constantRawMultilineString); + Expect.equals(crlf.constantRawMultilineString, lf.constantRawMultilineString); + Expect.equals(lf.constantRawMultilineString, cr.constantRawMultilineString); + + Expect.equals(4, cr.nonConstantMultilineString.length); + Expect.equals(4, crlf.nonConstantMultilineString.length); + Expect.equals(4, lf.nonConstantMultilineString.length); + + Expect.equals(6, cr.nonConstantRawMultilineString.length); + Expect.equals(6, crlf.nonConstantRawMultilineString.length); + Expect.equals(6, lf.nonConstantRawMultilineString.length); + + Expect.equals(cr.nonConstantMultilineString, crlf.nonConstantMultilineString); + Expect.equals(crlf.nonConstantMultilineString, lf.nonConstantMultilineString); + Expect.equals(lf.nonConstantMultilineString, cr.nonConstantMultilineString); + + Expect.equals( + cr.nonConstantRawMultilineString, crlf.nonConstantRawMultilineString); + Expect.equals( + crlf.nonConstantRawMultilineString, lf.nonConstantRawMultilineString); + Expect.equals( + lf.nonConstantRawMultilineString, cr.nonConstantRawMultilineString); + + const c1 = + cr.constantMultilineString == crlf.constantMultilineString ? true : null; + const c2 = + crlf.constantMultilineString == lf.constantMultilineString ? true : null; + const c3 = + lf.constantMultilineString == cr.constantMultilineString ? true : null; + Expect.isTrue(c1); + Expect.isTrue(c2); + Expect.isTrue(c3); + + const c1r = cr.constantRawMultilineString == crlf.constantRawMultilineString + ? true + : null; + const c2r = crlf.constantRawMultilineString == lf.constantRawMultilineString + ? true + : null; + const c3r = lf.constantRawMultilineString == cr.constantRawMultilineString + ? true + : null; + Expect.isTrue(c1r); + Expect.isTrue(c2r); + Expect.isTrue(c3r); + + + + + + + + const c6 = c3 == true ? 3 : 4; + Expect.equals(3, c6); + + + + + + + + + + + const c7 = + cr.constantMultilineString != crlf.constantMultilineString ? true : null; + const c8 = + crlf.constantMultilineString != lf.constantMultilineString ? true : null; + const c9 = + lf.constantMultilineString != cr.constantMultilineString ? true : null; + Expect.isNull(c7); + Expect.isNull(c8); + Expect.isNull(c9); + + const c7r = cr.constantRawMultilineString != crlf.constantRawMultilineString + ? true + : null; + const c8r = crlf.constantRawMultilineString != lf.constantRawMultilineString + ? true + : null; + const c9r = lf.constantRawMultilineString != cr.constantRawMultilineString + ? true + : null; + Expect.isNull(c7r); + Expect.isNull(c8r); + Expect.isNull(c9r); + + // What's the deal with the compile-time errors below? This is to validate + // that constants are evaluated correctly at compile-time (or analysis + // time). For example, only if [c7] is evaluated correctly does it become + // null which leads to a compile-time error (as it isn't a boolean). For + // tools like dart2js, this ensures that the compile-time evaluation of + // constants is similar to the runtime evaluation tested above. For tools + // like the analyzer, this ensures that evaluation is tested (there's no + // runtime evaluation). + + + + + + + +} diff --git a/tests/language/string/multiline_newline_runtime_4_test.dart b/tests/language/string/multiline_newline_runtime_4_test.dart new file mode 100644 index 00000000000..caef817dd07 --- /dev/null +++ b/tests/language/string/multiline_newline_runtime_4_test.dart @@ -0,0 +1,128 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'multiline_newline_cr.dart' as cr; +import 'multiline_newline_crlf.dart' as crlf; +import 'multiline_newline_lf.dart' as lf; + +main() { + Expect.equals(4, cr.constantMultilineString.length); + Expect.equals(4, crlf.constantMultilineString.length); + Expect.equals(4, lf.constantMultilineString.length); + + Expect.equals(6, cr.constantRawMultilineString.length); + Expect.equals(6, crlf.constantRawMultilineString.length); + Expect.equals(6, lf.constantRawMultilineString.length); + + Expect.equals(cr.constantMultilineString, crlf.constantMultilineString); + Expect.equals(crlf.constantMultilineString, lf.constantMultilineString); + Expect.equals(lf.constantMultilineString, cr.constantMultilineString); + + Expect.equals(cr.constantRawMultilineString, crlf.constantRawMultilineString); + Expect.equals(crlf.constantRawMultilineString, lf.constantRawMultilineString); + Expect.equals(lf.constantRawMultilineString, cr.constantRawMultilineString); + + Expect.equals(4, cr.nonConstantMultilineString.length); + Expect.equals(4, crlf.nonConstantMultilineString.length); + Expect.equals(4, lf.nonConstantMultilineString.length); + + Expect.equals(6, cr.nonConstantRawMultilineString.length); + Expect.equals(6, crlf.nonConstantRawMultilineString.length); + Expect.equals(6, lf.nonConstantRawMultilineString.length); + + Expect.equals(cr.nonConstantMultilineString, crlf.nonConstantMultilineString); + Expect.equals(crlf.nonConstantMultilineString, lf.nonConstantMultilineString); + Expect.equals(lf.nonConstantMultilineString, cr.nonConstantMultilineString); + + Expect.equals( + cr.nonConstantRawMultilineString, crlf.nonConstantRawMultilineString); + Expect.equals( + crlf.nonConstantRawMultilineString, lf.nonConstantRawMultilineString); + Expect.equals( + lf.nonConstantRawMultilineString, cr.nonConstantRawMultilineString); + + const c1 = + cr.constantMultilineString == crlf.constantMultilineString ? true : null; + const c2 = + crlf.constantMultilineString == lf.constantMultilineString ? true : null; + const c3 = + lf.constantMultilineString == cr.constantMultilineString ? true : null; + Expect.isTrue(c1); + Expect.isTrue(c2); + Expect.isTrue(c3); + + const c1r = cr.constantRawMultilineString == crlf.constantRawMultilineString + ? true + : null; + const c2r = crlf.constantRawMultilineString == lf.constantRawMultilineString + ? true + : null; + const c3r = lf.constantRawMultilineString == cr.constantRawMultilineString + ? true + : null; + Expect.isTrue(c1r); + Expect.isTrue(c2r); + Expect.isTrue(c3r); + + + + + + + + + + + const c4r = c1r == true ? 1 : 2; + Expect.equals(1, c4r); + + + + + + + + const c7 = + cr.constantMultilineString != crlf.constantMultilineString ? true : null; + const c8 = + crlf.constantMultilineString != lf.constantMultilineString ? true : null; + const c9 = + lf.constantMultilineString != cr.constantMultilineString ? true : null; + Expect.isNull(c7); + Expect.isNull(c8); + Expect.isNull(c9); + + const c7r = cr.constantRawMultilineString != crlf.constantRawMultilineString + ? true + : null; + const c8r = crlf.constantRawMultilineString != lf.constantRawMultilineString + ? true + : null; + const c9r = lf.constantRawMultilineString != cr.constantRawMultilineString + ? true + : null; + Expect.isNull(c7r); + Expect.isNull(c8r); + Expect.isNull(c9r); + + // What's the deal with the compile-time errors below? This is to validate + // that constants are evaluated correctly at compile-time (or analysis + // time). For example, only if [c7] is evaluated correctly does it become + // null which leads to a compile-time error (as it isn't a boolean). For + // tools like dart2js, this ensures that the compile-time evaluation of + // constants is similar to the runtime evaluation tested above. For tools + // like the analyzer, this ensures that evaluation is tested (there's no + // runtime evaluation). + + + + + + + +} diff --git a/tests/language/string/multiline_newline_runtime_5_test.dart b/tests/language/string/multiline_newline_runtime_5_test.dart new file mode 100644 index 00000000000..6510e9cc205 --- /dev/null +++ b/tests/language/string/multiline_newline_runtime_5_test.dart @@ -0,0 +1,128 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'multiline_newline_cr.dart' as cr; +import 'multiline_newline_crlf.dart' as crlf; +import 'multiline_newline_lf.dart' as lf; + +main() { + Expect.equals(4, cr.constantMultilineString.length); + Expect.equals(4, crlf.constantMultilineString.length); + Expect.equals(4, lf.constantMultilineString.length); + + Expect.equals(6, cr.constantRawMultilineString.length); + Expect.equals(6, crlf.constantRawMultilineString.length); + Expect.equals(6, lf.constantRawMultilineString.length); + + Expect.equals(cr.constantMultilineString, crlf.constantMultilineString); + Expect.equals(crlf.constantMultilineString, lf.constantMultilineString); + Expect.equals(lf.constantMultilineString, cr.constantMultilineString); + + Expect.equals(cr.constantRawMultilineString, crlf.constantRawMultilineString); + Expect.equals(crlf.constantRawMultilineString, lf.constantRawMultilineString); + Expect.equals(lf.constantRawMultilineString, cr.constantRawMultilineString); + + Expect.equals(4, cr.nonConstantMultilineString.length); + Expect.equals(4, crlf.nonConstantMultilineString.length); + Expect.equals(4, lf.nonConstantMultilineString.length); + + Expect.equals(6, cr.nonConstantRawMultilineString.length); + Expect.equals(6, crlf.nonConstantRawMultilineString.length); + Expect.equals(6, lf.nonConstantRawMultilineString.length); + + Expect.equals(cr.nonConstantMultilineString, crlf.nonConstantMultilineString); + Expect.equals(crlf.nonConstantMultilineString, lf.nonConstantMultilineString); + Expect.equals(lf.nonConstantMultilineString, cr.nonConstantMultilineString); + + Expect.equals( + cr.nonConstantRawMultilineString, crlf.nonConstantRawMultilineString); + Expect.equals( + crlf.nonConstantRawMultilineString, lf.nonConstantRawMultilineString); + Expect.equals( + lf.nonConstantRawMultilineString, cr.nonConstantRawMultilineString); + + const c1 = + cr.constantMultilineString == crlf.constantMultilineString ? true : null; + const c2 = + crlf.constantMultilineString == lf.constantMultilineString ? true : null; + const c3 = + lf.constantMultilineString == cr.constantMultilineString ? true : null; + Expect.isTrue(c1); + Expect.isTrue(c2); + Expect.isTrue(c3); + + const c1r = cr.constantRawMultilineString == crlf.constantRawMultilineString + ? true + : null; + const c2r = crlf.constantRawMultilineString == lf.constantRawMultilineString + ? true + : null; + const c3r = lf.constantRawMultilineString == cr.constantRawMultilineString + ? true + : null; + Expect.isTrue(c1r); + Expect.isTrue(c2r); + Expect.isTrue(c3r); + + + + + + + + + + + + + + const c5r = c2r == true ? 2 : 3; + Expect.equals(2, c5r); + + + + + const c7 = + cr.constantMultilineString != crlf.constantMultilineString ? true : null; + const c8 = + crlf.constantMultilineString != lf.constantMultilineString ? true : null; + const c9 = + lf.constantMultilineString != cr.constantMultilineString ? true : null; + Expect.isNull(c7); + Expect.isNull(c8); + Expect.isNull(c9); + + const c7r = cr.constantRawMultilineString != crlf.constantRawMultilineString + ? true + : null; + const c8r = crlf.constantRawMultilineString != lf.constantRawMultilineString + ? true + : null; + const c9r = lf.constantRawMultilineString != cr.constantRawMultilineString + ? true + : null; + Expect.isNull(c7r); + Expect.isNull(c8r); + Expect.isNull(c9r); + + // What's the deal with the compile-time errors below? This is to validate + // that constants are evaluated correctly at compile-time (or analysis + // time). For example, only if [c7] is evaluated correctly does it become + // null which leads to a compile-time error (as it isn't a boolean). For + // tools like dart2js, this ensures that the compile-time evaluation of + // constants is similar to the runtime evaluation tested above. For tools + // like the analyzer, this ensures that evaluation is tested (there's no + // runtime evaluation). + + + + + + + +} diff --git a/tests/language/string/multiline_newline_runtime_6_test.dart b/tests/language/string/multiline_newline_runtime_6_test.dart new file mode 100644 index 00000000000..353fb285d07 --- /dev/null +++ b/tests/language/string/multiline_newline_runtime_6_test.dart @@ -0,0 +1,128 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'multiline_newline_cr.dart' as cr; +import 'multiline_newline_crlf.dart' as crlf; +import 'multiline_newline_lf.dart' as lf; + +main() { + Expect.equals(4, cr.constantMultilineString.length); + Expect.equals(4, crlf.constantMultilineString.length); + Expect.equals(4, lf.constantMultilineString.length); + + Expect.equals(6, cr.constantRawMultilineString.length); + Expect.equals(6, crlf.constantRawMultilineString.length); + Expect.equals(6, lf.constantRawMultilineString.length); + + Expect.equals(cr.constantMultilineString, crlf.constantMultilineString); + Expect.equals(crlf.constantMultilineString, lf.constantMultilineString); + Expect.equals(lf.constantMultilineString, cr.constantMultilineString); + + Expect.equals(cr.constantRawMultilineString, crlf.constantRawMultilineString); + Expect.equals(crlf.constantRawMultilineString, lf.constantRawMultilineString); + Expect.equals(lf.constantRawMultilineString, cr.constantRawMultilineString); + + Expect.equals(4, cr.nonConstantMultilineString.length); + Expect.equals(4, crlf.nonConstantMultilineString.length); + Expect.equals(4, lf.nonConstantMultilineString.length); + + Expect.equals(6, cr.nonConstantRawMultilineString.length); + Expect.equals(6, crlf.nonConstantRawMultilineString.length); + Expect.equals(6, lf.nonConstantRawMultilineString.length); + + Expect.equals(cr.nonConstantMultilineString, crlf.nonConstantMultilineString); + Expect.equals(crlf.nonConstantMultilineString, lf.nonConstantMultilineString); + Expect.equals(lf.nonConstantMultilineString, cr.nonConstantMultilineString); + + Expect.equals( + cr.nonConstantRawMultilineString, crlf.nonConstantRawMultilineString); + Expect.equals( + crlf.nonConstantRawMultilineString, lf.nonConstantRawMultilineString); + Expect.equals( + lf.nonConstantRawMultilineString, cr.nonConstantRawMultilineString); + + const c1 = + cr.constantMultilineString == crlf.constantMultilineString ? true : null; + const c2 = + crlf.constantMultilineString == lf.constantMultilineString ? true : null; + const c3 = + lf.constantMultilineString == cr.constantMultilineString ? true : null; + Expect.isTrue(c1); + Expect.isTrue(c2); + Expect.isTrue(c3); + + const c1r = cr.constantRawMultilineString == crlf.constantRawMultilineString + ? true + : null; + const c2r = crlf.constantRawMultilineString == lf.constantRawMultilineString + ? true + : null; + const c3r = lf.constantRawMultilineString == cr.constantRawMultilineString + ? true + : null; + Expect.isTrue(c1r); + Expect.isTrue(c2r); + Expect.isTrue(c3r); + + + + + + + + + + + + + + + + + const c6r = c3r == true ? 3 : 4; + Expect.equals(3, c6r); + + const c7 = + cr.constantMultilineString != crlf.constantMultilineString ? true : null; + const c8 = + crlf.constantMultilineString != lf.constantMultilineString ? true : null; + const c9 = + lf.constantMultilineString != cr.constantMultilineString ? true : null; + Expect.isNull(c7); + Expect.isNull(c8); + Expect.isNull(c9); + + const c7r = cr.constantRawMultilineString != crlf.constantRawMultilineString + ? true + : null; + const c8r = crlf.constantRawMultilineString != lf.constantRawMultilineString + ? true + : null; + const c9r = lf.constantRawMultilineString != cr.constantRawMultilineString + ? true + : null; + Expect.isNull(c7r); + Expect.isNull(c8r); + Expect.isNull(c9r); + + // What's the deal with the compile-time errors below? This is to validate + // that constants are evaluated correctly at compile-time (or analysis + // time). For example, only if [c7] is evaluated correctly does it become + // null which leads to a compile-time error (as it isn't a boolean). For + // tools like dart2js, this ensures that the compile-time evaluation of + // constants is similar to the runtime evaluation tested above. For tools + // like the analyzer, this ensures that evaluation is tested (there's no + // runtime evaluation). + + + + + + + +} diff --git a/tests/language/string/multiline_newline_runtime_test.dart b/tests/language/string/multiline_newline_runtime_test.dart new file mode 100644 index 00000000000..7fa95cad940 --- /dev/null +++ b/tests/language/string/multiline_newline_runtime_test.dart @@ -0,0 +1,128 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'multiline_newline_cr.dart' as cr; +import 'multiline_newline_crlf.dart' as crlf; +import 'multiline_newline_lf.dart' as lf; + +main() { + Expect.equals(4, cr.constantMultilineString.length); + Expect.equals(4, crlf.constantMultilineString.length); + Expect.equals(4, lf.constantMultilineString.length); + + Expect.equals(6, cr.constantRawMultilineString.length); + Expect.equals(6, crlf.constantRawMultilineString.length); + Expect.equals(6, lf.constantRawMultilineString.length); + + Expect.equals(cr.constantMultilineString, crlf.constantMultilineString); + Expect.equals(crlf.constantMultilineString, lf.constantMultilineString); + Expect.equals(lf.constantMultilineString, cr.constantMultilineString); + + Expect.equals(cr.constantRawMultilineString, crlf.constantRawMultilineString); + Expect.equals(crlf.constantRawMultilineString, lf.constantRawMultilineString); + Expect.equals(lf.constantRawMultilineString, cr.constantRawMultilineString); + + Expect.equals(4, cr.nonConstantMultilineString.length); + Expect.equals(4, crlf.nonConstantMultilineString.length); + Expect.equals(4, lf.nonConstantMultilineString.length); + + Expect.equals(6, cr.nonConstantRawMultilineString.length); + Expect.equals(6, crlf.nonConstantRawMultilineString.length); + Expect.equals(6, lf.nonConstantRawMultilineString.length); + + Expect.equals(cr.nonConstantMultilineString, crlf.nonConstantMultilineString); + Expect.equals(crlf.nonConstantMultilineString, lf.nonConstantMultilineString); + Expect.equals(lf.nonConstantMultilineString, cr.nonConstantMultilineString); + + Expect.equals( + cr.nonConstantRawMultilineString, crlf.nonConstantRawMultilineString); + Expect.equals( + crlf.nonConstantRawMultilineString, lf.nonConstantRawMultilineString); + Expect.equals( + lf.nonConstantRawMultilineString, cr.nonConstantRawMultilineString); + + const c1 = + cr.constantMultilineString == crlf.constantMultilineString ? true : null; + const c2 = + crlf.constantMultilineString == lf.constantMultilineString ? true : null; + const c3 = + lf.constantMultilineString == cr.constantMultilineString ? true : null; + Expect.isTrue(c1); + Expect.isTrue(c2); + Expect.isTrue(c3); + + const c1r = cr.constantRawMultilineString == crlf.constantRawMultilineString + ? true + : null; + const c2r = crlf.constantRawMultilineString == lf.constantRawMultilineString + ? true + : null; + const c3r = lf.constantRawMultilineString == cr.constantRawMultilineString + ? true + : null; + Expect.isTrue(c1r); + Expect.isTrue(c2r); + Expect.isTrue(c3r); + + + + + + + + + + + + + + + + + + + + const c7 = + cr.constantMultilineString != crlf.constantMultilineString ? true : null; + const c8 = + crlf.constantMultilineString != lf.constantMultilineString ? true : null; + const c9 = + lf.constantMultilineString != cr.constantMultilineString ? true : null; + Expect.isNull(c7); + Expect.isNull(c8); + Expect.isNull(c9); + + const c7r = cr.constantRawMultilineString != crlf.constantRawMultilineString + ? true + : null; + const c8r = crlf.constantRawMultilineString != lf.constantRawMultilineString + ? true + : null; + const c9r = lf.constantRawMultilineString != cr.constantRawMultilineString + ? true + : null; + Expect.isNull(c7r); + Expect.isNull(c8r); + Expect.isNull(c9r); + + // What's the deal with the compile-time errors below? This is to validate + // that constants are evaluated correctly at compile-time (or analysis + // time). For example, only if [c7] is evaluated correctly does it become + // null which leads to a compile-time error (as it isn't a boolean). For + // tools like dart2js, this ensures that the compile-time evaluation of + // constants is similar to the runtime evaluation tested above. For tools + // like the analyzer, this ensures that evaluation is tested (there's no + // runtime evaluation). + + + + + + + +} diff --git a/tests/language/string/multiline_newline_test.dart b/tests/language/string/multiline_newline_test.dart new file mode 100644 index 00000000000..37ef0c7fba7 --- /dev/null +++ b/tests/language/string/multiline_newline_test.dart @@ -0,0 +1,173 @@ +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'multiline_newline_cr.dart' as cr; +import 'multiline_newline_crlf.dart' as crlf; +import 'multiline_newline_lf.dart' as lf; + +main() { + Expect.equals(4, cr.constantMultilineString.length); + Expect.equals(4, crlf.constantMultilineString.length); + Expect.equals(4, lf.constantMultilineString.length); + + Expect.equals(6, cr.constantRawMultilineString.length); + Expect.equals(6, crlf.constantRawMultilineString.length); + Expect.equals(6, lf.constantRawMultilineString.length); + + Expect.equals(cr.constantMultilineString, crlf.constantMultilineString); + Expect.equals(crlf.constantMultilineString, lf.constantMultilineString); + Expect.equals(lf.constantMultilineString, cr.constantMultilineString); + + Expect.equals(cr.constantRawMultilineString, crlf.constantRawMultilineString); + Expect.equals(crlf.constantRawMultilineString, lf.constantRawMultilineString); + Expect.equals(lf.constantRawMultilineString, cr.constantRawMultilineString); + + Expect.equals(4, cr.nonConstantMultilineString.length); + Expect.equals(4, crlf.nonConstantMultilineString.length); + Expect.equals(4, lf.nonConstantMultilineString.length); + + Expect.equals(6, cr.nonConstantRawMultilineString.length); + Expect.equals(6, crlf.nonConstantRawMultilineString.length); + Expect.equals(6, lf.nonConstantRawMultilineString.length); + + Expect.equals(cr.nonConstantMultilineString, crlf.nonConstantMultilineString); + Expect.equals(crlf.nonConstantMultilineString, lf.nonConstantMultilineString); + Expect.equals(lf.nonConstantMultilineString, cr.nonConstantMultilineString); + + Expect.equals( + cr.nonConstantRawMultilineString, crlf.nonConstantRawMultilineString); + Expect.equals( + crlf.nonConstantRawMultilineString, lf.nonConstantRawMultilineString); + Expect.equals( + lf.nonConstantRawMultilineString, cr.nonConstantRawMultilineString); + + const c1 = + cr.constantMultilineString == crlf.constantMultilineString ? true : null; + const c2 = + crlf.constantMultilineString == lf.constantMultilineString ? true : null; + const c3 = + lf.constantMultilineString == cr.constantMultilineString ? true : null; + Expect.isTrue(c1); + Expect.isTrue(c2); + Expect.isTrue(c3); + + const c1r = cr.constantRawMultilineString == crlf.constantRawMultilineString + ? true + : null; + const c2r = crlf.constantRawMultilineString == lf.constantRawMultilineString + ? true + : null; + const c3r = lf.constantRawMultilineString == cr.constantRawMultilineString + ? true + : null; + Expect.isTrue(c1r); + Expect.isTrue(c2r); + Expect.isTrue(c3r); + + const c4 = c1 ? 1 : 2; + // ^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + Expect.equals(1, c4); + + const c5 = c2 ? 2 : 3; + // ^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + Expect.equals(2, c5); + + const c6 = c3 ? 3 : 4; + // ^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + Expect.equals(3, c6); + + const c4r = c1r ? 1 : 2; + // ^^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + Expect.equals(1, c4r); + + const c5r = c2r ? 2 : 3; + // ^^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + Expect.equals(2, c5r); + + const c6r = c3r ? 3 : 4; + // ^^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + Expect.equals(3, c6r); + + const c7 = + cr.constantMultilineString != crlf.constantMultilineString ? true : null; + const c8 = + crlf.constantMultilineString != lf.constantMultilineString ? true : null; + const c9 = + lf.constantMultilineString != cr.constantMultilineString ? true : null; + Expect.isNull(c7); + Expect.isNull(c8); + Expect.isNull(c9); + + const c7r = cr.constantRawMultilineString != crlf.constantRawMultilineString + ? true + : null; + const c8r = crlf.constantRawMultilineString != lf.constantRawMultilineString + ? true + : null; + const c9r = lf.constantRawMultilineString != cr.constantRawMultilineString + ? true + : null; + Expect.isNull(c7r); + Expect.isNull(c8r); + Expect.isNull(c9r); + + // What's the deal with the compile-time errors below? This is to validate + // that constants are evaluated correctly at compile-time (or analysis + // time). For example, only if [c7] is evaluated correctly does it become + // null which leads to a compile-time error (as it isn't a boolean). For + // tools like dart2js, this ensures that the compile-time evaluation of + // constants is similar to the runtime evaluation tested above. For tools + // like the analyzer, this ensures that evaluation is tested (there's no + // runtime evaluation). + const c10 = c7 ? 1 : 2; + // ^^ + // [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_TYPE_BOOL + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + // ^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + const c11 = c8 ? 2 : 3; + // ^^ + // [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_TYPE_BOOL + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + // ^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + const c12 = c9 ? 3 : 4; + // ^^ + // [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_TYPE_BOOL + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + // ^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + + const c10r = c7r ? 1 : 2; + // ^^^ + // [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_TYPE_BOOL + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + // ^^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + const c11r = c8r ? 2 : 3; + // ^^^ + // [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_TYPE_BOOL + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + // ^^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE + const c12r = c9r ? 3 : 4; + // ^^^ + // [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_TYPE_BOOL + // [cfe] A value of type 'bool?' can't be assigned to a variable of type 'bool'. + // ^^^ + // [analyzer] STATIC_WARNING.UNCHECKED_USE_OF_NULLABLE_VALUE +} diff --git a/tests/language/string/multiline_strings_test.dart b/tests/language/string/multiline_strings_test.dart new file mode 100644 index 00000000000..fa96fb1bc3c --- /dev/null +++ b/tests/language/string/multiline_strings_test.dart @@ -0,0 +1,70 @@ +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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() { + Expect.equals( + 'foo', + ''' +foo'''); + + Expect.equals( + '\\\nfoo', + '''\\ +foo'''); + + Expect.equals( + '\t\nfoo', + '''\t +foo'''); + + Expect.equals( + 'foo', + '''\ +foo'''); + + Expect.equals( + 'foo', + '''\ \ +foo'''); + + Expect.equals( + ' \nfoo', + '''\x20 +foo'''); + + String x = ' '; + Expect.equals( + ' \nfoo', + '''$x +foo'''); + + Expect.equals( + 'foo', + r''' +foo'''); + + Expect.equals( + '\\\\\nfoo', + r'''\\ +foo'''); + + Expect.equals( + '\\t\nfoo', + r'''\t +foo'''); + + Expect.equals( + 'foo', + r'''\ +foo'''); + + Expect.equals( + 'foo', + r'''\ \ +foo'''); +} diff --git a/tests/language/string/no_operator_runtime_test.dart b/tests/language/string/no_operator_runtime_test.dart new file mode 100644 index 00000000000..ebf1dc763ea --- /dev/null +++ b/tests/language/string/no_operator_runtime_test.dart @@ -0,0 +1,29 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; + +main() { + var x = "x"; + var y = "y"; + + + + + + + + + + + + + + + + +} diff --git a/tests/language/string/no_operator_test.dart b/tests/language/string/no_operator_test.dart new file mode 100644 index 00000000000..e6da2492bc8 --- /dev/null +++ b/tests/language/string/no_operator_test.dart @@ -0,0 +1,74 @@ +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; + +main() { + var x = "x"; + var y = "y"; + Expect.throws(() => x < y); + // ^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '<' isn't defined for the class 'String'. + Expect.throws(() => x <= y); + // ^^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '<=' isn't defined for the class 'String'. + Expect.throws(() => x > y); + // ^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '>' isn't defined for the class 'String'. + Expect.throws(() => x >= y); + // ^^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '>=' isn't defined for the class 'String'. + Expect.throws(() => x - y); + // ^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '-' isn't defined for the class 'String'. + Expect.throws(() => x * y); + // ^ + // [analyzer] STATIC_WARNING.ARGUMENT_TYPE_NOT_ASSIGNABLE + // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'. + Expect.throws(() => x / y); + // ^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '/' isn't defined for the class 'String'. + Expect.throws(() => x ~/ y); + // ^^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '~/' isn't defined for the class 'String'. + Expect.throws(() => x % y); + // ^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '%' isn't defined for the class 'String'. + Expect.throws(() => x >> y); + // ^^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '>>' isn't defined for the class 'String'. + Expect.throws(() => x << y); + // ^^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '<<' isn't defined for the class 'String'. + Expect.throws(() => x & y); + // ^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '&' isn't defined for the class 'String'. + Expect.throws(() => x | y); + // ^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '|' isn't defined for the class 'String'. + Expect.throws(() => x ^ y); + // ^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '^' isn't defined for the class 'String'. + Expect.throws(() => -x); + // ^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator 'unary-' isn't defined for the class 'String'. + Expect.throws(() => ~x); + // ^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR + // [cfe] The operator '~' isn't defined for the class 'String'. +} diff --git a/tests/language/string/optimizations_test.dart b/tests/language/string/optimizations_test.dart new file mode 100644 index 00000000000..a40bc0b51dc --- /dev/null +++ b/tests/language/string/optimizations_test.dart @@ -0,0 +1,27 @@ +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file +// 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. + +// Regression test for dart2js's type inferrer, that used to not +// correctly infer optional named parameters. + +import "package:expect/expect.dart"; +import "../compiler_annotations.dart"; + +@DontInline() +foo({path}) { + () => 42; + return path.toString(); +} + +@DontInline() +bar({path}) { + () => 42; + return path; +} + +main() { + var a = [foo(path: '42'), foo(), 42, bar(path: '54')]; + Expect.isTrue(a[1] is String); + Expect.throwsNoSuchMethodError(() => bar().concat('54')); +} diff --git a/tests/language/string/overflow.dart b/tests/language/string/overflow.dart new file mode 100644 index 00000000000..8b01e194983 --- /dev/null +++ b/tests/language/string/overflow.dart @@ -0,0 +1,21 @@ +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file +// 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. + +// Test to ensure that the VM does not have an integer overflow issue +// when concatenating strings. + +import "package:expect/expect.dart"; + +main() { + String a = "a"; + for (; a.length < 256 * 1024 * 1024;) a = a + a; + + var exception_thrown = false; + try { + var concat = "$a$a$a$a$a$a$a$a"; + } on OutOfMemoryError catch (exc) { + exception_thrown = true; + } + Expect.isTrue(exception_thrown); +} diff --git a/tests/language/string/raw_string_test.dart b/tests/language/string/raw_string_test.dart new file mode 100644 index 00000000000..358f88200bb --- /dev/null +++ b/tests/language/string/raw_string_test.dart @@ -0,0 +1,53 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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 +2 +3"""); + Expect.equals( + "1\n2\n3", + r'''1 +2 +3'''); + Expect.equals( + "1", + r""" +1"""); + 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(); +} diff --git a/tests/language/string/runtime_test.dart b/tests/language/string/runtime_test.dart new file mode 100644 index 00000000000..41a0d8ea9c6 --- /dev/null +++ b/tests/language/string/runtime_test.dart @@ -0,0 +1,47 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. +// Replace with shared test once interface issues clarified. + +import "package:expect/expect.dart"; + +class StringTest { + static testMain() { + testCodePoints(); + testNoSuchMethod(); + testStringsJoin(); + testCharCodes(); + } + + static testCodePoints() { + String str = "string"; + for (int i = 0; i < str.length; i++) { + Expect.equals(true, str[i] is String); + Expect.equals(true, str.codeUnitAt(i) is int); + } + } + + static testStringsJoin() { + List a = ["Hello", "World"]; + String s = a.join("*^*"); + Expect.equals("Hello*^*World", s); + } + + static testNoSuchMethod() { + String a = "Hello"; + + } + + static testCharCodes() { + String s = new String.fromCharCodes(const [0x41, 0xC1, 0x424]); + Expect.equals("A", s[0]); + Expect.equals(0x424, s.codeUnitAt(2)); + } +} + +main() { + StringTest.testMain(); +} diff --git a/tests/language/string/split_test.dart b/tests/language/string/split_test.dart new file mode 100644 index 00000000000..25172370143 --- /dev/null +++ b/tests/language/string/split_test.dart @@ -0,0 +1,30 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// 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. +// Issue 24043. + +import "package:expect/expect.dart"; + +class EvilMatch implements Match { + int get start => 100000000; + int get end => 3; + bool noSuchMethod(Invocation im) => false; // To appease dartanalyzer. +} + +class EvilIterator implements Iterator { + bool moveNext() => true; + EvilMatch get current => new EvilMatch(); +} + +class EvilIterable extends Iterable { + get iterator => new EvilIterator(); +} + +class EvilPattern implements Pattern { + allMatches(String s, [int start = 0]) => new EvilIterable(); + bool noSuchMethod(Invocation im) => false; // To appease dartanalyzer. +} + +void main() { + Expect.throwsRangeError(() => "foo".split(new EvilPattern())[0].length); +} diff --git a/tests/language/string/string_test.dart b/tests/language/string/string_test.dart new file mode 100644 index 00000000000..1ab3f926176 --- /dev/null +++ b/tests/language/string/string_test.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. +// Replace with shared test once interface issues clarified. + +import "package:expect/expect.dart"; + +class StringTest { + static testMain() { + testCodePoints(); + testNoSuchMethod(); + testStringsJoin(); + testCharCodes(); + } + + static testCodePoints() { + String str = "string"; + for (int i = 0; i < str.length; i++) { + Expect.equals(true, str[i] is String); + Expect.equals(true, str.codeUnitAt(i) is int); + } + } + + static testStringsJoin() { + List a = ["Hello", "World"]; + String s = a.join("*^*"); + Expect.equals("Hello*^*World", s); + } + + static testNoSuchMethod() { + String a = "Hello"; + a[1] = 12; +// ^^^ +// [analyzer] STATIC_TYPE_WARNING.UNDEFINED_OPERATOR +// [cfe] The operator '[]=' isn't defined for the class 'String'. + } + + static testCharCodes() { + String s = new String.fromCharCodes(const [0x41, 0xC1, 0x424]); + Expect.equals("A", s[0]); + Expect.equals(0x424, s.codeUnitAt(2)); + } +} + +main() { + StringTest.testMain(); +} diff --git a/tests/language/string/substring_runtime_test.dart b/tests/language/string/substring_runtime_test.dart new file mode 100644 index 00000000000..38007adc731 --- /dev/null +++ b/tests/language/string/substring_runtime_test.dart @@ -0,0 +1,20 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. +// Dart version of two-argument Ackermann-Peter function. + +import "package:expect/expect.dart"; + +main() { + try { + + + } on TypeError catch (e) { + // OK. + } on ArgumentError catch (e) { + // OK. + } +} diff --git a/tests/language/string/substring_test.dart b/tests/language/string/substring_test.dart new file mode 100644 index 00000000000..bf2ce999b2b --- /dev/null +++ b/tests/language/string/substring_test.dart @@ -0,0 +1,23 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. +// Dart version of two-argument Ackermann-Peter function. + +import "package:expect/expect.dart"; + +main() { + try { + print("abcdef".substring(1.5, 3.5)); + // ^^^ + // [analyzer] STATIC_WARNING.ARGUMENT_TYPE_NOT_ASSIGNABLE + // [cfe] The argument type 'double' can't be assigned to the parameter type 'int'. + // ^^^ + // [analyzer] STATIC_WARNING.ARGUMENT_TYPE_NOT_ASSIGNABLE + // [cfe] The argument type 'double' can't be assigned to the parameter type 'int'. + Expect.fail("Should have thrown an exception"); + } on TypeError catch (e) { + // OK. + } on ArgumentError catch (e) { + // OK. + } +} diff --git a/tests/language/string/supertype_checked_test.dart b/tests/language/string/supertype_checked_test.dart new file mode 100644 index 00000000000..016c757c340 --- /dev/null +++ b/tests/language/string/supertype_checked_test.dart @@ -0,0 +1,29 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +// This tests a bug in dart2js which caused the compiler to emit bad +// type assertions for supertypes of String. + +class A implements Comparable { + int value; + + A(this.value); + + int compareTo(Object other) { + A o = promote(other); + return value.compareTo(o.value); + } + + A promote(var other) { + return other; + } +} + +main() { + var a = new A(1); + var b = new A(2); + Expect.equals(-1, a.compareTo(b)); +} diff --git a/tests/language/string/unicode1_test.dart b/tests/language/string/unicode1_test.dart new file mode 100644 index 00000000000..04a9f5f2428 --- /dev/null +++ b/tests/language/string/unicode1_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// 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. + +/// (backslash) uXXXX must have exactly 4 hex digits. + +main() { + var str = "Foo\u00"; + // ^^^^ + // [analyzer] SYNTACTIC_ERROR.INVALID_UNICODE_ESCAPE + // [cfe] An escape sequence starting with '\u' must be followed by 4 hexadecimal digits or from 1 to 6 digits between '{' and '}'. + str = "Foo\uDEEMBar"; + // ^^^^^ + // [analyzer] SYNTACTIC_ERROR.INVALID_UNICODE_ESCAPE + // [cfe] An escape sequence starting with '\u' must be followed by 4 hexadecimal digits or from 1 to 6 digits between '{' and '}'. +} diff --git a/tests/language/string/unicode2_test.dart b/tests/language/string/unicode2_test.dart new file mode 100644 index 00000000000..4624fbd33b2 --- /dev/null +++ b/tests/language/string/unicode2_test.dart @@ -0,0 +1,17 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// 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. + +/// \u{X*} should have 1-6 hex digits. + +main() { + var str = "Foo\u{}Bar"; + // ^^^^ + // [analyzer] SYNTACTIC_ERROR.INVALID_UNICODE_ESCAPE + // [cfe] An escape sequence starting with '\u' must be followed by 4 hexadecimal digits or from 1 to 6 digits between '{' and '}'. + str = "Foo\u{000000000}Bar"; + str = "Foo\u{DEAF!}Bar"; + // ^^^^^^^^ + // [analyzer] SYNTACTIC_ERROR.INVALID_UNICODE_ESCAPE + // [cfe] An escape sequence starting with '\u' must be followed by 4 hexadecimal digits or from 1 to 6 digits between '{' and '}'. +} diff --git a/tests/language/string/unicode3_test.dart b/tests/language/string/unicode3_test.dart new file mode 100644 index 00000000000..3c04303b184 --- /dev/null +++ b/tests/language/string/unicode3_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// 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. + +/// Backslash xXX must have exactly 2 hex digits. + +main() { + var str = "Foo\x0"; + // ^^^ + // [analyzer] SYNTACTIC_ERROR.INVALID_HEX_ESCAPE + // [cfe] An escape sequence starting with '\x' must be followed by 2 hexadecimal digits. + str = "Foo\xF Bar"; + // ^^^ + // [analyzer] SYNTACTIC_ERROR.INVALID_HEX_ESCAPE + // [cfe] An escape sequence starting with '\x' must be followed by 2 hexadecimal digits. +} diff --git a/tests/language/string/unicode4_test.dart b/tests/language/string/unicode4_test.dart new file mode 100644 index 00000000000..89095fab3ee --- /dev/null +++ b/tests/language/string/unicode4_test.dart @@ -0,0 +1,15 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// 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. + +/// Unicode escapes must refer to valid Unicode points and not surrogate +/// characters. + +main() { + var str = "Foo\u{FFFFFF}"; + // ^^^^^^^^^ + // [analyzer] SYNTACTIC_ERROR.INVALID_CODE_POINT + // [cfe] The escape sequence starting with '\u' isn't a valid code point. + str = "Foo\uD800"; + str = "Foo\uDC00"; +} diff --git a/tests/language/string/unicode_bom_middle_test.dart b/tests/language/string/unicode_bom_middle_test.dart new file mode 100644 index 00000000000..e620b2b0ec9 --- /dev/null +++ b/tests/language/string/unicode_bom_middle_test.dart @@ -0,0 +1,17 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); + +foo(x) { + if (inscrutable(1999) == 1999) return x; + return 499; +} + +main() { + Expect.equals(3, "xx".length); // BOM character between the xs. + Expect.equals(3, foo("xx").length); // BOM character between the xs. +} diff --git a/tests/language/string/unicode_bom_test.dart b/tests/language/string/unicode_bom_test.dart new file mode 100644 index 00000000000..2e234458d9a --- /dev/null +++ b/tests/language/string/unicode_bom_test.dart @@ -0,0 +1,11 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +// This file is saved with a BOM character (as first character). This character +// should be ignored. +// Tests that files with a BOM character are correctly handled. + +main() { + /* do nothing. */ +} diff --git a/tests/language/string/unicode_hash_test.dart b/tests/language/string/unicode_hash_test.dart new file mode 100644 index 00000000000..430c51ef16c --- /dev/null +++ b/tests/language/string/unicode_hash_test.dart @@ -0,0 +1,10 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// 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. + +import "package:expect/expect.dart"; + +main() { + Expect.equals("\u{10412}", "𐐒"); // Second string is literal U+10412. + Expect.equals("\u{10412}".hashCode, "𐐒".hashCode); +}