forked from elixirscript/elixirscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelixir_script_test.exs
More file actions
96 lines (74 loc) · 2.16 KB
/
Copy pathelixir_script_test.exs
File metadata and controls
96 lines (74 loc) · 2.16 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
defmodule ElixirScript.Test do
use ShouldI
import ElixirScript.TestHelper
should "turn javascript ast into javascript code strings" do
js_code = ElixirScript.transpile(":atom")
assert hd(js_code) == "Erlang.atom('atom')"
end
should "parse one module correctly" do
js_code = ElixirScript.transpile("""
defmodule Elephant do
@ul JQuery.("#todo-list")
def something() do
@ul
end
defp something_else() do
end
end
""")
assert_js_matches """
import Erlang from '__lib/erlang';
import Kernel from '__lib/kernel';
import fun from '__lib/funcy/fun';
const __MODULE__ = Erlang.atom('Elephant');
let something_else = fun([[], function() {
return null;
}]);
let something = fun([[], function() {
return ul;
}]);
const ul = JQuery('#todo-list');
export default {
something: something
};
""", hd(js_code)
end
should "parse multiple modules correctly" do
js_code = ElixirScript.transpile("""
defmodule Animals do
defmodule Elephant do
defstruct trunk: true
end
def something() do
%Elephant{}
end
defp something_else() do
end
end
""")
assert_js_matches """
import Erlang from '__lib/erlang';
import Kernel from '__lib/kernel';
import fun from '__lib/funcy/fun';
import Elephant from 'animals/elephant';
const __MODULE__ = Erlang.atom('Animals');
let something_else = fun([[], function() {
return null;
}]);
let something = fun([[], function() {
return Elephant.defstruct();
}]);
export default {
something: something
};
""", hd(js_code)
assert_js_matches """
import Erlang from '__lib/erlang';
import Kernel from '__lib/kernel';
import fun from '__lib/funcy/fun';
const __MODULE__ = Erlang.atom('Elephant');
function defstruct(trunk = true){return {__struct__: __MODULE__, trunk: trunk};}
export default {defstruct: defstruct};
""", List.last(js_code)
end
end