| 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 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 import 'package:serialization/serialization.dart'; | 8 import 'package:serialization/serialization.dart'; |
| 9 import 'package:serialization/src/serialization_helpers.dart'; | 9 import 'package:serialization/src/serialization_helpers.dart'; |
| 10 import 'package:serialization/src/mirrors_helpers.dart'; | 10 import 'package:serialization/src/mirrors_helpers.dart'; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 expect(m1, m2); | 299 expect(m1, m2); |
| 300 expect(identical(m1, m2), isFalse); | 300 expect(identical(m1, m2), isFalse); |
| 301 expect(m1 == m3, isFalse); | 301 expect(m1 == m3, isFalse); |
| 302 expect(identical(m2.parent, m3.parent), isTrue); | 302 expect(identical(m2.parent, m3.parent), isTrue); |
| 303 }); | 303 }); |
| 304 | 304 |
| 305 test("Constant values as fields", () { | 305 test("Constant values as fields", () { |
| 306 var s = new Serialization() | 306 var s = new Serialization() |
| 307 ..selfDescribing = false | 307 ..selfDescribing = false |
| 308 ..addRuleFor(a1, | 308 ..addRuleFor(a1, |
| 309 constructor: 'with', | 309 constructor: 'withData', |
| 310 constructorFields: ["street", "Kirkland", "WA", "98103"], | 310 constructorFields: ["street", "Kirkland", "WA", "98103"], |
| 311 fields: []); | 311 fields: []); |
| 312 var out = s.write(a1); | 312 var out = s.write(a1); |
| 313 var newAddress = s.read(out); | 313 var newAddress = s.read(out); |
| 314 expect(newAddress.street, a1.street); | 314 expect(newAddress.street, a1.street); |
| 315 expect(newAddress.city, "Kirkland"); | 315 expect(newAddress.city, "Kirkland"); |
| 316 expect(newAddress.state, "WA"); | 316 expect(newAddress.state, "WA"); |
| 317 expect(newAddress.zip, "98103"); | 317 expect(newAddress.zip, "98103"); |
| 318 }); | 318 }); |
| 319 | 319 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 /** A hard-coded rule for serializing Node instances. */ | 496 /** A hard-coded rule for serializing Node instances. */ |
| 497 class NodeRule extends CustomRule { | 497 class NodeRule extends CustomRule { |
| 498 bool appliesTo(instance, _) => instance is Node; | 498 bool appliesTo(instance, _) => instance is Node; |
| 499 getState(instance) => [instance.parent, instance.name, instance.children]; | 499 getState(instance) => [instance.parent, instance.name, instance.children]; |
| 500 create(state) => new Node(state[1]); | 500 create(state) => new Node(state[1]); |
| 501 setState(Node node, state) { | 501 setState(Node node, state) { |
| 502 node.parent = state[0]; | 502 node.parent = state[0]; |
| 503 node.children = state[2]; | 503 node.children = state[2]; |
| 504 } | 504 } |
| 505 } | 505 } |
| OLD | NEW |