| OLD | NEW |
| 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 json_test; | 5 library json_test; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import "dart:convert"; | 8 import "dart:convert"; |
| 9 | 9 |
| 10 bool badFormat(e) => e is FormatException; | 10 bool badFormat(e) => e is FormatException; |
| 11 | 11 |
| 12 jsonTest(testName, expect, action(sink)) { | 12 jsonTest(testName, expect, action(sink)) { |
| 13 var sink = new ChunkedConversionSink.withCallback((values) { | 13 var sink = new ChunkedConversionSink<dynamic>.withCallback((values) { |
| 14 var value = values[0]; | 14 var value = values[0]; |
| 15 Expect.equals(expect, value, "$testName:$value"); | 15 Expect.equals(expect, value, "$testName:$value"); |
| 16 }); | 16 }); |
| 17 var decoderSink = JSON.decoder.startChunkedConversion(sink); | 17 var decoderSink = JSON.decoder.startChunkedConversion(sink); |
| 18 action(decoderSink); | 18 action(decoderSink); |
| 19 } | 19 } |
| 20 | 20 |
| 21 jsonThrowsTest(testName, action(sink)) { | 21 jsonThrowsTest(testName, action(sink)) { |
| 22 var sink = new ChunkedConversionSink.withCallback((values) { | 22 var sink = new ChunkedConversionSink<dynamic>.withCallback((values) { |
| 23 Expect.fail("Should have thrown: $testName"); | 23 Expect.fail("Should have thrown: $testName"); |
| 24 }); | 24 }); |
| 25 var decoderSink = JSON.decoder.startChunkedConversion(sink); | 25 var decoderSink = JSON.decoder.startChunkedConversion(sink); |
| 26 Expect.throws(() { action(decoderSink); }, (e) => e is FormatException, | 26 Expect.throws(() { action(decoderSink); }, (e) => e is FormatException, |
| 27 testName); | 27 testName); |
| 28 } | 28 } |
| 29 | 29 |
| 30 main() { | 30 main() { |
| 31 testNumbers(); | 31 testNumbers(); |
| 32 testStrings(); | 32 testStrings(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 jsonTest("$s1|$s2a|$s2b", expected, (sink) { | 164 jsonTest("$s1|$s2a|$s2b", expected, (sink) { |
| 165 sink.add(s1); | 165 sink.add(s1); |
| 166 sink.add(s2a); | 166 sink.add(s2a); |
| 167 sink.add(s2b); | 167 sink.add(s2b); |
| 168 sink.close(); | 168 sink.close(); |
| 169 }); | 169 }); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 } | 173 } |
| OLD | NEW |