From 2ebafdd317a98f70b4f70c7cf0f4628f95da497f Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Thu, 22 Aug 2024 23:54:32 +0200 Subject: [PATCH] fix tests on 1.16 --- lib/elixir_sense/core/compiler/macro.ex | 4 +-- test/elixir_sense/core/compiler_test.exs | 6 ++++ .../metadata_builder/error_recovery_test.exs | 8 ++++++ .../core/metadata_builder_test.exs | 28 ++++++++++--------- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/elixir_sense/core/compiler/macro.ex b/lib/elixir_sense/core/compiler/macro.ex index b10dd018..62f4f0de 100644 --- a/lib/elixir_sense/core/compiler/macro.ex +++ b/lib/elixir_sense/core/compiler/macro.ex @@ -132,7 +132,7 @@ defmodule ElixirSense.Core.Compiler.Macro do when is_atom(name) and is_list(args) and is_list(meta) do arity = length(args) - case Macro.Env.expand_import(env, meta, name, arity, trace: false, check_deprecations: false) do + case NormalizedMacroEnv.expand_import(env, meta, name, arity, trace: false, check_deprecations: false) do {:macro, _receiver, expander} -> # TODO register call # We don't want the line to propagate yet, but generated might! @@ -169,7 +169,7 @@ defmodule ElixirSense.Core.Compiler.Macro do {original, false} true -> - case Macro.Env.expand_require(env, meta, receiver, name, length(args), + case NormalizedMacroEnv.expand_require(env, meta, receiver, name, length(args), trace: false, check_deprecations: false ) do diff --git a/test/elixir_sense/core/compiler_test.exs b/test/elixir_sense/core/compiler_test.exs index e5e1c9d0..afa74ede 100644 --- a/test/elixir_sense/core/compiler_test.exs +++ b/test/elixir_sense/core/compiler_test.exs @@ -380,6 +380,7 @@ if true or Version.match?(System.version(), ">= 1.17.0-dev") do assert_expansion("quote do: &inspect/1") end + if Version.match?(System.version(), ">= 1.17.0") do test "expands quote with bind_quoted" do assert_expansion(""" kv = [a: 1] @@ -390,6 +391,7 @@ if true or Version.match?(System.version(), ">= 1.17.0-dev") do end """) end + end test "expands quote with unquote false" do assert_expansion(""" @@ -399,11 +401,13 @@ if true or Version.match?(System.version(), ">= 1.17.0-dev") do """) end + if Version.match?(System.version(), ">= 1.17.0") do test "expands quote with file" do assert_expansion(""" quote file: "some.ex", do: bar(1, 2, 3) """) end + end test "expands quote with line" do assert_expansion(""" @@ -445,6 +449,7 @@ if true or Version.match?(System.version(), ">= 1.17.0-dev") do """) end + if Version.match?(System.version(), ">= 1.17.0") do test "expands &" do assert_expansion("& &1") assert_expansion("&Enum.take(&1, 5)") @@ -458,6 +463,7 @@ if true or Version.match?(System.version(), ">= 1.17.0-dev") do assert_expansion("&Enum.map(&2, &1)") assert_expansion("&inspect([&2, &1])") end + end test "expands fn" do assert_expansion("fn -> 1 end") diff --git a/test/elixir_sense/core/metadata_builder/error_recovery_test.exs b/test/elixir_sense/core/metadata_builder/error_recovery_test.exs index 241b1176..864d32d2 100644 --- a/test/elixir_sense/core/metadata_builder/error_recovery_test.exs +++ b/test/elixir_sense/core/metadata_builder/error_recovery_test.exs @@ -441,6 +441,7 @@ defmodule ElixirSense.Core.MetadataBuilder.ErrorRecoveryTest do assert Enum.any?(env.vars, &(&1.name == :x)) end + if Version.match?(System.version(), ">= 1.17.0") do test "cursor in left side of catch clause after type" do code = """ try do @@ -452,7 +453,9 @@ defmodule ElixirSense.Core.MetadataBuilder.ErrorRecoveryTest do assert {meta, env} = get_cursor_env(code) assert Enum.any?(env.vars, &(&1.name == :x)) end + end + if Version.match?(System.version(), ">= 1.17.0") do test "cursor in left side of catch clause 2 arg guard" do code = """ try do @@ -464,6 +467,7 @@ defmodule ElixirSense.Core.MetadataBuilder.ErrorRecoveryTest do assert {meta, env} = get_cursor_env(code) assert Enum.any?(env.vars, &(&1.name == :x)) end + end test "cursor in right side of catch clause" do code = """ @@ -777,6 +781,7 @@ defmodule ElixirSense.Core.MetadataBuilder.ErrorRecoveryTest do assert Enum.any?(env.vars, &(&1.name == :y)) end + if Version.match?(System.version(), ">= 1.17.0") do test "cursor in do block reduce left side of clause too many args" do code = """ for x <- [], reduce: %{} do @@ -788,6 +793,7 @@ defmodule ElixirSense.Core.MetadataBuilder.ErrorRecoveryTest do # this test fails # assert Enum.any?(env.vars, &(&1.name == :y)) end + end test "cursor in do block reduce right side of clause" do code = """ @@ -868,6 +874,7 @@ defmodule ElixirSense.Core.MetadataBuilder.ErrorRecoveryTest do assert Enum.any?(env.vars, &(&1.name == :x)) end + if Version.match?(System.version(), ">= 1.17.0") do test "incomplete clause left side guard" do code = """ fn @@ -877,6 +884,7 @@ defmodule ElixirSense.Core.MetadataBuilder.ErrorRecoveryTest do assert {meta, env} = get_cursor_env(code) assert Enum.any?(env.vars, &(&1.name == :x)) end + end test "incomplete clause right side" do code = """ diff --git a/test/elixir_sense/core/metadata_builder_test.exs b/test/elixir_sense/core/metadata_builder_test.exs index 0b760c81..199d3389 100644 --- a/test/elixir_sense/core/metadata_builder_test.exs +++ b/test/elixir_sense/core/metadata_builder_test.exs @@ -3850,8 +3850,10 @@ defmodule ElixirSense.Core.MetadataBuilderTest do test "map guards" do assert %VarInfo{name: :x, type: {:map, [], nil}} = var_with_guards("is_map(x)") + if Version.match?(System.version(), ">= 1.17.0") do assert %VarInfo{name: :x, type: {:map, [], nil}} = var_with_guards("is_non_struct_map(x)") + end assert %VarInfo{name: :x, type: {:map, [], nil}} = var_with_guards("map_size(x) == 1") assert %VarInfo{name: :x, type: {:map, [], nil}} = var_with_guards("1 == map_size(x)") @@ -7860,7 +7862,7 @@ defmodule ElixirSense.Core.MetadataBuilderTest do kind: :type, name: :foo, positions: [{4, 5}], - end_positions: [{4, 28}], + end_positions: _, generated: [false], specs: ["@type foo() :: unquote(v())"] } @@ -7894,13 +7896,13 @@ defmodule ElixirSense.Core.MetadataBuilderTest do |> string_to_state assert %{ - {My, :bar, 0} => %ElixirSense.Core.State.TypeInfo{ - name: :bar, + {My, :foo, 0} => %ElixirSense.Core.State.TypeInfo{ + name: :foo, args: [[]], - specs: ["@type bar()"], + specs: ["@type foo"], kind: :type, - positions: [{3, 3}], - end_positions: [{3, 14}], + positions: [{2, 3}], + end_positions: [{2, 12}], generated: [false], doc: "", meta: %{} @@ -7922,7 +7924,7 @@ defmodule ElixirSense.Core.MetadataBuilderTest do specs: ["@type baz(a)"], kind: :type, positions: [{4, 3}], - end_positions: [{4, 15}], + end_positions: _, generated: [false], doc: "", meta: %{} @@ -8040,13 +8042,13 @@ defmodule ElixirSense.Core.MetadataBuilderTest do |> string_to_state assert %{ - {My, :bar, 0} => %ElixirSense.Core.State.SpecInfo{ - name: :bar, + {My, :foo, 0} => %ElixirSense.Core.State.SpecInfo{ + name: :foo, args: [[]], - specs: ["@spec bar()"], + specs: ["@spec foo"], kind: :spec, - positions: [{3, 3}], - end_positions: [{3, 14}], + positions: [{2, 3}], + end_positions: [{2, 12}], generated: [false], doc: "", meta: %{} @@ -8068,7 +8070,7 @@ defmodule ElixirSense.Core.MetadataBuilderTest do specs: ["@spec baz(a)"], kind: :spec, positions: [{4, 3}], - end_positions: [{4, 15}], + end_positions: _, generated: [false], doc: "", meta: %{}