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

Side by Side Diff: test/json_test.dart

Issue 2612233003: Always serialize 64-bit integers as strings in JSON. (Closed)
Patch Set: Add test for JSON-coding of int64s Created 3 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 unified diff | Download patch
« no previous file with comments | « test/event_test.dart ('k') | test/map_mixin_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 // Basic smoke tests for the GeneratedMessage JSON API. 1 // Basic smoke tests for the GeneratedMessage JSON API.
2 // 2 //
3 // There are more JSON tests in the dart-protoc-plugin package. 3 // There are more JSON tests in the dart-protoc-plugin package.
4 library json_test; 4 library json_test;
5 5
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'package:fixnum/fixnum.dart' show Int64;
7 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
8 9
9 import 'mock_util.dart' show MockMessage, mockInfo; 10 import 'mock_util.dart' show MockMessage, mockInfo;
10 11
11 class T extends MockMessage { 12 class T extends MockMessage {
12 get info_ => _info; 13 get info_ => _info;
13 static final _info = mockInfo("T", () => new T()); 14 static final _info = mockInfo("T", () => new T());
14 } 15 }
15 16
16 main() { 17 main() {
(...skipping 15 matching lines...) Expand all
32 var t = new T(); 33 var t = new T();
33 t.mergeFromJson('''{"1": 123, "2": "hello"}'''); 34 t.mergeFromJson('''{"1": 123, "2": "hello"}''');
34 checkMessage(t); 35 checkMessage(t);
35 }); 36 });
36 37
37 test('testMergeFromJsonMap', () { 38 test('testMergeFromJsonMap', () {
38 var t = new T(); 39 var t = new T();
39 t.mergeFromJsonMap({"1": 123, "2": "hello"}); 40 t.mergeFromJsonMap({"1": 123, "2": "hello"});
40 checkMessage(t); 41 checkMessage(t);
41 }); 42 });
43
44 test('testInt64JsonEncoding', () {
45 final value = new Int64(1234567890123456789);
46 final t = new T()
47 ..int64 = value;
48 final encoded = t.writeToJsonMap();
49 expect(encoded["5"], "$value");
50 final decoded = new T()..mergeFromJsonMap(encoded);
51 expect(decoded.int64, value);
52 });
42 } 53 }
43 54
44 checkJsonMap(Map m) { 55 checkJsonMap(Map m) {
45 expect(m.length, 2); 56 expect(m.length, 2);
46 expect(m["1"], 123); 57 expect(m["1"], 123);
47 expect(m["2"], "hello"); 58 expect(m["2"], "hello");
48 } 59 }
49 60
50 checkMessage(T t) { 61 checkMessage(T t) {
51 expect(t.val, 123); 62 expect(t.val, 123);
52 expect(t.str, "hello"); 63 expect(t.str, "hello");
53 } 64 }
OLDNEW
« no previous file with comments | « test/event_test.dart ('k') | test/map_mixin_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698