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

Unified Diff: tests/json/json_test.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/isolate/timer_test.dart ('k') | tests/language/arithmetic_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/json/json_test.dart
diff --git a/tests/json/json_test.dart b/tests/json/json_test.dart
index ef1c20e2dd3bbb6c43b8ee847ca4990eb5c1f161..5ec1c8386ad70c64b1ac46088a606c2964cbe439 100644
--- a/tests/json/json_test.dart
+++ b/tests/json/json_test.dart
@@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
library json_tests;
-import 'dart:json';
+import 'dart:json' as json;
import 'dart:html';
import '../../pkg/unittest/lib/unittest.dart';
import '../../pkg/unittest/lib/html_config.dart';
@@ -12,95 +12,95 @@ main() {
useHtmlConfiguration();
test('Parse', () {
// Scalars.
- expect(JSON.parse(' 5 '), equals(5));
- expect(JSON.parse(' -42 '), equals(-42));
- expect(JSON.parse(' 3e0 '), equals(3));
- expect(JSON.parse(' 3.14 '), equals(3.14));
- expect(JSON.parse('true '), isTrue);
- expect(JSON.parse(' false'), isFalse);
- expect(JSON.parse(' null '), isNull);
- expect(JSON.parse('\n\rnull\t'), isNull);
- expect(JSON.parse(' "hi there\\" bob" '), equals('hi there" bob'));
- expect(JSON.parse(' "" '), isEmpty);
+ expect(json.parse(' 5 '), equals(5));
+ expect(json.parse(' -42 '), equals(-42));
+ expect(json.parse(' 3e0 '), equals(3));
+ expect(json.parse(' 3.14 '), equals(3.14));
+ expect(json.parse('true '), isTrue);
+ expect(json.parse(' false'), isFalse);
+ expect(json.parse(' null '), isNull);
+ expect(json.parse('\n\rnull\t'), isNull);
+ expect(json.parse(' "hi there\\" bob" '), equals('hi there" bob'));
+ expect(json.parse(' "" '), isEmpty);
// Lists.
- expect(JSON.parse(' [] '), isEmpty);
- expect(JSON.parse('[ ]'), isEmpty);
- expect(JSON.parse(' [3, -4.5, true, "hi", false] '),
+ expect(json.parse(' [] '), isEmpty);
+ expect(json.parse('[ ]'), isEmpty);
+ expect(json.parse(' [3, -4.5, true, "hi", false] '),
equals([3, -4.5, true, 'hi', false]));
// Nulls are tricky.
- expect(JSON.parse('[null]'), orderedEquals([null]));
- expect(JSON.parse(' [3, -4.5, null, true, "hi", false] '),
+ expect(json.parse('[null]'), orderedEquals([null]));
+ expect(json.parse(' [3, -4.5, null, true, "hi", false] '),
equals([3, -4.5, null, true, 'hi', false]));
- expect(JSON.parse('[[null]]'), equals([[null]]));
- expect(JSON.parse(' [ [3], [], [null], ["hi", true]] '),
+ expect(json.parse('[[null]]'), equals([[null]]));
+ expect(json.parse(' [ [3], [], [null], ["hi", true]] '),
equals([[3], [], [null], ['hi', true]]));
// Maps.
- expect(JSON.parse(' {} '), isEmpty);
- expect(JSON.parse('{ }'), isEmpty);
+ expect(json.parse(' {} '), isEmpty);
+ expect(json.parse('{ }'), isEmpty);
- expect(JSON.parse(
+ expect(json.parse(
' {"x":3, "y": -4.5, "z" : "hi","u" : true, "v": false } '),
equals({"x":3, "y": -4.5, "z" : "hi", "u" : true, "v": false }));
- expect(JSON.parse(' {"x":3, "y": -4.5, "z" : "hi" } '),
+ expect(json.parse(' {"x":3, "y": -4.5, "z" : "hi" } '),
equals({"x":3, "y": -4.5, "z" : "hi" }));
- expect(JSON.parse(' {"y": -4.5, "z" : "hi" ,"x":3 } '),
+ expect(json.parse(' {"y": -4.5, "z" : "hi" ,"x":3 } '),
equals({"y": -4.5, "z" : "hi" ,"x":3 }));
- expect(JSON.parse('{ " hi bob " :3, "": 4.5}'),
+ expect(json.parse('{ " hi bob " :3, "": 4.5}'),
equals({ " hi bob " :3, "": 4.5}));
- expect(JSON.parse(' { "x" : { } } '), equals({ 'x' : {}}));
- expect(JSON.parse('{"x":{}}'), equals({ 'x' : {}}));
+ expect(json.parse(' { "x" : { } } '), equals({ 'x' : {}}));
+ expect(json.parse('{"x":{}}'), equals({ 'x' : {}}));
// Nulls are tricky.
- expect(JSON.parse('{"w":null}'), equals({ 'w' : null}));
+ expect(json.parse('{"w":null}'), equals({ 'w' : null}));
- expect(JSON.parse('{"x":{"w":null}}'), equals({"x":{"w":null}}));
+ expect(json.parse('{"x":{"w":null}}'), equals({"x":{"w":null}}));
- expect(JSON.parse(' {"x":3, "y": -4.5, "z" : "hi",'
+ expect(json.parse(' {"x":3, "y": -4.5, "z" : "hi",'
'"w":null, "u" : true, "v": false } '),
equals({"x":3, "y": -4.5, "z" : "hi",
"w":null, "u" : true, "v": false }));
- expect(JSON.parse('{"x": {"a":3, "b": -4.5}, "y":[{}], '
+ expect(json.parse('{"x": {"a":3, "b": -4.5}, "y":[{}], '
'"z":"hi","w":{"c":null,"d":true}, "v":null}'),
equals({"x": {"a":3, "b": -4.5}, "y":[{}],
"z":"hi","w":{"c":null,"d":true}, "v":null}));
test('stringify', () {
// Scalars.
- expect(JSON.stringify(5), equals('5'));
- expect(JSON.stringify(-42), equals('-42'));
+ expect(json.stringify(5), equals('5'));
+ expect(json.stringify(-42), equals('-42'));
// Dart does not guarantee a formatting for doubles,
// so reparse and compare to the original.
validateRoundTrip(3.14);
- expect(JSON.stringify(true), equals('true'));
- expect(JSON.stringify(false), equals('false'));
- expect(JSON.stringify(null), equals('null'));
- expect(JSON.stringify(' hi there" bob '), equals('" hi there\\" bob "'));
- expect(JSON.stringify('hi\\there'), equals('"hi\\\\there"'));
+ expect(json.stringify(true), equals('true'));
+ expect(json.stringify(false), equals('false'));
+ expect(json.stringify(null), equals('null'));
+ expect(json.stringify(' hi there" bob '), equals('" hi there\\" bob "'));
+ expect(json.stringify('hi\\there'), equals('"hi\\\\there"'));
// TODO(devoncarew): these tests break the dartium build
- //expect(JSON.stringify('hi\nthere'), equals('"hi\\nthere"'));
- //expect(JSON.stringify('hi\r\nthere'), equals('"hi\\r\\nthere"'));
- expect(JSON.stringify(''), equals('""'));
+ //expect(json.stringify('hi\nthere'), equals('"hi\\nthere"'));
+ //expect(json.stringify('hi\r\nthere'), equals('"hi\\r\\nthere"'));
+ expect(json.stringify(''), equals('""'));
// Lists.
- expect(JSON.stringify([]), equals('[]'));
- expect(JSON.stringify(new List(0)), equals('[]'));
- expect(JSON.stringify(new List(3)), equals('[null,null,null]'));
+ expect(json.stringify([]), equals('[]'));
+ expect(json.stringify(new List.fixedLength(0)), equals('[]'));
+ expect(json.stringify(new List.fixedLength(3)), equals('[null,null,null]'));
validateRoundTrip([3, -4.5, null, true, 'hi', false]);
- expect(JSON.stringify([[3], [], [null], ['hi', true]]),
+ expect(json.stringify([[3], [], [null], ['hi', true]]),
equals('[[3],[],[null],["hi",true]]'));
// Maps.
- expect(JSON.stringify({}), equals('{}'));
- expect(JSON.stringify(new Map()), equals('{}'));
- expect(JSON.stringify({'x':{}}), equals('{"x":{}}'));
- expect(JSON.stringify({'x':{'a':3}}), equals('{"x":{"a":3}}'));
+ expect(json.stringify({}), equals('{}'));
+ expect(json.stringify(new Map()), equals('{}'));
+ expect(json.stringify({'x':{}}), equals('{"x":{}}'));
+ expect(json.stringify({'x':{'a':3}}), equals('{"x":{"a":3}}'));
// Dart does not guarantee an order on the keys
// of a map literal, so reparse and compare to the original Map.
@@ -112,17 +112,17 @@ main() {
{'x':{'a':3, 'b':-4.5}, 'y':[{}], 'z':'hi', 'w':{'c':null, 'd':true},
'v':null});
- expect(JSON.stringify(new ToJson(4)), "4");
- expect(JSON.stringify(new ToJson([4, "a"])), '[4,"a"]');
- expect(JSON.stringify(new ToJson([4, new ToJson({"x":42})])),
+ expect(json.stringify(new ToJson(4)), "4");
+ expect(json.stringify(new ToJson([4, "a"])), '[4,"a"]');
+ expect(json.stringify(new ToJson([4, new ToJson({"x":42})])),
'[4,{"x":42}]');
Expect.throws(() {
- JSON.stringify([new ToJson(new ToJson(4))]);
+ json.stringify([new ToJson(new ToJson(4))]);
});
Expect.throws(() {
- JSON.stringify([new Object()]);
+ json.stringify([new Object()]);
});
});
@@ -132,7 +132,7 @@ main() {
* Checks that we get an exception (rather than silently returning null) if
* we try to stringify something that cannot be converted to json.
*/
- expect(() => JSON.stringify(new TestClass()), throws);
+ expect(() => json.stringify(new TestClass()), throws);
});
});
}
@@ -155,7 +155,7 @@ class ToJson {
* back, and produce something equivalent to the argument.
*/
validateRoundTrip(expected) {
- expect(JSON.parse(JSON.stringify(expected)), equals(expected));
+ expect(json.parse(json.stringify(expected)), equals(expected));
}
« no previous file with comments | « tests/isolate/timer_test.dart ('k') | tests/language/arithmetic_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698