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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 expect(m2.name, "2"); | 634 expect(m2.name, "2"); |
635 expect(m3.name, "3"); | 635 expect(m3.name, "3"); |
636 expect(m2.parent, m1); | 636 expect(m2.parent, m1); |
637 expect(m3.parent, m1); | 637 expect(m3.parent, m1); |
638 expect(m1.parent, isNull); | 638 expect(m1.parent, isNull); |
639 } | 639 } |
640 | 640 |
641 /** Extract the state from [object] using the rules in [s] and return it. */ | 641 /** Extract the state from [object] using the rules in [s] and return it. */ |
642 states(object, Serialization s) { | 642 states(object, Serialization s) { |
643 var rules = s.rulesFor(object, null); | 643 var rules = s.rulesFor(object, null); |
644 return rules.mappedBy((x) => x.extractState(object, doNothing)).toList(); | 644 return rules.map((x) => x.extractState(object, doNothing)).toList(); |
645 } | 645 } |
646 | 646 |
647 /** A hard-coded rule for serializing Node instances. */ | 647 /** A hard-coded rule for serializing Node instances. */ |
648 class NodeRule extends CustomRule { | 648 class NodeRule extends CustomRule { |
649 bool appliesTo(instance, _) => instance.runtimeType == Node; | 649 bool appliesTo(instance, _) => instance.runtimeType == Node; |
650 getState(instance) => [instance.parent, instance.name, instance.children]; | 650 getState(instance) => [instance.parent, instance.name, instance.children]; |
651 create(state) => new Node(state[1]); | 651 create(state) => new Node(state[1]); |
652 setState(Node node, state) { | 652 setState(Node node, state) { |
653 node.parent = state[0]; | 653 node.parent = state[0]; |
654 node.children = state[2]; | 654 node.children = state[2]; |
655 } | 655 } |
656 } | 656 } |
OLD | NEW |