Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: pkg/serialization/test/serialization_test.dart

Issue 13982012: Update pkg/serialization to use Symbols and synchronous mirrors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/serialization/lib/src/serialization_rule.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 test('Stream', () { 117 test('Stream', () {
118 // This is an interesting case. The Stream doesn't expose its internal 118 // This is an interesting case. The Stream doesn't expose its internal
119 // collection at all, and sets it in the constructor. So to get it we 119 // collection at all, and sets it in the constructor. So to get it we
120 // read a private field and then set that via the constructor. That works 120 // read a private field and then set that via the constructor. That works
121 // but should we have some kind of large red flag that you're using private 121 // but should we have some kind of large red flag that you're using private
122 // state. 122 // state.
123 var stream = new Stream([3,4,5]); 123 var stream = new Stream([3,4,5]);
124 expect((stream..next()).next(), 4); 124 expect((stream..next()).next(), 4);
125 expect(stream.position, 2); 125 expect(stream.position, 2);
126 // The Symbol class does not allow us to create symbols for private
127 // variables. However, the mirror system uses them. So we get the symbol
128 // we want from the mirror.
129 // TODO(alanknight): Either delete this test and decide we shouldn't
130 // attempt to access private variables or fix this properly.
131 var _collectionSym = reflect(stream).type.variables.keys.firstWhere(
132 (x) => MirrorSystem.getName(x) == "_collection");
126 var s = new Serialization() 133 var s = new Serialization()
127 ..addRuleFor(stream, 134 ..addRuleFor(stream,
128 constructorFields: ['_collection']); 135 constructorFields: [_collectionSym]);
129 var state = states(stream, s).first; 136 var state = states(stream, s).first;
130 // Define names for the variable offsets to make this more readable. 137 // Define names for the variable offsets to make this more readable.
131 var _collection = 0, position = 1; 138 var _collection = 0, position = 1;
132 expect(state[_collection],[3,4,5]); 139 expect(state[_collection],[3,4,5]);
133 expect(state[position], 2); 140 expect(state[position], 2);
134 }); 141 });
135 142
136 test('date', () { 143 test('date', () {
137 var date = new DateTime.now(); 144 var date = new DateTime.now();
138 var s = new Serialization() 145 var s = new Serialization()
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 expect(all.contains(n2), isTrue); 211 expect(all.contains(n2), isTrue);
205 expect(all.contains(n3), isTrue); 212 expect(all.contains(n3), isTrue);
206 expect(all.contains(n1.children), isTrue); 213 expect(all.contains(n1.children), isTrue);
207 }); 214 });
208 215
209 test('Flatten references in a cyclical structure', () { 216 test('Flatten references in a cyclical structure', () {
210 var s = new Serialization(); 217 var s = new Serialization();
211 var w = new Writer(s); 218 var w = new Writer(s);
212 w.trace = new Trace(w); 219 w.trace = new Trace(w);
213 w.write(n1); 220 w.write(n1);
214 expect(w.states.length, 5); // prims, lists, essential lists, basic 221 expect(w.states.length, 6); // prims, lists, essential lists, basic, symbol
215 var children = 0, name = 1, parent = 2; 222 var children = 0, name = 1, parent = 2;
216 var nodeRule = s.rules.firstWhere((x) => x is BasicRule); 223 var nodeRule = s.rules.firstWhere((x) => x is BasicRule);
217 List rootNode = w.states[nodeRule.number].where( 224 List rootNode = w.states[nodeRule.number].where(
218 (x) => x[name] == "1").toList(); 225 (x) => x[name] == "1").toList();
219 rootNode = rootNode.first; 226 rootNode = rootNode.first;
220 expect(rootNode[parent], isNull); 227 expect(rootNode[parent], isNull);
221 var list = w.states[1].first; 228 var list = w.states[1].first;
222 expect(w.stateForReference(rootNode[children]), list); 229 expect(w.stateForReference(rootNode[children]), list);
223 var parentNode = w.stateForReference(list[0])[parent]; 230 var parentNode = w.stateForReference(list[0])[parent];
224 expect(w.stateForReference(parentNode), rootNode); 231 expect(w.stateForReference(parentNode), rootNode);
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 } 746 }
740 findValue(String key, Map state) { 747 findValue(String key, Map state) {
741 var answer; 748 var answer;
742 for (var each in state.keys) { 749 for (var each in state.keys) {
743 var value = state[each]; 750 var value = state[each];
744 if (value == key) return each; 751 if (value == key) return each;
745 } 752 }
746 return null; 753 return null;
747 } 754 }
748 } 755 }
OLDNEW
« no previous file with comments | « pkg/serialization/lib/src/serialization_rule.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698