-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathelixir_script_test.exs
More file actions
65 lines (52 loc) · 1.81 KB
/
elixir_script_test.exs
File metadata and controls
65 lines (52 loc) · 1.81 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
defmodule ElixirScript.Test do
use ExUnit.Case
import ElixirScript.TestHelper
test "turn javascript ast into javascript code strings" do
js_code = ElixirScript.compile(":atom")
assert Enum.join(js_code, "\n") |> String.trim == "Symbol.for('atom')"
end
test "parse macros" do
js_code = ElixirScript.compile("""
defmodule Animals do
use ElixirScript.Using
defp something_else() do
ElixirScript.Math.squared(1)
end
end
""", %{ env: make_custom_env })
assert_js_matches """
import Elixir$ElixirScript$Kernel from '../elixir/Elixir.ElixirScript.Kernel';
const something_else = Elixir.Core.Patterns.defmatch(Elixir.Core.Patterns.clause([],function() {
return 1 * 1;
}));
const sandwich = Elixir.Core.Patterns.defmatch(Elixir.Core.Patterns.clause([],function() {
return null;
}));
export default {
sandwich
};
""", List.last(js_code)
end
test "set standard lib path" do
js_code = ElixirScript.compile("""
defmodule Animals do
use ElixirScript.Using
defp something_else() do
ElixirScript.Math.squared(1)
end
end
""", %{ env: make_custom_env, core_path: "elixirscript"} )
assert_js_matches """
import Elixir$ElixirScript$Kernel from '../elixir/Elixir.ElixirScript.Kernel';
const something_else = Elixir.Core.Patterns.defmatch(Elixir.Core.Patterns.clause([],function() {
return 1 * 1;
}));
const sandwich = Elixir.Core.Patterns.defmatch(Elixir.Core.Patterns.clause([],function() {
return null;
}));
export default {
sandwich
};
""", List.last(js_code)
end
end