Skip to content

Commit 72767c0

Browse files
committed
Update tests for functions turned to async functions
1 parent 8dc2cc8 commit 72767c0

8 files changed

Lines changed: 54 additions & 52 deletions

File tree

src/javascript/tests/case.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const Patterns = Core.Patterns;
55
const SpecialForms = Core.SpecialForms;
66
const Tuple = Core.Tuple;
77

8-
test('case', t => {
8+
test('case', async t => {
99
const clauses = [
1010
Patterns.clause(
1111
[
1212
new Tuple(
1313
Symbol.for('selector'),
1414
Patterns.variable(),
1515
Patterns.variable()
16-
),
16+
)
1717
],
1818
(i, value) => {
1919
return value;
@@ -24,10 +24,10 @@ test('case', t => {
2424
),
2525
Patterns.clause([Patterns.variable()], value => {
2626
return value;
27-
}),
27+
})
2828
];
2929

30-
const result = SpecialForms._case('thing', clauses);
30+
const result = await SpecialForms._case('thing', clauses);
3131

3232
t.is(result, 'thing');
3333
});

src/javascript/tests/cond.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import Core from '../lib/core';
33

44
const SpecialForms = Core.SpecialForms;
55

6-
test('cond', t => {
6+
test('cond', async t => {
77
const clauses = [
88
[1 + 1 === 1, () => 'This will never match'],
99
[2 * 2 !== 4, () => 'Nor this'],
10-
[true, () => 'This will'],
10+
[true, () => 'This will']
1111
];
1212

13-
const result = SpecialForms.cond(...clauses);
13+
const result = await SpecialForms.cond(...clauses);
1414

1515
t.is(result, 'This will');
1616
});

src/javascript/tests/core/erlang_compat/lists_spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ test('flatten', t => {
1616
t.deepEqual(Core.lists.flatten([1, [[2], 3]]), [1, 2, 3]);
1717
});
1818

19-
test('foldl', t => {
20-
t.deepEqual(Core.lists.foldl((v, acc) => acc + v, 0, [1, 2, 3]), 6);
19+
test('foldl', async t => {
20+
t.deepEqual(await Core.lists.foldl((v, acc) => acc + v, 0, [1, 2, 3]), 6);
2121
});
2222

23-
test('foldr', t => {
23+
test('foldr', async t => {
2424
t.deepEqual(
25-
Core.lists.foldr((v, acc) => acc + v.toString(), '', [1, 2, 3]),
25+
await Core.lists.foldr((v, acc) => acc + v.toString(), '', [1, 2, 3]),
2626
'321'
2727
);
2828
});

src/javascript/tests/core/erlang_compat/maps_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ test('find', t => {
1515
t.deepEqual(result.values, [Symbol.for('ok'), 'b']);
1616
});
1717

18-
test('fold', t => {
18+
test('fold', async t => {
1919
const myMap = new Map([['a', 1], ['b', 2]]);
20-
const result = Core.maps.fold((k, v, acc) => acc + v, 0, myMap);
20+
const result = await Core.maps.fold((k, v, acc) => acc + v, 0, myMap);
2121
t.is(result, 3);
2222
});

src/javascript/tests/core/functions.spec.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ import test from 'ava';
22
import Core from '../../lib/core';
33
const Functions = Core.Functions;
44

5-
test('call_property', t => {
6-
t.is(Functions.call_property(1, 'toString'), '1');
7-
t.is(Functions.call_property([], 'toString'), '');
8-
t.is(Functions.call_property([], 'length'), 0);
9-
t.is(Functions.call_property('', 'toString'), '');
10-
t.is(Functions.call_property('', 'length'), 0);
11-
t.is(Functions.call_property(Symbol('test'), 'toString'), 'Symbol(test)');
12-
t.is(Functions.call_property({ completed: false }, 'completed'), false);
13-
t.is(Functions.call_property({ id: 0 }, 'id'), 0);
5+
test('call_property', async t => {
6+
t.is(await Functions.call_property(1, 'toString'), '1');
7+
t.is(await Functions.call_property([], 'toString'), '');
8+
t.is(await Functions.call_property([], 'length'), 0);
9+
t.is(await Functions.call_property('', 'toString'), '');
10+
t.is(await Functions.call_property('', 'length'), 0);
11+
t.is(
12+
await Functions.call_property(Symbol('test'), 'toString'),
13+
'Symbol(test)'
14+
);
15+
t.is(await Functions.call_property({ completed: false }, 'completed'), false);
16+
t.is(await Functions.call_property({ id: 0 }, 'id'), 0);
1417
});
1518

1619
test('split_at', t => {

src/javascript/tests/for.spec.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ const collectable = {
1414
[
1515
$,
1616
Patterns.type(Tuple, {
17-
values: [Symbol.for('cont'), Patterns.variable()],
18-
}),
17+
values: [Symbol.for('cont'), Patterns.variable()]
18+
})
1919
],
2020
(list, x) => list.concat([x])
2121
),
2222
Patterns.clause([$, Symbol.for('done')], list => list)
2323
);
2424

2525
return new Tuple([], fun);
26-
},
26+
}
2727
};
2828

29-
test('simple for', t => {
29+
test('simple for', async t => {
3030
const gen = Patterns.list_generator($, [1, 2, 3, 4]);
31-
const result = SpecialForms._for(
31+
const result = await SpecialForms._for(
3232
Patterns.clause([$], x => x * 2),
3333
[gen],
3434
collectable
@@ -37,12 +37,12 @@ test('simple for', t => {
3737
t.deepEqual(result, [2, 4, 6, 8]);
3838
});
3939

40-
test('for with multiple generators', t => {
40+
test('for with multiple generators', async t => {
4141
//for x <- [1, 2], y <- [2, 3], do: x*y
4242

4343
const gen = Patterns.list_generator($, [1, 2]);
4444
const gen2 = Patterns.list_generator($, [2, 3]);
45-
const result = SpecialForms._for(
45+
const result = await SpecialForms._for(
4646
Patterns.clause([$, $], (x, y) => x * y),
4747
[gen, gen2],
4848
collectable
@@ -51,10 +51,10 @@ test('for with multiple generators', t => {
5151
t.deepEqual(result, [2, 3, 4, 6]);
5252
});
5353

54-
test('for with filter', t => {
54+
test('for with filter', async t => {
5555
//for n <- [1, 2, 3, 4, 5, 6], rem(n, 2) == 0, do: n
5656
const gen = Patterns.list_generator($, [1, 2, 3, 4, 5, 6]);
57-
const result = SpecialForms._for(
57+
const result = await SpecialForms._for(
5858
Patterns.clause([$], x => x, x => x % 2 === 0),
5959
[gen],
6060
collectable
@@ -63,7 +63,7 @@ test('for with filter', t => {
6363
t.deepEqual(result, [2, 4, 6]);
6464
});
6565

66-
test('for with pattern matching', t => {
66+
test('for with pattern matching', async t => {
6767
//for {:user, name} <- [user: "john", admin: "john", user: "meg"], do
6868
// String.upcase(name)
6969
//end
@@ -73,11 +73,11 @@ test('for with pattern matching', t => {
7373
[
7474
[Symbol.for('user'), 'john'],
7575
[Symbol.for('admin'), 'john'],
76-
[Symbol.for('user'), 'meg'],
76+
[Symbol.for('user'), 'meg']
7777
]
7878
);
7979

80-
const result = SpecialForms._for(
80+
const result = await SpecialForms._for(
8181
Patterns.clause([[Symbol.for('user'), $]], name => name.toUpperCase()),
8282
[gen],
8383
collectable
@@ -86,7 +86,7 @@ test('for with pattern matching', t => {
8686
t.deepEqual(result, ['JOHN', 'MEG']);
8787
});
8888

89-
test('for with bitstring', t => {
89+
test('for with bitstring', async t => {
9090
//for <<r::8, g::8, b::8 <- <<213, 45, 132, 64, 76, 32, 76, 0, 0, 234, 32, 15>> >>, do: {r, g, b}
9191

9292
const gen = Patterns.bitstring_generator(
@@ -117,17 +117,17 @@ test('for with bitstring', t => {
117117
BitString.integer({ value: $ }),
118118
BitString.integer({ value: $ }),
119119
BitString.integer({ value: $ })
120-
),
120+
)
121121
],
122122
(r, g, b) => new Tuple(r, g, b)
123123
);
124124

125-
const result = SpecialForms._for(expression, [gen], collectable);
125+
const result = await SpecialForms._for(expression, [gen], collectable);
126126

127127
t.deepEqual(result, [
128128
new Tuple(213, 45, 132),
129129
new Tuple(64, 76, 32),
130130
new Tuple(76, 0, 0),
131-
new Tuple(234, 32, 15),
131+
new Tuple(234, 32, 15)
132132
]);
133133
});

src/javascript/tests/try.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Core from '../lib/core';
33
const Patterns = Core.Patterns;
44
const SpecialForms = Core.SpecialForms;
55

6-
test('try', t => {
6+
test('try', async t => {
77
/*
88
try do
99
1 / x
@@ -18,7 +18,7 @@ test('try', t => {
1818

1919
const x = 1;
2020

21-
const value = SpecialForms._try(
21+
const value = await SpecialForms._try(
2222
() => {
2323
return 1 / x;
2424
},

src/javascript/tests/with.spec.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function map_fetch(map, key) {
1616
return Symbol.for('error');
1717
}
1818

19-
test('with', t => {
19+
test('with', async t => {
2020
/*
2121
opts = %{width: 10, height: 15}
2222
@@ -29,7 +29,7 @@ test('with', t => {
2929

3030
const opts = { width: 10, height: 15 };
3131

32-
const value = SpecialForms._with(
32+
const value = await SpecialForms._with(
3333
[new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'width')],
3434
[new Tuple(Symbol.for('ok'), $), width => map_fetch(opts, 'height')],
3535
(width, height) => new Tuple(Symbol.for('ok'), width * height)
@@ -38,7 +38,7 @@ test('with', t => {
3838
t.deepEqual(value, new Tuple(Symbol.for('ok'), 150));
3939
});
4040

41-
test('with without match', t => {
41+
test('with without match', async t => {
4242
/*
4343
opts = %{width: 10}
4444
@@ -51,7 +51,7 @@ test('with without match', t => {
5151

5252
const opts = { width: 10 };
5353

54-
const value = SpecialForms._with(
54+
const value = await SpecialForms._with(
5555
[new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'width')],
5656
[new Tuple(Symbol.for('ok'), $), width => map_fetch(opts, 'height')],
5757
(width, height) => new Tuple(Symbol.for('ok'), width * height)
@@ -60,7 +60,7 @@ test('with without match', t => {
6060
t.deepEqual(value, Symbol.for('error'));
6161
});
6262

63-
test('with bare expression', t => {
63+
test('with bare expression', async t => {
6464
/*
6565
opts = %{width: 10}
6666
@@ -74,7 +74,7 @@ test('with bare expression', t => {
7474

7575
const opts = { width: 10, height: 15 };
7676

77-
const value = SpecialForms._with(
77+
const value = await SpecialForms._with(
7878
[new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'width')],
7979
[$, width => width * 2],
8080
[
@@ -88,7 +88,7 @@ test('with bare expression', t => {
8888
t.deepEqual(value, new Tuple(Symbol.for('ok'), 300));
8989
});
9090

91-
test('with else', t => {
91+
test('with else', async t => {
9292
/*
9393
opts = %{width: 10}
9494
@@ -104,7 +104,7 @@ test('with else', t => {
104104

105105
const opts = { width: 10 };
106106

107-
const value = SpecialForms._with(
107+
const value = await SpecialForms._with(
108108
[new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'width')],
109109
[new Tuple(Symbol.for('ok'), $), width => map_fetch(opts, 'height')],
110110
(width, height) => new Tuple(Symbol.for('ok'), width * height),
@@ -119,7 +119,7 @@ test('with else', t => {
119119
t.deepEqual(value, new Tuple(Symbol.for('error'), Symbol.for('wrong_data')));
120120
});
121121

122-
test('with else that don`t match', t => {
122+
test('with else that don`t match', async t => {
123123
/*
124124
opts = %{width: 10}
125125
@@ -135,8 +135,7 @@ test('with else that don`t match', t => {
135135

136136
const opts = { width: 10 };
137137

138-
const withFunction = SpecialForms._with.bind(
139-
null,
138+
const withFunctionPromise = SpecialForms._with(
140139
[new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'width')],
141140
[new Tuple(Symbol.for('ok'), $), width => map_fetch(opts, 'height')],
142141
(width, height) => new Tuple(Symbol.for('ok'), width * height),
@@ -148,5 +147,5 @@ test('with else that don`t match', t => {
148147
)
149148
);
150149

151-
t.throws(withFunction, MatchError);
150+
await t.throws(withFunctionPromise, MatchError);
152151
});

0 commit comments

Comments
 (0)