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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 ..addRuleFor(stream, | 122 ..addRuleFor(stream, |
123 constructorFields: ['_collection']); | 123 constructorFields: ['_collection']); |
124 var state = states(stream, s).first; | 124 var state = states(stream, s).first; |
125 // Define names for the variable offsets to make this more readable. | 125 // Define names for the variable offsets to make this more readable. |
126 var _collection = 0, position = 1; | 126 var _collection = 0, position = 1; |
127 expect(state[_collection],[3,4,5]); | 127 expect(state[_collection],[3,4,5]); |
128 expect(state[position], 2); | 128 expect(state[position], 2); |
129 }); | 129 }); |
130 | 130 |
131 test('date', () { | 131 test('date', () { |
132 var date = new Date.now(); | 132 var date = new DateTime.now(); |
133 var s = new Serialization() | 133 var s = new Serialization() |
134 ..addRuleFor(date, | 134 ..addRuleFor(date, |
135 constructorFields : ["year", "month", "day", "hour", "minute", | 135 constructorFields : ["year", "month", "day", "hour", "minute", |
136 "second", "millisecond", "isUtc"]) | 136 "second", "millisecond", "isUtc"]) |
137 .configureForMaps(); | 137 .configureForMaps(); |
138 var state = states(date, s).first; | 138 var state = states(date, s).first; |
139 expect(state["year"],date.year); | 139 expect(state["year"],date.year); |
140 expect(state["isUtc"],date.isUtc); | 140 expect(state["isUtc"],date.isUtc); |
141 expect(state["millisecond"], date.millisecond); | 141 expect(state["millisecond"], date.millisecond); |
142 }); | 142 }); |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 /** A hard-coded rule for serializing Node instances. */ | 568 /** A hard-coded rule for serializing Node instances. */ |
569 class NodeRule extends CustomRule { | 569 class NodeRule extends CustomRule { |
570 bool appliesTo(instance, _) => instance.runtimeType == Node; | 570 bool appliesTo(instance, _) => instance.runtimeType == Node; |
571 getState(instance) => [instance.parent, instance.name, instance.children]; | 571 getState(instance) => [instance.parent, instance.name, instance.children]; |
572 create(state) => new Node(state[1]); | 572 create(state) => new Node(state[1]); |
573 setState(Node node, state) { | 573 setState(Node node, state) { |
574 node.parent = state[0]; | 574 node.parent = state[0]; |
575 node.children = state[2]; | 575 node.children = state[2]; |
576 } | 576 } |
577 } | 577 } |
OLD | NEW |