OLD | NEW |
(Empty) | |
| 1 dart_library.library('lib/convert/json_toEncodable_reviver_test', null, /* Impor
ts */[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__json_toEncodable_reviver_test(exports, dart_sdk, expect) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const convert = dart_sdk.convert; |
| 8 const _interceptors = dart_sdk._interceptors; |
| 9 const dart = dart_sdk.dart; |
| 10 const dartx = dart_sdk.dartx; |
| 11 const expect$ = expect.expect; |
| 12 const json_toEncodable_reviver_test = Object.create(null); |
| 13 let JSArrayOfObject = () => (JSArrayOfObject = dart.constFn(_interceptors.JSAr
ray$(core.Object)))(); |
| 14 let ATodynamic = () => (ATodynamic = dart.constFn(dart.definiteFunctionType(da
rt.dynamic, [json_toEncodable_reviver_test.A])))(); |
| 15 let dynamicAnddynamicTodynamic = () => (dynamicAnddynamicTodynamic = dart.cons
tFn(dart.definiteFunctionType(dart.dynamic, [dart.dynamic, dart.dynamic])))(); |
| 16 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
| 17 let dynamicToString = () => (dynamicToString = dart.constFn(dart.definiteFunct
ionType(core.String, [dart.dynamic])))(); |
| 18 let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.definiteFunctionType(da
rt.void, [])))(); |
| 19 json_toEncodable_reviver_test.A = class A extends core.Object { |
| 20 new(x) { |
| 21 this.x = x; |
| 22 } |
| 23 }; |
| 24 dart.setSignature(json_toEncodable_reviver_test.A, { |
| 25 constructors: () => ({new: dart.definiteFunctionType(json_toEncodable_revive
r_test.A, [dart.dynamic])}) |
| 26 }); |
| 27 json_toEncodable_reviver_test.toEncodable = function(a) { |
| 28 return dart.map({A: a.x}); |
| 29 }; |
| 30 dart.fn(json_toEncodable_reviver_test.toEncodable, ATodynamic()); |
| 31 json_toEncodable_reviver_test.reviver = function(key, value) { |
| 32 if (core.Map.is(value) && value[dartx.length] == 1 && value[dartx.get]("A")
!= null) { |
| 33 return new json_toEncodable_reviver_test.A(value[dartx.get]("A")); |
| 34 } |
| 35 return value; |
| 36 }; |
| 37 dart.fn(json_toEncodable_reviver_test.reviver, dynamicAnddynamicTodynamic()); |
| 38 json_toEncodable_reviver_test.extendedJson = dart.const(new convert.JsonCodec(
{toEncodable: json_toEncodable_reviver_test.toEncodable, reviver: json_toEncodab
le_reviver_test.reviver})); |
| 39 json_toEncodable_reviver_test.main = function() { |
| 40 let encoded = json_toEncodable_reviver_test.extendedJson.encode(JSArrayOfObj
ect().of([new json_toEncodable_reviver_test.A(0), dart.map({"2": new json_toEnco
dable_reviver_test.A(1)})])); |
| 41 expect$.Expect.equals('[{"A":0},{"2":{"A":1}}]', encoded); |
| 42 let decoded = json_toEncodable_reviver_test.extendedJson.decode(encoded); |
| 43 expect$.Expect.isTrue(core.List.is(decoded)); |
| 44 expect$.Expect.equals(2, dart.dload(decoded, 'length')); |
| 45 expect$.Expect.isTrue(json_toEncodable_reviver_test.A.is(dart.dindex(decoded
, 0))); |
| 46 expect$.Expect.equals(0, dart.dload(dart.dindex(decoded, 0), 'x')); |
| 47 expect$.Expect.isTrue(core.Map.is(dart.dindex(decoded, 1))); |
| 48 expect$.Expect.isNotNull(dart.dindex(dart.dindex(decoded, 1), "2")); |
| 49 expect$.Expect.isTrue(json_toEncodable_reviver_test.A.is(dart.dindex(dart.di
ndex(decoded, 1), "2"))); |
| 50 expect$.Expect.equals(1, dart.dload(dart.dindex(dart.dindex(decoded, 1), "2"
), 'x')); |
| 51 let a = json_toEncodable_reviver_test.extendedJson.decode(json_toEncodable_r
eviver_test.extendedJson.encode(new json_toEncodable_reviver_test.A(499))); |
| 52 expect$.Expect.isTrue(json_toEncodable_reviver_test.A.is(a)); |
| 53 expect$.Expect.equals(499, dart.dload(a, 'x')); |
| 54 json_toEncodable_reviver_test.testInvalidMap(); |
| 55 }; |
| 56 dart.fn(json_toEncodable_reviver_test.main, VoidTodynamic()); |
| 57 json_toEncodable_reviver_test.testInvalidMap = function() { |
| 58 let map = dart.map(["a", 42, "b", 42, 37, 42]); |
| 59 let enc = new convert.JsonEncoder(dart.fn(_ => "fixed", dynamicToString())); |
| 60 let res = enc.convert(map); |
| 61 expect$.Expect.equals('"fixed"', res); |
| 62 enc = new convert.JsonEncoder.withIndent(" ", dart.fn(_ => "fixed", dynamicT
oString())); |
| 63 res = enc.convert(map); |
| 64 expect$.Expect.equals('"fixed"', res); |
| 65 }; |
| 66 dart.fn(json_toEncodable_reviver_test.testInvalidMap, VoidTovoid()); |
| 67 // Exports: |
| 68 exports.json_toEncodable_reviver_test = json_toEncodable_reviver_test; |
| 69 }); |
OLD | NEW |