| 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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 } | 508 } |
| 509 | 509 |
| 510 /** | 510 /** |
| 511 * Set up a basic reader with some fake data. Hard-codes the assumption | 511 * Set up a basic reader with some fake data. Hard-codes the assumption |
| 512 * of how many rules there are. | 512 * of how many rules there are. |
| 513 */ | 513 */ |
| 514 Reader setUpReader(aSerialization, sampleData) { | 514 Reader setUpReader(aSerialization, sampleData) { |
| 515 var reader = new Reader(aSerialization); | 515 var reader = new Reader(aSerialization); |
| 516 // We're not sure which rule needs the sample data, so put it everywhere | 516 // We're not sure which rule needs the sample data, so put it everywhere |
| 517 // and trust that the extra will just be ignored. | 517 // and trust that the extra will just be ignored. |
| 518 reader.data = new List.filled(10, [sampleData]); | 518 var fillValue = [sampleData]; |
| 519 var data = []; |
| 520 for (int i = 0; i < 10; i++) { |
| 521 data.add(fillValue); |
| 522 } |
| 523 reader.data = data; |
| 519 return reader; | 524 return reader; |
| 520 } | 525 } |
| 521 | 526 |
| 522 /** Return a serialization for Node objects, using a reflective rule. */ | 527 /** Return a serialization for Node objects, using a reflective rule. */ |
| 523 Serialization nodeSerializerReflective(Node n) { | 528 Serialization nodeSerializerReflective(Node n) { |
| 524 return new Serialization() | 529 return new Serialization() |
| 525 ..addRuleFor(n, constructorFields: ["name"]) | 530 ..addRuleFor(n, constructorFields: ["name"]) |
| 526 ..namedObjects['Node'] = reflect(new Node('')).type; | 531 ..namedObjects['Node'] = reflect(new Node('')).type; |
| 527 } | 532 } |
| 528 | 533 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 | 646 |
| 642 /** A hard-coded rule for serializing Node instances. */ | 647 /** A hard-coded rule for serializing Node instances. */ |
| 643 class NodeRule extends CustomRule { | 648 class NodeRule extends CustomRule { |
| 644 bool appliesTo(instance, _) => instance.runtimeType == Node; | 649 bool appliesTo(instance, _) => instance.runtimeType == Node; |
| 645 getState(instance) => [instance.parent, instance.name, instance.children]; | 650 getState(instance) => [instance.parent, instance.name, instance.children]; |
| 646 create(state) => new Node(state[1]); | 651 create(state) => new Node(state[1]); |
| 647 setState(Node node, state) { | 652 setState(Node node, state) { |
| 648 node.parent = state[0]; | 653 node.parent = state[0]; |
| 649 node.children = state[2]; | 654 node.children = state[2]; |
| 650 } | 655 } |
| 651 } | 656 } |
| OLD | NEW |