| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 Node n1 = new Node("1"), n2 = new Node("2"), n3 = new Node("3"); | 185 Node n1 = new Node("1"), n2 = new Node("2"), n3 = new Node("3"); |
| 186 n1.children = [n2, n3]; | 186 n1.children = [n2, n3]; |
| 187 n2.parent = n1; | 187 n2.parent = n1; |
| 188 n3.parent = n1; | 188 n3.parent = n1; |
| 189 | 189 |
| 190 test('Trace a cyclical structure', () { | 190 test('Trace a cyclical structure', () { |
| 191 var s = new Serialization(); | 191 var s = new Serialization(); |
| 192 var trace = new Trace(new Writer(s)); | 192 var trace = new Trace(new Writer(s)); |
| 193 trace.writer.trace = trace; | 193 trace.writer.trace = trace; |
| 194 trace.trace(n1); | 194 trace.trace(n1); |
| 195 var all = trace.writer.references.keys; | 195 var all = trace.writer.references.keys.toSet(); |
| 196 expect(all.length, 4); | 196 expect(all.length, 4); |
| 197 expect(all.contains(n1), isTrue); | 197 expect(all.contains(n1), isTrue); |
| 198 expect(all.contains(n2), isTrue); | 198 expect(all.contains(n2), isTrue); |
| 199 expect(all.contains(n3), isTrue); | 199 expect(all.contains(n3), isTrue); |
| 200 expect(all.contains(n1.children), isTrue); | 200 expect(all.contains(n1.children), isTrue); |
| 201 }); | 201 }); |
| 202 | 202 |
| 203 test('Flatten references in a cyclical structure', () { | 203 test('Flatten references in a cyclical structure', () { |
| 204 var s = new Serialization(); | 204 var s = new Serialization(); |
| 205 var w = new Writer(s); | 205 var w = new Writer(s); |
| (...skipping 275 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 |