-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathstring_test.exs
More file actions
43 lines (36 loc) · 1.65 KB
/
Copy pathstring_test.exs
File metadata and controls
43 lines (36 loc) · 1.65 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
defmodule ElixirScript.Translator.String.Test do
use ExUnit.Case
import ElixirScript.TestHelper
test "translate string" do
ex_ast = quote do: "Hello"
assert_translation(ex_ast, "'Hello'")
end
test "translate multiline string" do
ex_ast = quote do: """
Hello
This is another line
"""
assert_translation(ex_ast, "'Hello\\nThis is another line\\n'")
end
test "translate string concatenation" do
ex_ast = quote do: "Hello" <> "World"
assert_translation(ex_ast, "'Hello' + 'World'")
end
test "translate string interpolation" do
ex_ast = quote do: "Hello #{"world"}"
assert_translation(ex_ast, "'Hello ' + Elixir.ElixirScript.String.Chars.__load(Elixir).to_string('world')")
ex_ast = quote do: "Hello #{length([])}"
assert_translation(ex_ast, "'Hello ' + Elixir.ElixirScript.String.Chars.__load(Elixir).to_string(Elixir.ElixirScript.Kernel.__load(Elixir).length(Object.freeze([])))")
end
test "translate multiline string interpolation" do
ex_ast = quote do: """
Hello #{length([])}
"""
assert_translation(ex_ast, "'Hello ' + (Elixir.ElixirScript.String.Chars.__load(Elixir).to_string(Elixir.ElixirScript.Kernel.__load(Elixir).length(Object.freeze([]))) + '\\n')")
ex_ast = quote do: """
Hello #{length([])}
How are you, #{length([])}?
"""
assert_translation(ex_ast, "'Hello ' + (Elixir.ElixirScript.String.Chars.__load(Elixir).to_string(Elixir.ElixirScript.Kernel.__load(Elixir).length(Object.freeze([]))) + ('\\nHow are you, ' + (Elixir.ElixirScript.String.Chars.__load(Elixir).to_string(Elixir.ElixirScript.Kernel.__load(Elixir).length(Object.freeze([]))) + '?\\n')))")
end
end