From 65f1798c86709dfc2529a37e2ddc4bc4092e6dc4 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Fri, 27 Sep 2024 23:24:06 +0200 Subject: [PATCH] exclude some tests on < 1.15 --- test/elixir_sense/core/compiler_test.exs | 90 ++++++++++++++---------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/test/elixir_sense/core/compiler_test.exs b/test/elixir_sense/core/compiler_test.exs index 89f2648e..e7503970 100644 --- a/test/elixir_sense/core/compiler_test.exs +++ b/test/elixir_sense/core/compiler_test.exs @@ -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 @@ -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("<> = \"\"") - end + if Version.match?(System.version(), ">= 1.15.0") do + test "expands <<>>" do + assert_expansion("<<>>") + assert_expansion("<<1>>") + assert_expansion("<> = \"\"") + end - test "expands <<>> with modifier" do - assert_expansion("x = 1; y = 1; <>") - assert_expansion("x = 1; y = 1; <> = <<>>") + test "expands <<>> with modifier" do + assert_expansion("x = 1; y = 1; <>") + assert_expansion("x = 1; y = 1; <> = <<>>") + end end test "expands __block__" do @@ -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 <> do - :ok + if Version.match?(System.version(), ">= 1.15.0") do + test "expands for with bitstring generator" do + assert_expansion(""" + for <> do + :ok + end + """) end - """) - end - test "expands for with reduce" do - assert_expansion(""" - for <>, x in ?a..?z, reduce: %{} do - acc -> acc + test "expands for with reduce" do + assert_expansion(""" + for <>, x in ?a..?z, reduce: %{} do + acc -> acc + end + """) end - """) end test "expands for in block" do @@ -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