From b7392befea3aabe940fef7c2b949d2bd1131758f Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Sat, 4 May 2024 07:32:07 +0200 Subject: [PATCH] skip tests on < 1.14 --- .../providers/plugins/phoenix/scope_test.exs | 193 ++++++++--------- .../test/providers/plugins/phoenix_test.exs | 195 +++++++++--------- 2 files changed, 195 insertions(+), 193 deletions(-) diff --git a/apps/language_server/test/providers/plugins/phoenix/scope_test.exs b/apps/language_server/test/providers/plugins/phoenix/scope_test.exs index 1b9bb2d81..223ed95d6 100644 --- a/apps/language_server/test/providers/plugins/phoenix/scope_test.exs +++ b/apps/language_server/test/providers/plugins/phoenix/scope_test.exs @@ -3,112 +3,113 @@ defmodule ElixirLS.LanguageServer.Plugins.Phoenix.ScopeTest do alias ElixirSense.Core.Binding alias ElixirLS.LanguageServer.Plugins.Phoenix.Scope - @moduletag requires_elixir_1_14: true - describe "within_scope/1" do - test "returns true and nil alias" do - buffer = """ - scope "/" do - get "/", - """ - - assert {true, nil} = Scope.within_scope(buffer) - end - - test "returns true and alias when passing alias as option" do - buffer = """ - scope "/", alias: ExampleWeb do - get "/", - """ - - assert {true, ExampleWeb} = Scope.within_scope(buffer) - end + if Version.match?(System.version(), ">= 1.14.0") do + describe "within_scope/1" do + test "returns true and nil alias" do + buffer = """ + scope "/" do + get "/", + """ - test "returns true and alias when passing alias as second parameter" do - buffer = """ - scope "/", ExampleWeb do - get "/", - """ + assert {true, nil} = Scope.within_scope(buffer) + end - assert {true, ExampleWeb} = Scope.within_scope(buffer) - end + test "returns true and alias when passing alias as option" do + buffer = """ + scope "/", alias: ExampleWeb do + get "/", + """ - test "returns true and alias when nested within other scopes" do - _define_existing_atom = ExampleWeb.Admin - _define_existing_atom = Admin + assert {true, ExampleWeb} = Scope.within_scope(buffer) + end - buffer = """ - scope "/", ExampleWeb do - scope "/admin", Admin do + test "returns true and alias when passing alias as second parameter" do + buffer = """ + scope "/", ExampleWeb do get "/", - """ + """ - assert {true, ExampleWeb.Admin} = Scope.within_scope(buffer) - end + assert {true, ExampleWeb} = Scope.within_scope(buffer) + end - test "can expand module attributes" do - buffer = """ - defmodule ExampleWeb.Router do - import Phoenix.Router - @web_prefix ExampleWweb - - scope "/", @web_prefix do - get "/", - """ - - binding = %Binding{ - structs: %{}, - variables: [], - attributes: [ - %ElixirSense.Core.State.AttributeInfo{ - name: :web_prefix, - positions: [{4, 5}], - type: {:atom, ExampleWeb} - } - ], - current_module: ExampleWeb.Router, - specs: %{}, - types: %{}, - mods_funs: %{} - } - - assert {true, ExampleWeb} = Scope.within_scope(buffer, binding) - end + test "returns true and alias when nested within other scopes" do + _define_existing_atom = ExampleWeb.Admin + _define_existing_atom = Admin - test "can expand variables" do - buffer = """ - defmodule ExampleWeb.Router do - import Phoenix.Router - web_prefix = ExampleWweb - - scope "/", web_prefix do - get "/", - """ - - binding = %Binding{ - structs: %{}, - variables: [ - %ElixirSense.Core.State.VarInfo{ - name: :web_prefix, - positions: [{5, 5}], - scope_id: 2, - is_definition: true, - type: {:atom, ExampleWeb} - } - ], - attributes: [], - current_module: ExampleWeb.Router, - specs: %{}, - types: %{}, - mods_funs: %{} - } - - assert {true, ExampleWeb} = Scope.within_scope(buffer, binding) - end + buffer = """ + scope "/", ExampleWeb do + scope "/admin", Admin do + get "/", + """ - test "returns false" do - buffer = "get \"\\\" ," + assert {true, ExampleWeb.Admin} = Scope.within_scope(buffer) + end - assert {false, nil} = Scope.within_scope(buffer) + test "can expand module attributes" do + buffer = """ + defmodule ExampleWeb.Router do + import Phoenix.Router + @web_prefix ExampleWweb + + scope "/", @web_prefix do + get "/", + """ + + binding = %Binding{ + structs: %{}, + variables: [], + attributes: [ + %ElixirSense.Core.State.AttributeInfo{ + name: :web_prefix, + positions: [{4, 5}], + type: {:atom, ExampleWeb} + } + ], + current_module: ExampleWeb.Router, + specs: %{}, + types: %{}, + mods_funs: %{} + } + + assert {true, ExampleWeb} = Scope.within_scope(buffer, binding) + end + + test "can expand variables" do + buffer = """ + defmodule ExampleWeb.Router do + import Phoenix.Router + web_prefix = ExampleWweb + + scope "/", web_prefix do + get "/", + """ + + binding = %Binding{ + structs: %{}, + variables: [ + %ElixirSense.Core.State.VarInfo{ + name: :web_prefix, + positions: [{5, 5}], + scope_id: 2, + is_definition: true, + type: {:atom, ExampleWeb} + } + ], + attributes: [], + current_module: ExampleWeb.Router, + specs: %{}, + types: %{}, + mods_funs: %{} + } + + assert {true, ExampleWeb} = Scope.within_scope(buffer, binding) + end + + test "returns false" do + buffer = "get \"\\\" ," + + assert {false, nil} = Scope.within_scope(buffer) + end end end end diff --git a/apps/language_server/test/providers/plugins/phoenix_test.exs b/apps/language_server/test/providers/plugins/phoenix_test.exs index 4a8d513fa..1444b87fd 100644 --- a/apps/language_server/test/providers/plugins/phoenix_test.exs +++ b/apps/language_server/test/providers/plugins/phoenix_test.exs @@ -28,129 +28,130 @@ defmodule ElixirLS.LanguageServer.Plugins.PhoenixTest do ) end - @moduletag requires_elixir_1_14: true - describe "suggestions/4" do - test "overrides with controllers for phoenix_route_funcs, when in the second parameter" do - buffer = """ - defmodule ExampleWeb.Router do - import Phoenix.Router - - get "/", P - # ^ - end - """ - - [cursor] = cursors(buffer) + if Version.match?(System.version(), ">= 1.14.0") do + describe "suggestions/4" do + test "overrides with controllers for phoenix_route_funcs, when in the second parameter" do + buffer = """ + defmodule ExampleWeb.Router do + import Phoenix.Router - result = suggestions(buffer, cursor) + get "/", P + # ^ + end + """ - assert [ - %{ - type: :generic, - kind: :class, - label: "ExampleWeb.PageController", - insert_text: "ExampleWeb.PageController", - detail: "Phoenix controller" - } - ] = result - end + [cursor] = cursors(buffer) - test "do not prepend alias defined within Phoenix `scope` functions" do - _define_existing_atom = ExampleWeb + result = suggestions(buffer, cursor) - buffer = """ - defmodule ExampleWeb.Router do - import Phoenix.Router + assert [ + %{ + type: :generic, + kind: :class, + label: "ExampleWeb.PageController", + insert_text: "ExampleWeb.PageController", + detail: "Phoenix controller" + } + ] = result + end - scope "/", ExampleWeb do - get "/", P - # ^ - end - end - """ + test "do not prepend alias defined within Phoenix `scope` functions" do + _define_existing_atom = ExampleWeb - [cursor] = cursors(buffer) + buffer = """ + defmodule ExampleWeb.Router do + import Phoenix.Router - result = suggestions(buffer, cursor) + scope "/", ExampleWeb do + get "/", P + # ^ + end + end + """ - assert [ - %{ - type: :generic, - kind: :class, - label: "ExampleWeb.PageController", - insert_text: "PageController", - detail: "Phoenix controller" - } - ] = result - end + [cursor] = cursors(buffer) - test "overrides with action suggestions for phoenix_route_funcs, when in the third parameter" do - buffer = """ - defmodule ExampleWeb.Router do - import Phoenix.Router + result = suggestions(buffer, cursor) - get "/", ExampleWeb.PageController, : - # ^ + assert [ + %{ + type: :generic, + kind: :class, + label: "ExampleWeb.PageController", + insert_text: "PageController", + detail: "Phoenix controller" + } + ] = result end - """ - [cursor] = cursors(buffer) + test "overrides with action suggestions for phoenix_route_funcs, when in the third parameter" do + buffer = """ + defmodule ExampleWeb.Router do + import Phoenix.Router - result = suggestions(buffer, cursor) + get "/", ExampleWeb.PageController, : + # ^ + end + """ - assert [ - %{ - detail: "Phoenix action", - insert_text: "home", - kind: :function, - label: ":home", - type: :generic - } - ] = result - end + [cursor] = cursors(buffer) - test "overrides with action suggestions even when inside scope" do - buffer = """ - defmodule ExampleWeb.Router do - import Phoenix.Router + result = suggestions(buffer, cursor) - scope "/", ExampleWeb do - get "/", PageController, : - # ^ - end + assert [ + %{ + detail: "Phoenix action", + insert_text: "home", + kind: :function, + label: ":home", + type: :generic + } + ] = result end - """ - [cursor] = cursors(buffer) + test "overrides with action suggestions even when inside scope" do + buffer = """ + defmodule ExampleWeb.Router do + import Phoenix.Router - result = suggestions(buffer, cursor) + scope "/", ExampleWeb do + get "/", PageController, : + # ^ + end + end + """ - assert [ - %{ - detail: "Phoenix action", - insert_text: "home", - kind: :function, - label: ":home", - type: :generic - } - ] = result - end + [cursor] = cursors(buffer) - test "ignores for non-phoenix_route_funcs" do - buffer = """ - defmodule ExampleWeb.Router do - import Phoenix.Router + result = suggestions(buffer, cursor) - something_else "/", P - # ^ + assert [ + %{ + detail: "Phoenix action", + insert_text: "home", + kind: :function, + label: ":home", + type: :generic + } + ] = result end - """ - [cursor] = cursors(buffer) + test "ignores for non-phoenix_route_funcs" do + buffer = """ + defmodule ExampleWeb.Router do + import Phoenix.Router - result = suggestions(buffer, cursor) + something_else "/", P + # ^ + end + """ - refute Enum.find(result, &(&1[:detail] == "Phoenix controller")) + [cursor] = cursors(buffer) + + result = suggestions(buffer, cursor) + + refute Enum.find(result, &(&1[:detail] == "Phoenix controller")) + end end end end