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