Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: runtime/bin/vmservice/observatory/test/string_escaping_test.dart

Issue 558853004: Preserve the contents of Dart strings with unmatched surrogate halfs by avoiding a UTF16 -> UTF8 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library string_escaping_test; 5 library string_escaping_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:mirrors'; 8 import 'dart:mirrors';
9 import 'package:observatory/service_io.dart'; 9 import 'package:observatory/service_io.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
11 import 'test_helper.dart'; 11 import 'test_helper.dart';
12 12
13 var ascii; 13 var ascii;
14 var latin1; 14 var latin1;
15 var unicode; 15 var unicode;
16 var hebrew; 16 var hebrew;
17 var singleQuotes; 17 var singleQuotes;
18 var doubleQuotes; 18 var doubleQuotes;
19 var newLines; 19 var newLines;
20 var tabs; 20 var tabs;
21 var suggrogatePairs; 21 var suggrogatePairs;
22 var nullInTheMiddle; 22 var nullInTheMiddle;
23 var escapedUnicodeEscape; 23 var escapedUnicodeEscape;
24 var longStringEven; 24 var longStringEven;
25 var longStringOdd; 25 var longStringOdd;
26 var malformedWithLeadSurrogate;
27 var malformedWithTrailSurrogate;
26 28
27 void script() { 29 void script() {
28 ascii = "Hello, World!"; 30 ascii = "Hello, World!";
29 latin1 = "blåbærgrød"; 31 latin1 = "blåbærgrød";
30 unicode = "Îñţérñåţîöñåļîžåţîờñ"; 32 unicode = "Îñţérñåţîöñåļîžåţîờñ";
31 hebrew = "שלום רב שובך צפורה נחמדת"; // Right-to-left text. 33 hebrew = "שלום רב שובך צפורה נחמדת"; // Right-to-left text.
32 singleQuotes = "'One,' he said."; 34 singleQuotes = "'One,' he said.";
33 doubleQuotes = '"Two," he said.'; 35 doubleQuotes = '"Two," he said.';
34 newLines = "Windows\r\nSmalltalk\rUnix\n"; 36 newLines = "Windows\r\nSmalltalk\rUnix\n";
35 tabs = "One\tTwo\tThree"; 37 tabs = "One\tTwo\tThree";
36 suggrogatePairs = "1𝄞2𝄞𝄞3𝄞𝄞𝄞"; 38 suggrogatePairs = "1𝄞2𝄞𝄞3𝄞𝄞𝄞";
37 nullInTheMiddle = "There are four\u0000 words."; 39 nullInTheMiddle = "There are four\u0000 words.";
38 escapedUnicodeEscape = "Should not be A: \\u0041"; 40 escapedUnicodeEscape = "Should not be A: \\u0041";
39 41
40 // A surrogate pair will cross the preferred truncation boundry. 42 // A surrogate pair will cross the preferred truncation boundry.
41 longStringEven = ".."; 43 longStringEven = "..";
42 for (int i = 0; i < 512; i++) longStringEven += "𝄞"; 44 for (int i = 0; i < 512; i++) longStringEven += "𝄞";
43 longStringOdd = "."; 45 longStringOdd = ".";
44 for (int i = 0; i < 512; i++) longStringOdd += "𝄞"; 46 for (int i = 0; i < 512; i++) longStringOdd += "𝄞";
47
48 malformedWithLeadSurrogate = "before" + "𝄞"[0] + "after";
49 malformedWithTrailSurrogate = "before" + "𝄞"[1] + "after";
45 } 50 }
46 51
47 var tests = [ 52 var tests = [
48 53
49 (Isolate isolate) => 54 (Isolate isolate) =>
50 isolate.rootLib.load().then((Library lib) { 55 isolate.rootLib.load().then((Library lib) {
51 expectFullString(String varName, String varValueAsString) { 56 expectFullString(String varName, String varValueAsString) {
52 ServiceMap field = lib.variables.singleWhere((v) => v.name == varName); 57 ServiceMap field = lib.variables.singleWhere((v) => v.name == varName);
53 Instance value = field['value']; 58 Instance value = field['value'];
54 expect(value.valueAsString, equals(varValueAsString)); 59 expect(value.valueAsString, equals(varValueAsString));
55 expect(value.valueAsStringIsTruncated, isFalse); 60 expect(value.valueAsStringIsTruncated, isFalse);
56 } 61 }
57 expectTruncatedString(String varName, String varValueAsString) { 62 expectTruncatedString(String varName, String varValueAsString) {
58 ServiceMap field = lib.variables.singleWhere((v) => v.name == varName); 63 ServiceMap field = lib.variables.singleWhere((v) => v.name == varName);
59 Instance value = field['value']; 64 Instance value = field['value'];
60 expect(varValueAsString, startsWith(value.valueAsString)); 65 expect(varValueAsString, startsWith(value.valueAsString));
61 expect(value.valueAsStringIsTruncated, isTrue); 66 expect(value.valueAsStringIsTruncated, isTrue);
62 } 67 }
63 68
64 script(); // Need to initialize variables in the testing isolate. 69 script(); // Need to initialize variables in the testing isolate.
65 expectFullString('ascii', ascii); 70 expectFullString('ascii', ascii);
66 expectFullString('latin1', latin1); 71 expectFullString('latin1', latin1);
67 expectFullString('unicode', unicode); 72 expectFullString('unicode', unicode);
68 expectFullString('hebrew', hebrew); 73 expectFullString('hebrew', hebrew);
69 expectFullString('singleQuotes', singleQuotes); 74 expectFullString('singleQuotes', singleQuotes);
70 expectFullString('doubleQuotes', doubleQuotes); 75 expectFullString('doubleQuotes', doubleQuotes);
71 expectFullString('newLines', newLines); 76 expectFullString('newLines', newLines);
72 expectFullString('tabs', tabs); 77 expectFullString('tabs', tabs);
73 expectFullString('suggrogatePairs', suggrogatePairs); 78 expectFullString('suggrogatePairs', suggrogatePairs);
74 expectFullString('nullInTheMiddle', nullInTheMiddle); /// 01: ok 79 expectFullString('nullInTheMiddle', nullInTheMiddle);
75 expectTruncatedString('longStringEven', longStringEven); 80 expectTruncatedString('longStringEven', longStringEven);
76 expectTruncatedString('longStringOdd', longStringOdd); 81 expectTruncatedString('longStringOdd', longStringOdd);
82 expectFullString('malformedWithLeadSurrogate', malformedWithLeadSurrogate);
83 expectFullString('malformedWithTrailSurrogate', malformedWithTrailSurrogate) ;
77 }), 84 }),
78 85
79 ]; 86 ];
80 87
81 main(args) => runIsolateTests(args, tests, testeeBefore: script); 88 main(args) => runIsolateTests(args, tests, testeeBefore: script);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698