-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathtry.spec.js
More file actions
45 lines (40 loc) · 771 Bytes
/
try.spec.js
File metadata and controls
45 lines (40 loc) · 771 Bytes
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
import test from 'ava';
import Core from '../lib/core';
const Patterns = Core.Patterns;
const SpecialForms = Core.SpecialForms;
test('try', t => {
/*
try do
1 / x
else
y when y < 1 and y > -1 ->
:small
_ ->
:large
end
*/
const x = 1;
const value = SpecialForms._try(
() => {
return 1 / x;
},
null,
null,
Patterns.defmatch(
Patterns.clause(
[Patterns.variable()],
y => {
return Symbol.for('small');
},
y => {
return y < 1 && y > -1;
}
),
Patterns.clause([Patterns.wildcard()], () => {
return Symbol.for('large');
})
),
null
);
t.is(value, Symbol.for('large'));
});