Skip to content

Commit

Permalink
exclude some tests on < 1.15
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Sep 27, 2024
1 parent c3cd2dc commit 65f1798
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions test/elixir_sense/core/compiler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ if true or Version.match?(System.version(), ">= 1.17.0-dev") do
end

defp state_to_map(%State{} = state) do
Map.take(state, [:caller, :prematch, :stacktrace, :unused, :runtime_modules, :vars])
res = Map.take(state, [:caller, :prematch, :stacktrace, :unused, :runtime_modules, :vars])

if Version.match?(System.version(), "< 1.15.0") do
res |> Map.put(:prematch, :warn)
else
res
end
end

defp expand(ast) do
Expand Down Expand Up @@ -172,15 +178,17 @@ if true or Version.match?(System.version(), ">= 1.17.0-dev") do
assert_expansion("%x{} = %Date{year: 2024, month: 2, day: 18}")
end

test "expands <<>>" do
assert_expansion("<<>>")
assert_expansion("<<1>>")
assert_expansion("<<x, rest::binary>> = \"\"")
end
if Version.match?(System.version(), ">= 1.15.0") do
test "expands <<>>" do
assert_expansion("<<>>")
assert_expansion("<<1>>")
assert_expansion("<<x, rest::binary>> = \"\"")
end

test "expands <<>> with modifier" do
assert_expansion("x = 1; y = 1; <<x::size(y)>>")
assert_expansion("x = 1; y = 1; <<x::size(y)>> = <<>>")
test "expands <<>> with modifier" do
assert_expansion("x = 1; y = 1; <<x::size(y)>>")
assert_expansion("x = 1; y = 1; <<x::size(y)>> = <<>>")
end
end

test "expands __block__" do
Expand Down Expand Up @@ -557,20 +565,22 @@ if true or Version.match?(System.version(), ">= 1.17.0-dev") do
""")
end

test "expands for with bitstring generator" do
assert_expansion("""
for <<r::8, g::8, b::8 <- "foo">> do
:ok
if Version.match?(System.version(), ">= 1.15.0") do
test "expands for with bitstring generator" do
assert_expansion("""
for <<r::8, g::8, b::8 <- "foo">> do
:ok
end
""")
end
""")
end

test "expands for with reduce" do
assert_expansion("""
for <<x <- "AbCabCABc">>, x in ?a..?z, reduce: %{} do
acc -> acc
test "expands for with reduce" do
assert_expansion("""
for <<x <- "AbCabCABc">>, x in ?a..?z, reduce: %{} do
acc -> acc
end
""")
end
""")
end

test "expands for in block" do

Check failure on line 586 in test/elixir_sense/core/compiler_test.exs

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 24.x)

test special forms expands for in block (ElixirSense.Core.CompilerTest)

Check failure on line 586 in test/elixir_sense/core/compiler_test.exs

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 25.x)

test special forms expands for in block (ElixirSense.Core.CompilerTest)

Check failure on line 586 in test/elixir_sense/core/compiler_test.exs

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 22.x)

test special forms expands for in block (ElixirSense.Core.CompilerTest)

Check failure on line 586 in test/elixir_sense/core/compiler_test.exs

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 23.x)

test special forms expands for in block (ElixirSense.Core.CompilerTest)

Check failure on line 586 in test/elixir_sense/core/compiler_test.exs

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 22.x)

test special forms expands for in block (ElixirSense.Core.CompilerTest)

Check failure on line 586 in test/elixir_sense/core/compiler_test.exs

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 24.x)

test special forms expands for in block (ElixirSense.Core.CompilerTest)

Check failure on line 586 in test/elixir_sense/core/compiler_test.exs

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 23.x)

test special forms expands for in block (ElixirSense.Core.CompilerTest)

Check failure on line 586 in test/elixir_sense/core/compiler_test.exs

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 25.x)

test special forms expands for in block (ElixirSense.Core.CompilerTest)
Expand Down Expand Up @@ -683,29 +693,31 @@ if true or Version.match?(System.version(), ">= 1.17.0-dev") do
assert state_to_map(state) == elixir_ex_to_map(elixir_state)
end

test "expands nullary call if_undefined: :warn" do
Code.put_compiler_option(:on_undefined_variable, :warn)
ast = {:self, [], nil}
if Version.match?(System.version(), ">= 1.15.0") do
test "expands nullary call if_undefined: :warn" do
Code.put_compiler_option(:on_undefined_variable, :warn)
ast = {:self, [], nil}

{expanded, state, env} =
Compiler.expand(
ast,
%State{
prematch: Code.get_compiler_option(:on_undefined_variable) || :warn
},
Compiler.env()
)
{expanded, state, env} =
Compiler.expand(
ast,
%State{
prematch: Code.get_compiler_option(:on_undefined_variable) || :warn
},
Compiler.env()
)

elixir_env = :elixir_env.new()
elixir_env = :elixir_env.new()

{elixir_expanded, elixir_state, elixir_env} =
:elixir_expand.expand(ast, :elixir_env.env_to_ex(elixir_env), elixir_env)
{elixir_expanded, elixir_state, elixir_env} =
:elixir_expand.expand(ast, :elixir_env.env_to_ex(elixir_env), elixir_env)

assert expanded == elixir_expanded
assert env == elixir_env
assert state_to_map(state) == elixir_ex_to_map(elixir_state)
after
Code.put_compiler_option(:on_undefined_variable, :raise)
assert expanded == elixir_expanded
assert env == elixir_env
assert state_to_map(state) == elixir_ex_to_map(elixir_state)
after
Code.put_compiler_option(:on_undefined_variable, :raise)
end
end

test "expands local call" do
Expand Down

0 comments on commit 65f1798

Please sign in to comment.