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

Unified Diff: test/codegen/lib/convert/json_pretty_test.dart

Issue 1965563003: Update dart:convert and dart:core Uri. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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
Index: test/codegen/lib/convert/json_pretty_test.dart
diff --git a/test/codegen/lib/convert/json_pretty_test.dart b/test/codegen/lib/convert/json_pretty_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..62380525aca53d9fb240278d45f6c52bb6015247
--- /dev/null
+++ b/test/codegen/lib/convert/json_pretty_test.dart
@@ -0,0 +1,116 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Note: This test relies on LF line endings in the source file.
+
+library json_pretty_test;
+
+import 'dart:convert';
+
+import "package:expect/expect.dart";
+
+void _testIndentWithNullChar() {
+ var encoder = const JsonEncoder.withIndent('\x00');
+ var encoded = encoder.convert([[],[[]]]);
+ Expect.equals("[\n\x00[],\n\x00[\n\x00\x00[]\n\x00]\n]", encoded);
+}
+
+void main() {
+ _testIndentWithNullChar();
+
+ _expect(null, 'null');
+
+ _expect([[],[[]]], '''
+[
+ [],
+ [
+ []
+ ]
+]''');
+
+ _expect([1, 2, 3, 4], '''
+[
+ 1,
+ 2,
+ 3,
+ 4
+]''');
+
+ _expect([true, null, 'hello', 42.42],
+ '''
+[
+ true,
+ null,
+ "hello",
+ 42.42
+]''');
+
+ _expect({"hello": [], "goodbye": {} } ,
+'''{
+ "hello": [],
+ "goodbye": {}
+}''');
+
+ _expect(["test", 1, 2, 33234.324, true, false, null, {
+ "test1": "test2",
+ "test3": "test4",
+ "grace": 5,
+ "shanna": [0, 1, 2]
+ }, {
+ "lib": "app.dart",
+ "src": ["foo.dart", "bar.dart"]
+ }],
+ '''[
+ "test",
+ 1,
+ 2,
+ 33234.324,
+ true,
+ false,
+ null,
+ {
+ "test1": "test2",
+ "test3": "test4",
+ "grace": 5,
+ "shanna": [
+ 0,
+ 1,
+ 2
+ ]
+ },
+ {
+ "lib": "app.dart",
+ "src": [
+ "foo.dart",
+ "bar.dart"
+ ]
+ }
+]''');
+}
+
+void _expect(Object object, String expected) {
+ var encoder = const JsonEncoder.withIndent(' ');
+ var prettyOutput = encoder.convert(object);
+
+ Expect.equals(expected, prettyOutput);
+
+ encoder = const JsonEncoder.withIndent('');
+
+ var flatOutput = encoder.convert(object);
+
+ var flatExpected = const LineSplitter().convert(expected)
+ .map((line) => line.trimLeft())
+ .join('\n');
+
+ Expect.equals(flatExpected, flatOutput);
+
+ var compactOutput = JSON.encode(object);
+
+ encoder = const JsonEncoder.withIndent(null);
+ Expect.equals(compactOutput, encoder.convert(object));
+
+ var prettyDecoded = JSON.decode(prettyOutput);
+
+ Expect.equals(compactOutput, JSON.encode(prettyDecoded));
+}

Powered by Google App Engine
This is Rietveld 408576698