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

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

Issue 1747663002: Support for boolean lists in FlatBuffer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Rewrite using Uint8List and padding. Created 4 years, 9 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
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 Offset offset = builder.writeListUint32(values); 185 Offset offset = builder.writeListUint32(values);
186 byteList = builder.finish(offset); 186 byteList = builder.finish(offset);
187 } 187 }
188 // read and verify 188 // read and verify
189 BufferPointer root = new BufferPointer.fromBytes(byteList); 189 BufferPointer root = new BufferPointer.fromBytes(byteList);
190 List<int> items = const Uint32ListReader().read(root); 190 List<int> items = const Uint32ListReader().read(root);
191 expect(items, hasLength(4)); 191 expect(items, hasLength(4));
192 expect(items, orderedEquals(values)); 192 expect(items, orderedEquals(values));
193 } 193 }
194 194
195 void test_writeList_ofBool() {
196 void verifyListBooleans(int len, List<int> trueBits) {
197 // write
198 List<int> byteList;
199 {
200 Builder builder = new Builder(initialSize: 0);
201 List<bool> values = new List<bool>.filled(len, false);
202 for (int bit in trueBits) {
203 values[bit] = true;
204 }
205 Offset offset = builder.writeListBool(values);
206 byteList = builder.finish(offset);
207 }
208 // read and verify
209 BufferPointer root = new BufferPointer.fromBytes(byteList);
210 List<bool> items = const BoolListReader().read(root);
211 expect(items, hasLength(len));
212 for (int i = 0; i < items.length; i++) {
213 expect(items[i], trueBits.contains(i), reason: 'bit $i of $len');
214 }
215 }
216 verifyListBooleans(0, <int>[]);
217 verifyListBooleans(1, <int>[]);
218 verifyListBooleans(1, <int>[0]);
219 verifyListBooleans(31, <int>[0, 1]);
220 verifyListBooleans(31, <int>[1, 2, 24, 25, 30]);
221 verifyListBooleans(31, <int>[0, 30]);
222 verifyListBooleans(32, <int>[1, 2, 24, 25, 31]);
223 verifyListBooleans(33, <int>[1, 2, 24, 25, 32]);
224 verifyListBooleans(33, <int>[1, 2, 24, 25, 31, 32]);
225 verifyListBooleans(63, <int>[]);
226 verifyListBooleans(63, <int>[0, 1, 2, 61, 62]);
227 verifyListBooleans(63, new List<int>.generate(63, (i) => i));
228 verifyListBooleans(64, <int>[]);
229 verifyListBooleans(64, <int>[0, 1, 2, 61, 62, 63]);
230 verifyListBooleans(64, <int>[1, 2, 62]);
231 verifyListBooleans(64, <int>[0, 1, 2, 63]);
232 verifyListBooleans(64, new List<int>.generate(64, (i) => i));
233 verifyListBooleans(100, <int>[0, 3, 30, 60, 90, 99]);
234 }
235
195 void test_writeList_ofFloat64() { 236 void test_writeList_ofFloat64() {
196 List<double> values = <double>[-1.234567, 3.4E+9, -5.6E-13, 7.8, 12.13]; 237 List<double> values = <double>[-1.234567, 3.4E+9, -5.6E-13, 7.8, 12.13];
197 // write 238 // write
198 List<int> byteList; 239 List<int> byteList;
199 { 240 {
200 Builder builder = new Builder(initialSize: 0); 241 Builder builder = new Builder(initialSize: 0);
201 Offset offset = builder.writeListFloat64(values); 242 Offset offset = builder.writeListFloat64(values);
202 byteList = builder.finish(offset); 243 byteList = builder.finish(offset);
203 } 244 }
204 // read and verify 245 // read and verify
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 394 }
354 395
355 class TestPointReader extends TableReader<TestPointImpl> { 396 class TestPointReader extends TableReader<TestPointImpl> {
356 const TestPointReader(); 397 const TestPointReader();
357 398
358 @override 399 @override
359 TestPointImpl createObject(BufferPointer object) { 400 TestPointImpl createObject(BufferPointer object) {
360 return new TestPointImpl(object); 401 return new TestPointImpl(object);
361 } 402 }
362 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698