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

Side by Side Diff: pkg/source_maps/test/vlq_test.dart

Issue 12207008: Move source maps package to the dart repo, so it can be used by other internal (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updates Created 7 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 | Annotate | Revision Log
« no previous file with comments | « pkg/source_maps/test/utils_test.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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.vlq_test;
6
7 import 'dart:math';
8 import 'package:unittest/unittest.dart';
9 import 'package:source_maps/src/vlq.dart';
10
11 main() {
12 test('encode and decode - simple values', () {
13 expect(encodeVlq(1).join(''), 'C');
14 expect(encodeVlq(2).join(''), 'E');
15 expect(encodeVlq(3).join(''), 'G');
16 expect(encodeVlq(100).join(''), 'oG');
17 expect(decodeVlq('C'.split('').iterator), 1);
18 expect(decodeVlq('E'.split('').iterator), 2);
19 expect(decodeVlq('G'.split('').iterator), 3);
20 expect(decodeVlq('oG'.split('').iterator), 100);
21 });
22
23 test('encode and decode', () {
24 for (int i = -10000; i < 10000; i++) {
25 _checkEncodeDecode(i);
26 }
27 });
28
29 test('only 32-bit ints allowed', () {
30 var max_int = pow(2, 31) - 1;
31 var min_int = -pow(2, 31);
32 _checkEncodeDecode(max_int - 1);
33 _checkEncodeDecode(min_int + 1);
34 _checkEncodeDecode(max_int);
35 _checkEncodeDecode(min_int);
36
37 expect(encodeVlq(min_int).join(''), 'hgggggE');
38 expect(decodeVlq('hgggggE'.split('').iterator), min_int);
39
40 expect(() => encodeVlq(max_int + 1), throws);
41 expect(() => encodeVlq(max_int + 2), throws);
42 expect(() => encodeVlq(min_int - 1), throws);
43 expect(() => encodeVlq(min_int - 2), throws);
44
45
46 // if we allowed more than 32 bits, these would be the expected encodings
47 // for the large numbers above.
48 expect(() => decodeVlq('ggggggE'.split('').iterator), throws);
49 expect(() => decodeVlq('igggggE'.split('').iterator), throws);
50 expect(() => decodeVlq('jgggggE'.split('').iterator), throws);
51 expect(() => decodeVlq('lgggggE'.split('').iterator), throws);
52 });
53 }
54
55 _checkEncodeDecode(int value) {
56 var encoded = encodeVlq(value);
57 expect(decodeVlq(encoded.iterator), value);
58 expect(decodeVlq(encoded.join('').split('').iterator), value);
59 }
OLDNEW
« no previous file with comments | « pkg/source_maps/test/utils_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698