OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, 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 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --checked | |
5 | |
6 library string_escaping_test; | |
7 | |
8 import 'package:observatory/service_io.dart'; | |
9 import 'package:unittest/unittest.dart'; | |
10 import 'test_helper.dart'; | |
11 | |
12 var ascii; | |
13 var latin1; | |
14 var unicode; | |
15 var hebrew; | |
16 var singleQuotes; | |
17 var doubleQuotes; | |
18 var newLines; | |
19 var tabs; | |
20 var suggrogatePairs; | |
21 var nullInTheMiddle; | |
22 var escapedUnicodeEscape; | |
23 var longStringEven; | |
24 var longStringOdd; | |
25 var malformedWithLeadSurrogate; | |
26 var malformedWithTrailSurrogate; | |
27 | |
28 void script() { | |
29 ascii = "Hello, World!"; | |
30 latin1 = "blåbærgrød"; | |
31 unicode = "Îñţérñåţîöñåļîžåţîờñ"; | |
32 hebrew = "שלום רב שובך צפורה נחמדת"; // Right-to-left text. | |
33 singleQuotes = "'One,' he said."; | |
34 doubleQuotes = '"Two," he said.'; | |
35 newLines = "Windows\r\nSmalltalk\rUnix\n"; | |
36 tabs = "One\tTwo\tThree"; | |
37 suggrogatePairs = "1𝄞2𝄞𝄞3𝄞𝄞𝄞"; | |
38 nullInTheMiddle = "There are four\u0000 words."; | |
39 escapedUnicodeEscape = "Should not be A: \\u0041"; | |
40 | |
41 // A surrogate pair will cross the preferred truncation boundry. | |
42 longStringEven = ".."; | |
43 for (int i = 0; i < 512; i++) longStringEven += "𝄞"; | |
44 longStringOdd = "."; | |
45 for (int i = 0; i < 512; i++) longStringOdd += "𝄞"; | |
46 | |
47 malformedWithLeadSurrogate = "before" + "𝄞"[0] + "after"; | |
48 malformedWithTrailSurrogate = "before" + "𝄞"[1] + "after"; | |
49 } | |
50 | |
51 var tests = [ | |
52 | |
53 (Isolate isolate) => | |
54 isolate.rootLib.load().then((Library lib) { | |
55 expectFullString(String varName, String varValueAsString) { | |
56 Field field = lib.variables.singleWhere((v) => v.name == varName); | |
57 Instance value = field.value; | |
58 expect(value.valueAsString, equals(varValueAsString)); | |
59 expect(value.valueAsStringIsTruncated, isFalse); | |
60 } | |
61 expectTruncatedString(String varName, String varValueAsString) { | |
62 Field field = lib.variables.singleWhere((v) => v.name == varName); | |
63 Instance value = field.value; | |
64 expect(varValueAsString, startsWith(value.valueAsString)); | |
65 expect(value.valueAsStringIsTruncated, isTrue); | |
66 } | |
67 | |
68 script(); // Need to initialize variables in the testing isolate. | |
69 expectFullString('ascii', ascii); | |
70 expectFullString('latin1', latin1); | |
71 expectFullString('unicode', unicode); | |
72 expectFullString('hebrew', hebrew); | |
73 expectFullString('singleQuotes', singleQuotes); | |
74 expectFullString('doubleQuotes', doubleQuotes); | |
75 expectFullString('newLines', newLines); | |
76 expectFullString('tabs', tabs); | |
77 expectFullString('suggrogatePairs', suggrogatePairs); | |
78 expectFullString('nullInTheMiddle', nullInTheMiddle); | |
79 expectTruncatedString('longStringEven', longStringEven); | |
80 expectTruncatedString('longStringOdd', longStringOdd); | |
81 expectFullString('malformedWithLeadSurrogate', malformedWithLeadSurrogate); | |
82 expectFullString('malformedWithTrailSurrogate', malformedWithTrailSurrogate)
; | |
83 }), | |
84 | |
85 ]; | |
86 | |
87 main(args) => runIsolateTests(args, tests, testeeBefore: script); | |
OLD | NEW |