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

Side by Side Diff: pkg/analyzer/test/src/summary/flat_buffers_test.dart

Issue 1690183003: Store enums in summary file as bytes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « pkg/analyzer/lib/src/summary/format.dart ('k') | pkg/analyzer/tool/summary/generate.dart » ('j') | 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 test.src.summary.flat_buffers_test; 5 library test.src.summary.flat_buffers_test;
6 6
7 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 8
9 import 'package:analyzer/src/summary/flat_buffers.dart'; 9 import 'package:analyzer/src/summary/flat_buffers.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 { 126 {
127 Builder builder = new Builder(initialSize: 0); 127 Builder builder = new Builder(initialSize: 0);
128 Offset<String> stringOffset = builder.writeString('12345'); 128 Offset<String> stringOffset = builder.writeString('12345');
129 builder.startTable(); 129 builder.startTable();
130 builder.addBool(0, true); 130 builder.addBool(0, true);
131 builder.addInt8(1, 10); 131 builder.addInt8(1, 10);
132 builder.addInt32(2, 20); 132 builder.addInt32(2, 20);
133 builder.addOffset(3, stringOffset); 133 builder.addOffset(3, stringOffset);
134 builder.addInt32(4, 40); 134 builder.addInt32(4, 40);
135 builder.addUint32(5, 0x9ABCDEF0); 135 builder.addUint32(5, 0x9ABCDEF0);
136 builder.addUint8(6, 0x9A);
136 Offset offset = builder.endTable(); 137 Offset offset = builder.endTable();
137 byteList = builder.finish(offset); 138 byteList = builder.finish(offset);
138 } 139 }
139 // read and verify 140 // read and verify
140 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject(); 141 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject();
141 expect(const BoolReader().vTableGet(object, 0), true); 142 expect(const BoolReader().vTableGet(object, 0), true);
142 expect(const Int8Reader().vTableGet(object, 1), 10); 143 expect(const Int8Reader().vTableGet(object, 1), 10);
143 expect(const Int32Reader().vTableGet(object, 2), 20); 144 expect(const Int32Reader().vTableGet(object, 2), 20);
144 expect(const StringReader().vTableGet(object, 3), '12345'); 145 expect(const StringReader().vTableGet(object, 3), '12345');
145 expect(const Int32Reader().vTableGet(object, 4), 40); 146 expect(const Int32Reader().vTableGet(object, 4), 40);
146 expect(const Uint32Reader().vTableGet(object, 5), 0x9ABCDEF0); 147 expect(const Uint32Reader().vTableGet(object, 5), 0x9ABCDEF0);
148 expect(const Uint8Reader().vTableGet(object, 6), 0x9A);
147 } 149 }
148 150
149 void test_writeList_of_Uint32() { 151 void test_writeList_of_Uint32() {
150 List<int> values = <int>[10, 100, 12345, 0x9abcdef0]; 152 List<int> values = <int>[10, 100, 12345, 0x9abcdef0];
151 // write 153 // write
152 List<int> byteList; 154 List<int> byteList;
153 { 155 {
154 Builder builder = new Builder(initialSize: 0); 156 Builder builder = new Builder(initialSize: 0);
155 Offset offset = builder.writeListUint32(values); 157 Offset offset = builder.writeListUint32(values);
156 byteList = builder.finish(offset); 158 byteList = builder.finish(offset);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 Builder builder = new Builder(initialSize: 0); 273 Builder builder = new Builder(initialSize: 0);
272 Offset offset = builder.writeListUint32(<int>[1, 2, 0x9ABCDEF0]); 274 Offset offset = builder.writeListUint32(<int>[1, 2, 0x9ABCDEF0]);
273 byteList = builder.finish(offset); 275 byteList = builder.finish(offset);
274 } 276 }
275 // read and verify 277 // read and verify
276 BufferPointer root = new BufferPointer.fromBytes(byteList); 278 BufferPointer root = new BufferPointer.fromBytes(byteList);
277 List<int> items = const ListReader<int>(const Uint32Reader()).read(root); 279 List<int> items = const ListReader<int>(const Uint32Reader()).read(root);
278 expect(items, hasLength(3)); 280 expect(items, hasLength(3));
279 expect(items, orderedEquals(<int>[1, 2, 0x9ABCDEF0])); 281 expect(items, orderedEquals(<int>[1, 2, 0x9ABCDEF0]));
280 } 282 }
283
284 void test_writeList_ofUint8() {
285 List<int> byteList;
286 {
287 Builder builder = new Builder(initialSize: 0);
288 Offset offset = builder.writeListUint8(<int>[1, 2, 0x9A]);
289 byteList = builder.finish(offset);
290 }
291 // read and verify
292 BufferPointer root = new BufferPointer.fromBytes(byteList);
293 List<int> items = const ListReader<int>(const Uint8Reader()).read(root);
294 expect(items, hasLength(3));
295 expect(items, orderedEquals(<int>[1, 2, 0x9A]));
296 }
281 } 297 }
282 298
283 class StringListWrapperImpl { 299 class StringListWrapperImpl {
284 final BufferPointer bp; 300 final BufferPointer bp;
285 301
286 StringListWrapperImpl(this.bp); 302 StringListWrapperImpl(this.bp);
287 303
288 List<String> get items => 304 List<String> get items =>
289 const ListReader<String>(const StringReader()).vTableGet(bp, 0); 305 const ListReader<String>(const StringReader()).vTableGet(bp, 0);
290 } 306 }
(...skipping 18 matching lines...) Expand all
309 } 325 }
310 326
311 class TestPointReader extends TableReader<TestPointImpl> { 327 class TestPointReader extends TableReader<TestPointImpl> {
312 const TestPointReader(); 328 const TestPointReader();
313 329
314 @override 330 @override
315 TestPointImpl createObject(BufferPointer object) { 331 TestPointImpl createObject(BufferPointer object) {
316 return new TestPointImpl(object); 332 return new TestPointImpl(object);
317 } 333 }
318 } 334 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/format.dart ('k') | pkg/analyzer/tool/summary/generate.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698