-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathshift-checker.test.ts
More file actions
81 lines (57 loc) · 2.01 KB
/
Copy pathshift-checker.test.ts
File metadata and controls
81 lines (57 loc) · 2.01 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
71
72
73
74
75
76
77
78
79
80
81
import { beforeEach, describe, it, TestContext } from 'node:test';
import { Builder, ShiftChecker } from '../src/builder';
describe ('LLParse/ShiftChecker', () => {
let b: Builder;
let sc: ShiftChecker;
beforeEach(() => {
b = new Builder();
});
it('should prohibit undefined properties', (t: TestContext) => {
const lshift = b.lshift("undefined", 1);
const start = b.node('start');
start
.otherwise(lshift);
lshift.skipTo(start);
sc = new ShiftChecker(b.properties);
t.assert.throws(() => {
sc.check(start);
}, /has not been defined for.*undefined/)
});
it('should detect overflowing bits', (t: TestContext) => {
const rshift = b.rshift("defined", 8);
const start = b.node('start');
b.property('i8', "defined");
start
.otherwise(rshift);
rshift.skipTo(start);
sc = new ShiftChecker(b.properties);
t.assert.throws(() => {
sc.check(start);
}, /and will cause node .* to overflow./);
});
it('should detect inapproperate types', (t: TestContext) => {
const rshift = b.rshift("defined", 8);
const start = b.node('start');
b.property('ptr', "defined");
start
.otherwise(rshift);
rshift.skipTo(start);
sc = new ShiftChecker(b.properties);
t.assert.throws(() => {
sc.check(start);
}, /defined cannot be provided to ".*" because field was defined as a "ptr"/);
});
it('should allow types that are smaller than itself', (t: TestContext) => {
const rshift = b.rshift("defined", 2);
const start = b.node('start');
/* hypothetically let's say we have an uint32_t in C but we only
need to pack a i16 bit integer, this is valid use-case because we can safely
pack it even if the property is bigger than itself. */
b.property('i32', "defined");
start
.otherwise(rshift);
rshift.skipTo(start);
sc = new ShiftChecker(b.properties);
t.assert.doesNotThrow(() => sc.check(start));
});
})