-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathcond_test.exs
More file actions
58 lines (52 loc) · 1.61 KB
/
cond_test.exs
File metadata and controls
58 lines (52 loc) · 1.61 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
defmodule ElixirScript.Translator.Cond.Test do
use ExUnit.Case
import ElixirScript.TestHelper
test "translate cond" do
ex_ast = quote do
cond do
1 + 1 == 1 ->
"This will never match"
2 * 2 != 4 ->
"Nor this"
true ->
"This will"
end
end
js_code = """
Bootstrap.Core.SpecialForms.cond(Object.freeze([1 + 1 == 1, function() {
return 'This will never match';
}]),Object.freeze([2 * 2 != 4, function() {
return 'Nor this';
}]),Object.freeze([true, function() {
return 'This will';
}]))
"""
assert_translation(ex_ast, js_code)
ex_ast = quote do
cond do
1 + 1 == 1 ->
a = 1
"This will never match"
2 * 2 != 4 ->
a = 2
"Nor this"
true ->
a = 3
"This will"
end
end
js_code = """
Bootstrap.Core.SpecialForms.cond(Object.freeze([1 + 1 == 1, function() {
let [a] = Bootstrap.Core.Patterns.match(Bootstrap.Core.Patterns.variable(),1);
return 'This will never match';
}]),Object.freeze([2 * 2 != 4, function() {
let [a] = Bootstrap.Core.Patterns.match(Bootstrap.Core.Patterns.variable(),2);
return 'Nor this';
}]),Object.freeze([true, function() {
let [a] = Bootstrap.Core.Patterns.match(Bootstrap.Core.Patterns.variable(),3);
return 'This will';
}]))
"""
assert_translation(ex_ast, js_code)
end
end