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

Side by Side Diff: tests/json/json_test.dart

Issue 212643007: Revert "Fix JSON tests, re-enable in all cases" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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
« no previous file with comments | « tests/json/json.status ('k') | tests/lib/convert/json2_test.dart » ('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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 json2_tests; 5 library json_tests;
6 import "package:expect/expect.dart";
7 import "dart:convert";
8 import 'dart:html';
9 import '../../pkg/unittest/lib/unittest.dart';
10 import '../../pkg/unittest/lib/html_config.dart';
6 11
7 import "dart:convert"; 12 main() {
8 13 useHtmlConfiguration();
9 import 'package:unittest/unittest.dart';
10
11 // Moved from "tests/json/json_test.dart"
12
13 void main() {
14 test('Parse', () { 14 test('Parse', () {
15 // Scalars. 15 // Scalars.
16 expect(JSON.decode(' 5 '), equals(5)); 16 expect(JSON.decode(' 5 '), equals(5));
17 expect(JSON.decode(' -42 '), equals(-42)); 17 expect(JSON.decode(' -42 '), equals(-42));
18 expect(JSON.decode(' 3e0 '), equals(3)); 18 expect(JSON.decode(' 3e0 '), equals(3));
19 expect(JSON.decode(' 3.14 '), equals(3.14)); 19 expect(JSON.decode(' 3.14 '), equals(3.14));
20 expect(JSON.decode('true '), isTrue); 20 expect(JSON.decode('true '), isTrue);
21 expect(JSON.decode(' false'), isFalse); 21 expect(JSON.decode(' false'), isFalse);
22 expect(JSON.decode(' null '), isNull); 22 expect(JSON.decode(' null '), isNull);
23 expect(JSON.decode('\n\rnull\t'), isNull); 23 expect(JSON.decode('\n\rnull\t'), isNull);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 expect(JSON.encode(5), equals('5')); 78 expect(JSON.encode(5), equals('5'));
79 expect(JSON.encode(-42), equals('-42')); 79 expect(JSON.encode(-42), equals('-42'));
80 // Dart does not guarantee a formatting for doubles, 80 // Dart does not guarantee a formatting for doubles,
81 // so reparse and compare to the original. 81 // so reparse and compare to the original.
82 validateRoundTrip(3.14); 82 validateRoundTrip(3.14);
83 expect(JSON.encode(true), equals('true')); 83 expect(JSON.encode(true), equals('true'));
84 expect(JSON.encode(false), equals('false')); 84 expect(JSON.encode(false), equals('false'));
85 expect(JSON.encode(null), equals('null')); 85 expect(JSON.encode(null), equals('null'));
86 expect(JSON.encode(' hi there" bob '), equals('" hi there\\" bob "')); 86 expect(JSON.encode(' hi there" bob '), equals('" hi there\\" bob "'));
87 expect(JSON.encode('hi\\there'), equals('"hi\\\\there"')); 87 expect(JSON.encode('hi\\there'), equals('"hi\\\\there"'));
88 expect(JSON.encode('hi\nthere'), equals('"hi\\nthere"')); 88 // TODO(devoncarew): these tests break the dartium build
89 expect(JSON.encode('hi\r\nthere'), equals('"hi\\r\\nthere"')); 89 //expect(JSON.encode('hi\nthere'), equals('"hi\\nthere"'));
90 //expect(JSON.encode('hi\r\nthere'), equals('"hi\\r\\nthere"'));
90 expect(JSON.encode(''), equals('""')); 91 expect(JSON.encode(''), equals('""'));
91 92
92 // Lists. 93 // Lists.
93 expect(JSON.encode([]), equals('[]')); 94 expect(JSON.encode([]), equals('[]'));
94 expect(JSON.encode(new List(0)), equals('[]')); 95 expect(JSON.encode(new List(0)), equals('[]'));
95 expect(JSON.encode(new List(3)), equals('[null,null,null]')); 96 expect(JSON.encode(new List(3)), equals('[null,null,null]'));
96 validateRoundTrip([3, -4.5, null, true, 'hi', false]); 97 validateRoundTrip([3, -4.5, null, true, 'hi', false]);
97 expect(JSON.encode([[3], [], [null], ['hi', true]]), 98 expect(JSON.encode([[3], [], [null], ['hi', true]]),
98 equals('[[3],[],[null],["hi",true]]')); 99 equals('[[3],[],[null],["hi",true]]'));
99 100
(...skipping 11 matching lines...) Expand all
111 validateRoundTrip({' hi bob ':3, '':4.5}); 112 validateRoundTrip({' hi bob ':3, '':4.5});
112 validateRoundTrip( 113 validateRoundTrip(
113 {'x':{'a':3, 'b':-4.5}, 'y':[{}], 'z':'hi', 'w':{'c':null, 'd':true}, 114 {'x':{'a':3, 'b':-4.5}, 'y':[{}], 'z':'hi', 'w':{'c':null, 'd':true},
114 'v':null}); 115 'v':null});
115 116
116 expect(JSON.encode(new ToJson(4)), "4"); 117 expect(JSON.encode(new ToJson(4)), "4");
117 expect(JSON.encode(new ToJson([4, "a"])), '[4,"a"]'); 118 expect(JSON.encode(new ToJson([4, "a"])), '[4,"a"]');
118 expect(JSON.encode(new ToJson([4, new ToJson({"x":42})])), 119 expect(JSON.encode(new ToJson([4, new ToJson({"x":42})])),
119 '[4,{"x":42}]'); 120 '[4,{"x":42}]');
120 121
121 expect(() => JSON.encode([new ToJson(new ToJson(4))]), throws); 122 Expect.throws(() {
123 JSON.encode([new ToJson(new ToJson(4))]);
124 });
122 125
123 expect(() => JSON.encode([new Object()]), throws); 126 Expect.throws(() {
127 JSON.encode([new Object()]);
128 });
129
124 }); 130 });
125 131
126 test('stringify throws if argument cannot be converted', () { 132 test('stringify throws if argument cannot be converted', () {
127 /** 133 /**
128 * Checks that we get an exception (rather than silently returning null) if 134 * Checks that we get an exception (rather than silently returning null) if
129 * we try to stringify something that cannot be converted to json. 135 * we try to stringify something that cannot be converted to json.
130 */ 136 */
131 expect(() => JSON.encode(new TestClass()), throws); 137 expect(() => JSON.encode(new TestClass()), throws);
132 }); 138 });
133 139
(...skipping 21 matching lines...) Expand all
155 class ToJson { 161 class ToJson {
156 final object; 162 final object;
157 const ToJson(this.object); 163 const ToJson(this.object);
158 toJson() => object; 164 toJson() => object;
159 } 165 }
160 166
161 /** 167 /**
162 * Checks that the argument can be converted to a JSON string and 168 * Checks that the argument can be converted to a JSON string and
163 * back, and produce something equivalent to the argument. 169 * back, and produce something equivalent to the argument.
164 */ 170 */
165 void validateRoundTrip(expected) { 171 validateRoundTrip(expected) {
166 expect(JSON.decode(JSON.encode(expected)), equals(expected)); 172 expect(JSON.decode(JSON.encode(expected)), equals(expected));
167 } 173 }
OLDNEW
« no previous file with comments | « tests/json/json.status ('k') | tests/lib/convert/json2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698