Skip to content

Commit 1d6bb81

Browse files
committed
Split up keyword elaboration tests
1 parent ca01362 commit 1d6bb81

File tree

9 files changed

+609
-587
lines changed

9 files changed

+609
-587
lines changed

src/language/compiling/semantics.test.ts

Lines changed: 2 additions & 587 deletions
Large diffs are not rendered by default.
Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
import either from '@matt.kantor/either'
2+
import assert from 'node:assert'
3+
import { elaborationSuite, success } from '../test-utilities.test.js'
4+
5+
elaborationSuite('@apply', [
6+
[{ 0: '@apply', 1: { 0: '@lookup', key: 'identity' }, 2: 'a' }, success('a')],
7+
[
8+
{
9+
0: '@apply',
10+
function: { 0: '@lookup', key: 'identity' },
11+
argument: 'a',
12+
},
13+
success('a'),
14+
],
15+
[
16+
{
17+
0: '@apply',
18+
function: { 0: '@lookup', key: 'identity' },
19+
argument: { foo: 'bar' },
20+
},
21+
success({ foo: 'bar' }),
22+
],
23+
[
24+
{ 0: '@apply', function: 'not a function', argument: 'a' },
25+
output => assert(either.isLeft(output)),
26+
],
27+
[
28+
{
29+
0: '@apply',
30+
function: { 0: '@function', 1: 'x', 2: { 0: '@lookup', 1: 'x' } },
31+
argument: 'identity is identical',
32+
},
33+
success('identity is identical'),
34+
],
35+
[
36+
{
37+
0: '@apply',
38+
function: {
39+
0: '@function',
40+
parameter: 'a',
41+
body: {
42+
0: '@apply',
43+
function: {
44+
0: '@function',
45+
parameter: 'b',
46+
body: {
47+
A: { 0: '@lookup', key: 'a' },
48+
B: { 0: '@lookup', key: 'b' },
49+
},
50+
},
51+
argument: 'b',
52+
},
53+
},
54+
argument: 'a',
55+
},
56+
success({ A: 'a', B: 'b' }),
57+
],
58+
[
59+
{
60+
0: '@apply',
61+
function: {
62+
0: '@function',
63+
1: 'x',
64+
2: {
65+
0: '@apply',
66+
function: {
67+
0: '@index',
68+
1: { 0: '@lookup', 1: 'boolean' },
69+
2: { 0: 'not' },
70+
},
71+
argument: { 0: '@lookup', 1: 'x' },
72+
},
73+
},
74+
argument: 'false',
75+
},
76+
success('true'),
77+
],
78+
[
79+
{
80+
0: '@apply',
81+
function: {
82+
0: '@function',
83+
1: 'x',
84+
2: {
85+
0: '@index',
86+
1: { 0: '@lookup', 1: 'x' },
87+
2: { 0: 'a' },
88+
},
89+
},
90+
argument: { a: 'it works' },
91+
},
92+
success('it works'),
93+
],
94+
[
95+
// {
96+
// a: "a"
97+
// b: (a => {
98+
// a: "b"
99+
// b: (a => :a)("it works")
100+
// })("unused")
101+
// }
102+
{
103+
a: 'a',
104+
b: {
105+
0: '@apply',
106+
function: {
107+
0: '@function',
108+
parameter: 'a',
109+
body: {
110+
a: 'b',
111+
b: {
112+
0: '@apply',
113+
function: {
114+
0: '@function',
115+
parameter: 'a',
116+
body: {
117+
0: '@lookup',
118+
key: 'a',
119+
},
120+
},
121+
argument: 'it works',
122+
},
123+
},
124+
},
125+
argument: 'unused',
126+
},
127+
},
128+
success({
129+
a: 'a',
130+
b: {
131+
a: 'b',
132+
b: 'it works',
133+
},
134+
}),
135+
],
136+
[
137+
// {
138+
// a: "a"
139+
// b: (a => {
140+
// a: "it works"
141+
// b: (a => :a)(:a)
142+
// })("unused")
143+
// }
144+
{
145+
a: 'a',
146+
b: {
147+
0: '@apply',
148+
function: {
149+
0: '@function',
150+
parameter: 'a',
151+
body: {
152+
a: 'it works',
153+
b: {
154+
0: '@apply',
155+
function: {
156+
0: '@function',
157+
parameter: 'a',
158+
body: { 0: '@lookup', key: 'a' },
159+
},
160+
argument: { 0: '@lookup', key: 'a' },
161+
},
162+
},
163+
},
164+
argument: 'unused',
165+
},
166+
},
167+
success({
168+
a: 'a',
169+
b: {
170+
a: 'it works',
171+
b: 'it works',
172+
},
173+
}),
174+
],
175+
[
176+
// {
177+
// a:"it works"
178+
// b: (a => {
179+
// b: (a => :a)(:a)
180+
// })(:a)
181+
// }
182+
{
183+
a: 'it works',
184+
b: {
185+
0: '@apply',
186+
function: {
187+
0: '@function',
188+
parameter: 'a',
189+
body: {
190+
b: {
191+
0: '@apply',
192+
function: {
193+
0: '@function',
194+
parameter: 'a',
195+
body: { 0: '@lookup', key: 'a' },
196+
},
197+
argument: { 0: '@lookup', key: 'a' },
198+
},
199+
},
200+
},
201+
argument: { 0: '@lookup', key: 'a' },
202+
},
203+
},
204+
success({
205+
a: 'it works',
206+
b: {
207+
b: 'it works',
208+
},
209+
}),
210+
],
211+
[
212+
// {
213+
// a: "a"
214+
// b: (a => {
215+
// a: "it works"
216+
// b: (b => :a)("unused")
217+
// })("unused")
218+
// }
219+
{
220+
a: 'a',
221+
b: {
222+
0: '@apply',
223+
function: {
224+
0: '@function',
225+
parameter: 'a',
226+
body: {
227+
a: 'it works',
228+
b: {
229+
0: '@apply',
230+
function: {
231+
0: '@function',
232+
parameter: 'b',
233+
body: { 0: '@lookup', key: 'a' },
234+
},
235+
argument: 'unused',
236+
},
237+
},
238+
},
239+
argument: 'unused',
240+
},
241+
},
242+
success({
243+
a: 'a',
244+
b: {
245+
a: 'it works',
246+
b: 'it works',
247+
},
248+
}),
249+
],
250+
[
251+
// {
252+
// a: "it works"
253+
// b: (b => {
254+
// b: "b"
255+
// c: (b => :a)("unused")
256+
// })("unused")
257+
// }
258+
{
259+
a: 'it works',
260+
b: {
261+
0: '@apply',
262+
function: {
263+
0: '@function',
264+
parameter: 'b',
265+
body: {
266+
b: 'b',
267+
c: {
268+
0: '@apply',
269+
function: {
270+
0: '@function',
271+
parameter: 'b',
272+
body: { 0: '@lookup', key: 'a' },
273+
},
274+
argument: 'unused',
275+
},
276+
},
277+
},
278+
argument: 'unused',
279+
},
280+
},
281+
success({
282+
a: 'it works',
283+
b: {
284+
b: 'b',
285+
c: 'it works',
286+
},
287+
}),
288+
],
289+
])
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import either from '@matt.kantor/either'
2+
import assert from 'node:assert'
3+
import { elaborationSuite, success } from '../test-utilities.test.js'
4+
5+
elaborationSuite('@check', [
6+
[{ 0: '@check', 1: 'a', 2: 'a' }, success('a')],
7+
[{ 0: '@check', type: 'a', value: 'a' }, success('a')],
8+
[{ 0: '@check', type: '', value: '' }, success('')],
9+
[{ 0: '@check', type: '@@a', value: '@@a' }, success('@a')],
10+
[{ 0: '@check', 1: 'a', 2: 'B' }, output => assert(either.isLeft(output))],
11+
[
12+
{ 0: '@check', type: 'a', value: 'B' },
13+
output => assert(either.isLeft(output)),
14+
],
15+
[
16+
{ 0: '@check', type: 'a', value: {} },
17+
output => assert(either.isLeft(output)),
18+
],
19+
[
20+
{ 0: '@check', type: {}, value: 'a' },
21+
output => assert(either.isLeft(output)),
22+
],
23+
[
24+
{
25+
0: '@check',
26+
type: { a: 'b' },
27+
value: { a: 'not b' },
28+
},
29+
output => assert(either.isLeft(output)),
30+
],
31+
[
32+
{
33+
0: '@check',
34+
type: { something: { more: 'complicated' } },
35+
value: { something: { more: 'complicated' } },
36+
},
37+
success({ something: { more: 'complicated' } }),
38+
],
39+
[
40+
{
41+
0: '@check',
42+
type: { something: { more: 'complicated' } },
43+
value: {
44+
something: { more: 'complicated, which also does not typecheck' },
45+
},
46+
},
47+
output => assert(either.isLeft(output)),
48+
],
49+
[
50+
{
51+
0: '@check',
52+
type: { a: 'b' },
53+
value: {},
54+
},
55+
output => assert(either.isLeft(output)),
56+
],
57+
[
58+
{
59+
0: '@check',
60+
type: { a: { b: 'c' } },
61+
value: { a: {} },
62+
},
63+
output => assert(either.isLeft(output)),
64+
],
65+
// values with excess properties:
66+
[
67+
{
68+
0: '@check',
69+
type: { a: 'b' },
70+
value: { a: 'b', c: 'd' },
71+
},
72+
success({ a: 'b', c: 'd' }),
73+
],
74+
[
75+
{
76+
0: '@check',
77+
type: {},
78+
value: { a: 'b' },
79+
},
80+
success({ a: 'b' }),
81+
],
82+
[
83+
{
84+
0: '@check',
85+
type: { a: {} },
86+
value: { a: { b: 'c' } },
87+
},
88+
success({ a: { b: 'c' } }),
89+
],
90+
])

0 commit comments

Comments
 (0)