Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 serialization_test; | 5 library serialization_test; |
| 6 | 6 |
| 7 import 'dart:json' as json; | 7 import 'dart:json' as json; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 import 'package:serialization/serialization.dart'; | 9 import 'package:serialization/serialization.dart'; |
| 10 import 'package:serialization/src/serialization_helpers.dart'; | 10 import 'package:serialization/src/serialization_helpers.dart'; |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 }); | 465 }); |
| 466 | 466 |
| 467 test("More complicated Maps", () { | 467 test("More complicated Maps", () { |
| 468 var s = new Serialization()..selfDescribing = false; | 468 var s = new Serialization()..selfDescribing = false; |
| 469 var p1 = new Person()..name = 'Alice'..address = a1; | 469 var p1 = new Person()..name = 'Alice'..address = a1; |
| 470 var data = new Map(); | 470 var data = new Map(); |
| 471 data["simple data"] = 1; | 471 data["simple data"] = 1; |
| 472 data[p1] = a1; | 472 data[p1] = a1; |
| 473 data[a1] = p1; | 473 data[a1] = p1; |
| 474 for (var eachFormat in formats) { | 474 for (var eachFormat in formats) { |
| 475 print(eachFormat); | |
|
floitsch
2013/02/26 13:54:19
remove.
Lasse Reichstein Nielsen
2013/02/26 15:26:00
Done.
| |
| 475 var output = s.write(data, eachFormat); | 476 var output = s.write(data, eachFormat); |
| 476 var reader = s.newReader(eachFormat); | 477 var reader = s.newReader(eachFormat); |
| 477 var input = reader.read(output); | 478 var input = reader.read(output); |
| 478 expect(input["simple data"], data["simple data"]); | 479 expect(input["simple data"], data["simple data"]); |
| 479 var p2 = input.keys.firstMatching((x) => x is Person); | 480 var p2 = input.keys.firstMatching((x) => x is Person); |
| 480 var a2 = input.keys.firstMatching((x) => x is Address); | 481 var a2 = input.keys.firstMatching((x) => x is Address); |
| 481 if (eachFormat is SimpleJsonFormat) { | 482 if (eachFormat is SimpleJsonFormat) { |
| 482 // JSON doesn't handle cycles, so these won't be identical. | 483 // JSON doesn't handle cycles, so these won't be identical. |
| 483 expect(input[p2] is Address, isTrue); | 484 expect(input[p2] is Address, isTrue); |
| 484 expect(input[a2] is Person, isTrue); | 485 expect(input[a2] is Person, isTrue); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 } | 740 } |
| 740 findValue(String key, Map state) { | 741 findValue(String key, Map state) { |
| 741 var answer; | 742 var answer; |
| 742 for (var each in state.keys) { | 743 for (var each in state.keys) { |
| 743 var value = state[each]; | 744 var value = state[each]; |
| 744 if (value == key) return each; | 745 if (value == key) return each; |
| 745 } | 746 } |
| 746 return null; | 747 return null; |
| 747 } | 748 } |
| 748 } | 749 } |
| OLD | NEW |