-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvlq.test.ts
More file actions
70 lines (53 loc) · 2.41 KB
/
vlq.test.ts
File metadata and controls
70 lines (53 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2025 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { describe, it } from "@std/testing/bdd";
import { TokenIterator } from "./vlq.ts";
import { assertFalse, assertStrictEquals } from "@std/assert";
describe("TokenIterator", () => {
describe("nextUnsignedVLQ", () => {
it("handles multi-digit numbers", () => {
const iter = new TokenIterator("hB");
assertStrictEquals(iter.nextUnsignedVLQ(), 33);
assertFalse(iter.hasNext());
});
it("returns zero when no more characters are available", () => {
const iter = new TokenIterator("");
assertFalse(iter.hasNext());
assertStrictEquals(iter.nextUnsignedVLQ(), 0);
});
it("treats unknown characters as 0", () => {
const iter = new TokenIterator("h,C"); // 'h' has the continuation bit set. ',' is treated as 0 so we stop decoding.
assertStrictEquals(iter.nextUnsignedVLQ(), 1);
assertStrictEquals(iter.peek(), "C");
});
it("treats unknown unicode characters as 0", () => {
const iter = new TokenIterator("hæC"); // 'h' has the continuation bit set. 'æ' falls outside the array so has 'undefined as its digit value.
assertStrictEquals(iter.nextUnsignedVLQ(), 1);
assertStrictEquals(iter.peek(), "C");
});
});
describe("nextSignedVLQ", () => {
it("returns zero when no more characters are available", () => {
const iter = new TokenIterator("");
assertFalse(iter.hasNext());
assertStrictEquals(iter.nextSignedVLQ(), 0);
});
it("treats unknown characters as 0", () => {
const iter = new TokenIterator("i,C"); // 'i' has the continuation bit set. ',' is treated as 0 so we stop decoding.
assertStrictEquals(iter.nextSignedVLQ(), 1);
assertStrictEquals(iter.peek(), "C");
});
it("treats unknown unicode characters as 0", () => {
const iter = new TokenIterator("iæC"); // 'i' has the continuation bit set. 'æ' falls outside the array so has 'undefined as its digit value.
assertStrictEquals(iter.nextSignedVLQ(), 1);
assertStrictEquals(iter.peek(), "C");
});
});
describe("current", () => {
it("returns the empty string when calling it without advancing the iterator", () => {
const iter = new TokenIterator("CCCC");
assertStrictEquals(iter.currentChar(), "");
});
});
});