lrn@google.com | 788c569 | 2013-08-29 12:13:32 +0000 | [diff] [blame] | 1 | // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
Leaf Petersen | b101a7d | 2021-04-26 17:58:57 +0000 | [diff] [blame] | 5 | // @dart = 2.9 |
| 6 | |
lrn@google.com | 788c569 | 2013-08-29 12:13:32 +0000 | [diff] [blame] | 7 | // Test that different representations of the same string are all equal. |
| 8 | |
lrn@google.com | 3a01260 | 2013-10-25 10:30:34 +0000 | [diff] [blame] | 9 | import "dart:convert"; |
lrn@google.com | 788c569 | 2013-08-29 12:13:32 +0000 | [diff] [blame] | 10 | |
| 11 | import "package:expect/expect.dart"; |
| 12 | |
| 13 | main() { |
| 14 | var base = "\u{10412}"; |
| 15 | var strings = [ |
| 16 | "\u{10412}", |
| 17 | "𐐒", |
| 18 | new String.fromCharCodes([0xd801, 0xdc12]), |
| 19 | base[0] + base[1], |
| 20 | "$base", |
| 21 | "${base[0]}${base[1]}", |
| 22 | "${base[0]}${base.substring(1)}", |
| 23 | new String.fromCharCodes([0x10412]), |
| 24 | ("a" + base).substring(1), |
Jacob Richman | 2dcd56e | 2017-04-17 14:52:57 -0700 | [diff] [blame] | 25 | (new StringBuffer()..writeCharCode(0xd801)..writeCharCode(0xdc12)) |
| 26 | .toString(), |
lrn@google.com | 788c569 | 2013-08-29 12:13:32 +0000 | [diff] [blame] | 27 | (new StringBuffer()..writeCharCode(0x10412)).toString(), |
Lasse R.H. Nielsen | 0b58c4b | 2017-11-14 12:59:14 +0000 | [diff] [blame] | 28 | json.decode('"\u{10412}"'), |
| 29 | (json.decode('{"\u{10412}":[]}') as Map).keys.first |
lrn@google.com | 788c569 | 2013-08-29 12:13:32 +0000 | [diff] [blame] | 30 | ]; |
| 31 | for (String string in strings) { |
| 32 | Expect.equals(base.length, string.length); |
| 33 | Expect.equals(base, string); |
| 34 | Expect.equals(base.hashCode, string.hashCode); |
| 35 | Expect.listEquals(base.codeUnits.toList(), string.codeUnits.toList()); |
| 36 | } |
| 37 | } |