| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.vlq_test; | 5 library test.vlq_test; |
| 6 | 6 |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:test/test.dart'; |
| 9 import 'package:source_maps/src/vlq.dart'; | 9 import 'package:source_maps/src/vlq.dart'; |
| 10 | 10 |
| 11 main() { | 11 main() { |
| 12 test('encode and decode - simple values', () { | 12 test('encode and decode - simple values', () { |
| 13 expect(encodeVlq(1).join(''), 'C'); | 13 expect(encodeVlq(1).join(''), 'C'); |
| 14 expect(encodeVlq(2).join(''), 'E'); | 14 expect(encodeVlq(2).join(''), 'E'); |
| 15 expect(encodeVlq(3).join(''), 'G'); | 15 expect(encodeVlq(3).join(''), 'G'); |
| 16 expect(encodeVlq(100).join(''), 'oG'); | 16 expect(encodeVlq(100).join(''), 'oG'); |
| 17 expect(decodeVlq('C'.split('').iterator), 1); | 17 expect(decodeVlq('C'.split('').iterator), 1); |
| 18 expect(decodeVlq('E'.split('').iterator), 2); | 18 expect(decodeVlq('E'.split('').iterator), 2); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 42 expect(() => encodeVlq(min_int - 1), throws); | 42 expect(() => encodeVlq(min_int - 1), throws); |
| 43 expect(() => encodeVlq(min_int - 2), throws); | 43 expect(() => encodeVlq(min_int - 2), throws); |
| 44 | 44 |
| 45 | 45 |
| 46 // if we allowed more than 32 bits, these would be the expected encodings | 46 // if we allowed more than 32 bits, these would be the expected encodings |
| 47 // for the large numbers above. | 47 // for the large numbers above. |
| 48 expect(() => decodeVlq('ggggggE'.split('').iterator), throws); | 48 expect(() => decodeVlq('ggggggE'.split('').iterator), throws); |
| 49 expect(() => decodeVlq('igggggE'.split('').iterator), throws); | 49 expect(() => decodeVlq('igggggE'.split('').iterator), throws); |
| 50 expect(() => decodeVlq('jgggggE'.split('').iterator), throws); | 50 expect(() => decodeVlq('jgggggE'.split('').iterator), throws); |
| 51 expect(() => decodeVlq('lgggggE'.split('').iterator), throws); | 51 expect(() => decodeVlq('lgggggE'.split('').iterator), throws); |
| 52 }); | 52 }, |
| 53 // This test uses integers so large they overflow in JS. |
| 54 testOn: "dart-vm"); |
| 53 } | 55 } |
| 54 | 56 |
| 55 _checkEncodeDecode(int value) { | 57 _checkEncodeDecode(int value) { |
| 56 var encoded = encodeVlq(value); | 58 var encoded = encodeVlq(value); |
| 57 expect(decodeVlq(encoded.iterator), value); | 59 expect(decodeVlq(encoded.iterator), value); |
| 58 expect(decodeVlq(encoded.join('').split('').iterator), value); | 60 expect(decodeVlq(encoded.join('').split('').iterator), value); |
| 59 } | 61 } |
| OLD | NEW |