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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/source_maps/test/utils_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/source_maps/test/vlq_test.dart
diff --git a/pkg/source_maps/test/vlq_test.dart b/pkg/source_maps/test/vlq_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0abdc4795c2d99b70736f2994b7ff45dc926e5a5
--- /dev/null
+++ b/pkg/source_maps/test/vlq_test.dart
@@ -0,0 +1,59 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library test.vlq_test;
+
+import 'dart:math';
+import 'package:unittest/unittest.dart';
+import 'package:source_maps/src/vlq.dart';
+
+main() {
+ test('encode and decode - simple values', () {
+ expect(encodeVlq(1).join(''), 'C');
+ expect(encodeVlq(2).join(''), 'E');
+ expect(encodeVlq(3).join(''), 'G');
+ expect(encodeVlq(100).join(''), 'oG');
+ expect(decodeVlq('C'.split('').iterator), 1);
+ expect(decodeVlq('E'.split('').iterator), 2);
+ expect(decodeVlq('G'.split('').iterator), 3);
+ expect(decodeVlq('oG'.split('').iterator), 100);
+ });
+
+ test('encode and decode', () {
+ for (int i = -10000; i < 10000; i++) {
+ _checkEncodeDecode(i);
+ }
+ });
+
+ test('only 32-bit ints allowed', () {
+ var max_int = pow(2, 31) - 1;
+ var min_int = -pow(2, 31);
+ _checkEncodeDecode(max_int - 1);
+ _checkEncodeDecode(min_int + 1);
+ _checkEncodeDecode(max_int);
+ _checkEncodeDecode(min_int);
+
+ expect(encodeVlq(min_int).join(''), 'hgggggE');
+ expect(decodeVlq('hgggggE'.split('').iterator), min_int);
+
+ expect(() => encodeVlq(max_int + 1), throws);
+ expect(() => encodeVlq(max_int + 2), throws);
+ expect(() => encodeVlq(min_int - 1), throws);
+ expect(() => encodeVlq(min_int - 2), throws);
+
+
+ // if we allowed more than 32 bits, these would be the expected encodings
+ // for the large numbers above.
+ expect(() => decodeVlq('ggggggE'.split('').iterator), throws);
+ expect(() => decodeVlq('igggggE'.split('').iterator), throws);
+ expect(() => decodeVlq('jgggggE'.split('').iterator), throws);
+ expect(() => decodeVlq('lgggggE'.split('').iterator), throws);
+ });
+}
+
+_checkEncodeDecode(int value) {
+ var encoded = encodeVlq(value);
+ expect(decodeVlq(encoded.iterator), value);
+ expect(decodeVlq(encoded.join('').split('').iterator), value);
+}
« 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