Skip to content

Commit f5b09cb

Browse files
committed
Add test for FFI output. Refactor debug_info for ElixirScript replacements
1 parent 69c3274 commit f5b09cb

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

lib/elixir_script/beam.ex

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,11 @@ defmodule ElixirScript.Beam do
1010
@spec debug_info(atom) :: {:ok | :error, map | binary}
1111
def debug_info(module)
1212

13-
#Replacing String module with our ElixirScript's version
14-
def debug_info(String) do
15-
case debug_info(ElixirScript.String) do
13+
#Replace some modules with ElixirScript versions
14+
def debug_info(module) when module in [String, Agent] do
15+
case debug_info(Module.concat(ElixirScript, module)) do
1616
{:ok, info} ->
17-
{:ok, Map.put(info, :module, String)}
18-
e ->
19-
e
20-
end
21-
end
22-
23-
#Replacing Agent module with our ElixirScript's version
24-
def debug_info(Agent) do
25-
case debug_info(ElixirScript.Agent) do
26-
{:ok, info} ->
27-
{:ok, Map.put(info, :module, Agent)}
17+
{:ok, Map.put(info, :module, module)}
2818
e ->
2919
e
3020
end

test/compiler_test.exs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ defmodule ElixirScript.Compiler.Test do
66
assert is_binary(result)
77
end
88

9+
test "Use defined module with FFI module" do
10+
result = ElixirScript.Compiler.compile(Main)
11+
assert is_binary(result)
12+
assert result =~ "import Data_JSON from './data/json'"
13+
end
14+
915
test "Can compile multiple entry modules" do
10-
result = ElixirScript.Compiler.compile([Atom, String])
16+
result = ElixirScript.Compiler.compile([Atom, String, Agent])
1117
assert is_binary(result)
1218
end
1319

test/support/main.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
defmodule Main do
22
def start(:normal, [callback]) do
33
callback.("started")
4+
5+
Data.JSON.stringify(1)
46
end
57
end

0 commit comments

Comments
 (0)