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

Side by Side Diff: runtime/vm/json_test.cc

Issue 2081433002: Use official JSON encoding for stream (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixed & Added UTF-32 characters tests Created 4 years, 5 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
« no previous file with comments | « runtime/vm/json_stream.cc ('k') | runtime/vm/unicode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "platform/text_buffer.h" 6 #include "platform/text_buffer.h"
7 #include "vm/json_stream.h" 7 #include "vm/json_stream.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 10
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 EXPECT_STREQ("[\"Hel\\\"\\\"lo\\r\\n\\t\"]", js.ToCString()); 212 EXPECT_STREQ("[\"Hel\\\"\\\"lo\\r\\n\\t\"]", js.ToCString());
213 } 213 }
214 214
215 215
216 TEST_CASE(JSON_JSONStream_DartString) { 216 TEST_CASE(JSON_JSONStream_DartString) {
217 const char* kScriptChars = 217 const char* kScriptChars =
218 "var ascii = 'Hello, World!';\n" 218 "var ascii = 'Hello, World!';\n"
219 "var unicode = '\\u00CE\\u00F1\\u0163\\u00E9r\\u00F1\\u00E5\\u0163" 219 "var unicode = '\\u00CE\\u00F1\\u0163\\u00E9r\\u00F1\\u00E5\\u0163"
220 "\\u00EE\\u00F6\\u00F1\\u00E5\\u013C\\u00EE\\u017E\\u00E5\\u0163" 220 "\\u00EE\\u00F6\\u00F1\\u00E5\\u013C\\u00EE\\u017E\\u00E5\\u0163"
221 "\\u00EE\\u1EDD\\u00F1';\n" 221 "\\u00EE\\u1EDD\\u00F1';\n"
222 "var surrogates = '\\u{1D11E}\\u{1D11E}\\u{1D11E}\\u{1D11E}" 222 "var surrogates = '\\u{1D11E}\\u{1D11E}\\u{1D11E}"
223 "\\u{1D11E}';\n" 223 "\\u{1D11E}\\u{1D11E}';\n"
224 "var wrongEncoding = '\\u{1D11E}' + surrogates[0] + '\\u{1D11E}';"
224 "var nullInMiddle = 'This has\\u0000 four words.';"; 225 "var nullInMiddle = 'This has\\u0000 four words.';";
225 226
226 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 227 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
227 EXPECT_VALID(lib); 228 EXPECT_VALID(lib);
228 229
229 Dart_Handle result; 230 Dart_Handle result;
230 String& obj = String::Handle(); 231 String& obj = String::Handle();
231 232
232 { 233 {
233 result = Dart_GetField(lib, NewString("ascii")); 234 result = Dart_GetField(lib, NewString("ascii"));
(...skipping 24 matching lines...) Expand all
258 { 259 {
259 result = Dart_GetField(lib, NewString("unicode")); 260 result = Dart_GetField(lib, NewString("unicode"));
260 EXPECT_VALID(result); 261 EXPECT_VALID(result);
261 obj ^= Api::UnwrapHandle(result); 262 obj ^= Api::UnwrapHandle(result);
262 263
263 JSONStream js; 264 JSONStream js;
264 { 265 {
265 JSONObject jsobj(&js); 266 JSONObject jsobj(&js);
266 EXPECT(!jsobj.AddPropertyStr("unicode", obj)); 267 EXPECT(!jsobj.AddPropertyStr("unicode", obj));
267 } 268 }
268 EXPECT_STREQ("{\"unicode\":\"\\u00CE\\u00F1\\u0163\\u00E9r\\u00F1\\u00E5" 269 EXPECT_STREQ("{\"unicode\":\"Îñţérñåţîöñåļîžåţîờñ\"}", js.ToCString());
269 "\\u0163\\u00EE\\u00F6\\u00F1\\u00E5\\u013C\\u00EE\\u017E"
270 "\\u00E5\\u0163\\u00EE\\u1EDD\\u00F1\"}", js.ToCString());
271 } 270 }
272 271
273 { 272 {
274 result = Dart_GetField(lib, NewString("surrogates")); 273 result = Dart_GetField(lib, NewString("surrogates"));
275 EXPECT_VALID(result); 274 EXPECT_VALID(result);
276 obj ^= Api::UnwrapHandle(result); 275 obj ^= Api::UnwrapHandle(result);
277 276
278 JSONStream js; 277 JSONStream js;
279 { 278 {
280 JSONObject jsobj(&js); 279 JSONObject jsobj(&js);
281 EXPECT(!jsobj.AddPropertyStr("surrogates", obj)); 280 EXPECT(!jsobj.AddPropertyStr("surrogates", obj));
282 } 281 }
283 EXPECT_STREQ("{\"surrogates\":\"\\uD834\\uDD1E\\uD834\\uDD1E\\uD834\\uDD1E" 282 EXPECT_STREQ("{\"surrogates\":\"𝄞𝄞𝄞𝄞𝄞\"}", js.ToCString());
284 "\\uD834\\uDD1E\\uD834\\uDD1E\"}", js.ToCString());
285 } 283 }
286 284
287 { 285 {
286 result = Dart_GetField(lib, NewString("wrongEncoding"));
287 EXPECT_VALID(result);
288 obj ^= Api::UnwrapHandle(result);
289
290 JSONStream js;
291 {
292 JSONObject jsobj(&js);
293 EXPECT(!jsobj.AddPropertyStr("wrongEncoding", obj));
294 }
295 EXPECT_STREQ("{\"wrongEncoding\":\"𝄞\\uD834𝄞\"}", js.ToCString());
296 }
297
298
299 {
288 result = Dart_GetField(lib, NewString("nullInMiddle")); 300 result = Dart_GetField(lib, NewString("nullInMiddle"));
289 EXPECT_VALID(result); 301 EXPECT_VALID(result);
290 obj ^= Api::UnwrapHandle(result); 302 obj ^= Api::UnwrapHandle(result);
291 303
292 JSONStream js; 304 JSONStream js;
293 { 305 {
294 JSONObject jsobj(&js); 306 JSONObject jsobj(&js);
295 EXPECT(!jsobj.AddPropertyStr("nullInMiddle", obj)); 307 EXPECT(!jsobj.AddPropertyStr("nullInMiddle", obj));
296 } 308 }
297 EXPECT_STREQ("{\"nullInMiddle\":\"This has\\u0000 four words.\"}", 309 EXPECT_STREQ("{\"nullInMiddle\":\"This has\\u0000 four words.\"}",
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 &js); 350 &js);
339 } 351 }
340 } 352 }
341 353
342 EXPECT_STREQ("{\"test\":[{a, b, c},{a, b, c},{a, b, c}]}", js.ToCString()); 354 EXPECT_STREQ("{\"test\":[{a, b, c},{a, b, c},{a, b, c}]}", js.ToCString());
343 } 355 }
344 356
345 #endif // !PRODUCT 357 #endif // !PRODUCT
346 358
347 } // namespace dart 359 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/json_stream.cc ('k') | runtime/vm/unicode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698