blob: 2f752de10709fe79bb42b02a2bc6621e0740f51c [file] [log] [blame]
lrn@google.com788c5692013-08-29 12:13:32 +00001// 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 Petersenb101a7d2021-04-26 17:58:57 +00005// @dart = 2.9
6
lrn@google.com788c5692013-08-29 12:13:32 +00007// Test that different representations of the same string are all equal.
8
lrn@google.com3a012602013-10-25 10:30:34 +00009import "dart:convert";
lrn@google.com788c5692013-08-29 12:13:32 +000010
11import "package:expect/expect.dart";
12
13main() {
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 Richman2dcd56e2017-04-17 14:52:57 -070025 (new StringBuffer()..writeCharCode(0xd801)..writeCharCode(0xdc12))
26 .toString(),
lrn@google.com788c5692013-08-29 12:13:32 +000027 (new StringBuffer()..writeCharCode(0x10412)).toString(),
Lasse R.H. Nielsen0b58c4b2017-11-14 12:59:14 +000028 json.decode('"\u{10412}"'),
29 (json.decode('{"\u{10412}":[]}') as Map).keys.first
lrn@google.com788c5692013-08-29 12:13:32 +000030 ];
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}