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

Side by Side Diff: tests/lib/codec/codec2_test.dart

Issue 19000006: First version of Codecs and Converters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert sdk/lib/json change. Created 7 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 | Annotate | Revision Log
« sdk/lib/convert/utf.dart ('K') | « tests/lib/codec/codec1_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'dart:codec';
6
7 import 'package:expect/expect.dart';
8
9 main() {
10 final RAW = '["122ç",50,50,231]';
11 final ENCODED = const [91, 34, 49, 50, 50, 195, 167, 34, 44,
12 53, 48, 44, 53, 48, 44, 50, 51, 49, 93];
13 final UTF8 = Encoding.UTF8;
14 Expect.listEquals(ENCODED, UTF8.encode(RAW));
15 Expect.equals(RAW, UTF8.decode(ENCODED));
16
17 Expect.listEquals([], UTF8.encode(""));
18 Expect.equals("", UTF8.decode([]));
19
20 final JSON_ENCODED = RAW;
21 Expect.equals(JSON_ENCODED, JSON.encode(["122ç", 50, 50, 231]));
22 Expect.listEquals(["122ç", 50, 50, 231], JSON.decode(JSON_ENCODED));
23
24 // Test that the reviver is passed to the decoder.
25 var decoded = JSON.decode('{"p": 5}', reviver: (k, v) {
26 if (k == "") return v;
27 return v * 2;
28 });
29 Expect.equals(10, decoded["p"]);
30 var jsonWithReviver = new JsonCodec.withReviver((k, v) {
31 if (k == "") return v;
32 return v * 2;
33 });
34 decoded = jsonWithReviver.decode('{"p": 5}');
35 Expect.equals(10, decoded["p"]);
36
37 // Test example from comments.
38 final JSON_TO_BYTES = JSON.fuse(Encoding.UTF8);
39 List<int> bytes = JSON_TO_BYTES.encode(["json-object"]);
40 decoded = JSON_TO_BYTES.decode(bytes);
41 Expect.isTrue(decoded is List);
42 Expect.equals("json-object", decoded[0]);
43 }
OLDNEW
« sdk/lib/convert/utf.dart ('K') | « tests/lib/codec/codec1_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698