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 '../../unittest/lib/unittest.dart'; | 7 import '../../unittest/lib/unittest.dart'; |
8 import '../lib/serialization.dart'; | 8 import '../lib/serialization.dart'; |
9 import '../lib/src/serialization_helpers.dart'; | 9 import '../lib/src/serialization_helpers.dart'; |
10 import '../lib/src/mirrors_helpers.dart'; | 10 import '../lib/src/mirrors_helpers.dart'; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 // and get their types. If only we had class literals implemented... | 315 // and get their types. If only we had class literals implemented... |
316 var basicRule = new BasicRule(reflect(null).type, '', [], [], []); | 316 var basicRule = new BasicRule(reflect(null).type, '', [], [], []); |
317 | 317 |
318 var meta = new Serialization() | 318 var meta = new Serialization() |
319 ..selfDescribing = false | 319 ..selfDescribing = false |
320 ..addRuleFor(new ListRule()) | 320 ..addRuleFor(new ListRule()) |
321 ..addRuleFor(new PrimitiveRule()) | 321 ..addRuleFor(new PrimitiveRule()) |
322 // TODO(alanknight): Handle CustomRule as well. | 322 // TODO(alanknight): Handle CustomRule as well. |
323 // Note that we're passing in a constant for one of the fields. | 323 // Note that we're passing in a constant for one of the fields. |
324 ..addRuleFor(basicRule, | 324 ..addRuleFor(basicRule, |
325 constructorFields: ['typeWrapped', | 325 constructorFields: ['type', |
326 'constructorName', | 326 'constructorName', |
327 'constructorFields', 'regularFields', []], | 327 'constructorFields', 'regularFields', []], |
328 fields: []) | 328 fields: []) |
329 ..addRuleFor(new Serialization()).specialTreatmentFor('rules', | 329 ..addRuleFor(new Serialization()).specialTreatmentFor('rules', |
330 (InstanceMirror s, List rules) { | 330 (InstanceMirror s, List rules) { |
331 rules.forEach((x) => s.reflectee.addRule(x)); | 331 rules.forEach((x) => s.reflectee.addRule(x)); |
332 }) | 332 }) |
333 ..addRule(new NamedObjectRule()) | 333 ..addRule(new NamedObjectRule()) |
334 ..addRule(new MirrorRule()); | 334 ..addRule(new MirrorRule()); |
335 return meta; | 335 return meta; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 /** A hard-coded rule for serializing Node instances. */ | 481 /** A hard-coded rule for serializing Node instances. */ |
482 class NodeRule extends CustomRule { | 482 class NodeRule extends CustomRule { |
483 bool appliesTo(instance, _) => instance is Node; | 483 bool appliesTo(instance, _) => instance is Node; |
484 getState(instance) => [instance.parent, instance.name, instance.children]; | 484 getState(instance) => [instance.parent, instance.name, instance.children]; |
485 create(state) => new Node(state[1]); | 485 create(state) => new Node(state[1]); |
486 setState(Node node, state) { | 486 setState(Node node, state) { |
487 node.parent = state[0]; | 487 node.parent = state[0]; |
488 node.children = state[2]; | 488 node.children = state[2]; |
489 } | 489 } |
490 } | 490 } |
OLD | NEW |