| OLD | NEW |
| 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 'package:analyzer/src/summary/flat_buffers.dart'; | 7 import 'package:analyzer/src/summary/flat_buffers.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 | 9 |
| 10 import '../../reflective_tests.dart'; | 10 import '../../reflective_tests.dart'; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 // read and verify | 103 // read and verify |
| 104 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject(); | 104 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject(); |
| 105 expect(const BoolReader().vTableGet(object, 0), true); | 105 expect(const BoolReader().vTableGet(object, 0), true); |
| 106 expect(const Int8Reader().vTableGet(object, 1), 10); | 106 expect(const Int8Reader().vTableGet(object, 1), 10); |
| 107 expect(const Int32Reader().vTableGet(object, 2), 20); | 107 expect(const Int32Reader().vTableGet(object, 2), 20); |
| 108 expect(const StringReader().vTableGet(object, 3), '12345'); | 108 expect(const StringReader().vTableGet(object, 3), '12345'); |
| 109 expect(const Int32Reader().vTableGet(object, 4), 40); | 109 expect(const Int32Reader().vTableGet(object, 4), 40); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void test_writeList_ofFloat64() { |
| 113 List<double> values = <double>[-1.234567, 3.4E+9, -5.6E-13, 7.8, 12.13]; |
| 114 // write |
| 115 List<int> byteList; |
| 116 { |
| 117 Builder builder = new Builder(initialSize: 0); |
| 118 Offset offset = builder.writeListFloat64(values); |
| 119 byteList = builder.finish(offset); |
| 120 } |
| 121 // read and verify |
| 122 BufferPointer root = new BufferPointer.fromBytes(byteList); |
| 123 List<double> items = const Float64ListReader().read(root); |
| 124 expect(items, hasLength(5)); |
| 125 expect(items, orderedEquals(values)); |
| 126 } |
| 127 |
| 112 void test_writeList_ofInt32() { | 128 void test_writeList_ofInt32() { |
| 113 List<int> byteList; | 129 List<int> byteList; |
| 114 { | 130 { |
| 115 Builder builder = new Builder(initialSize: 0); | 131 Builder builder = new Builder(initialSize: 0); |
| 116 Offset offset = builder.writeListInt32(<int>[1, 2, 3, 4, 5]); | 132 Offset offset = builder.writeListInt32(<int>[1, 2, 3, 4, 5]); |
| 117 byteList = builder.finish(offset); | 133 byteList = builder.finish(offset); |
| 118 } | 134 } |
| 119 // read and verify | 135 // read and verify |
| 120 BufferPointer root = new BufferPointer.fromBytes(byteList); | 136 BufferPointer root = new BufferPointer.fromBytes(byteList); |
| 121 List<int> items = const ListReader<int>(const Int32Reader()).read(root); | 137 List<int> items = const ListReader<int>(const Int32Reader()).read(root); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 242 } |
| 227 | 243 |
| 228 class TestPointReader extends TableReader<TestPointImpl> { | 244 class TestPointReader extends TableReader<TestPointImpl> { |
| 229 const TestPointReader(); | 245 const TestPointReader(); |
| 230 | 246 |
| 231 @override | 247 @override |
| 232 TestPointImpl createObject(BufferPointer object) { | 248 TestPointImpl createObject(BufferPointer object) { |
| 233 return new TestPointImpl(object); | 249 return new TestPointImpl(object); |
| 234 } | 250 } |
| 235 } | 251 } |
| OLD | NEW |