-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.js
More file actions
129 lines (119 loc) · 2.82 KB
/
Copy pathtests.js
File metadata and controls
129 lines (119 loc) · 2.82 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const { test } = require('uvu');
const assert = require('uvu/assert');
const { parse } = require('./src/index');
test('parse Inc16 chip', () => {
const hdl = `
/**
* 16-bit incrementer:
* out = in + 1 (arithmetic addition)
*/
CHIP Inc16 {
IN in[16];
OUT out[16];
PARTS:
// Put you code here:
Add16(a[0]=true, b=in, out=out);
}`;
assert.equal(parse(hdl), {
name: 'Inc16',
definitions: [
{ type: 'IN', pins: [{ name: 'in', bits: 16 }] },
{ type: 'OUT', pins: [{ name: 'out', bits: 16 }] },
],
parts: [
{
name: 'Add16',
connections: [
{
from: { pin: 'a', bits: 0 },
to: { const: 'true' },
},
{
from: { pin: 'b', bits: null },
to: { pin: 'in', bits: null },
},
{
from: { pin: 'out', bits: null },
to: { pin: 'out', bits: null },
},
],
},
],
});
});
test('parse a chip definition with BUILTIN and CLOCKED pins', () => {
const hdl = `
CHIP Bit {
IN in, load;
OUT out;
BUILTIN Bit;
CLOCKED in, load;
}
`;
assert.equal(parse(hdl), {
name: 'Bit',
definitions: [
{
type: 'IN',
pins: [
{ name: 'in', bits: 1 },
{ name: 'load', bits: 1 },
],
},
{ type: 'OUT', pins: [{ name: 'out', bits: 1 }] },
{ type: 'BUILTIN', name: 'Bit' },
{ type: 'CLOCKED', pins: ['in', 'load'] },
],
parts: null,
});
});
test('Issue #1', () => {
const hdl = `
CHIP Or {
IN a, b;
OUT out;
PARTS:
Nand (a = nota, b=notb, out=out);
Not (in=a, out=nota);
Not (in=b, out=notb);
}
`;
assert.equal(parse(hdl), {
name: 'Or',
definitions: [
{
type: 'IN',
pins: [
{ name: 'a', bits: 1 },
{ name: 'b', bits: 1 },
],
},
{ type: 'OUT', pins: [{ name: 'out', bits: 1 }] },
],
parts: [
{
name: 'Nand',
connections: [
{ from: { pin: 'a', bits: null }, to: { pin: 'nota', bits: null } },
{ from: { pin: 'b', bits: null }, to: { pin: 'notb', bits: null } },
{ from: { pin: 'out', bits: null }, to: { pin: 'out', bits: null } },
],
},
{
name: 'Not',
connections: [
{ from: { pin: 'in', bits: null }, to: { pin: 'a', bits: null } },
{ from: { pin: 'out', bits: null }, to: { pin: 'nota', bits: null } },
],
},
{
name: 'Not',
connections: [
{ from: { pin: 'in', bits: null }, to: { pin: 'b', bits: null } },
{ from: { pin: 'out', bits: null }, to: { pin: 'notb', bits: null } },
],
},
],
});
});
test.run();