-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.test.js
75 lines (62 loc) · 1010 Bytes
/
compiler.test.js
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
const { hex, b } = require('./opcode.js');
const { parse, compile } = require('./compiler.js');
describe('parse', () => {
it('should be defined', () => {
expect(parse).toBeTruthy();
});
it('should works', () => {
expect(
parse(`
LDA 14
ADD 15
JC 5
OUT 0
JMP 1
SUB 15
JZ 1
OUT 0
JMP 5
0
55
`)
).toEqual([
/* 0 */ ['LDA', 14],
/* 1 */ ['ADD', 15],
/* 2 */ ['JC', 5],
/* 3 */ ['OUT', 0],
/* 4 */ ['JMP', 1],
/* 5 */ ['SUB', 15],
/* 6 */ ['JZ', 1],
/* 7 */ ['OUT', 0],
/* 8 */ ['JMP', 5],
/* 9 */ [],
/* 10 */ [],
/* 11 */ [],
/* 12 */ [],
/* 13 */ [],
/* 14 */ [0],
/* 15 */ [55],
]);
});
});
describe('compile', () => {
it('should works', () => {
expect(
compile(`
LDA 14
ADD 15
JC 5
OUT 0
JMP 1
SUB 15
JZ 1
OUT 0
JMP 5
0
255
`)
.map(_ => hex(_))
.join(' ')
).toEqual('e 1f 55 20 41 7f 61 20 45 0 0 0 0 0 0 ff');
});
});