Skip to content

Commit

Permalink
skip tests on < 1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed May 4, 2024
1 parent d17ee89 commit b7392be
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 193 deletions.
193 changes: 97 additions & 96 deletions apps/language_server/test/providers/plugins/phoenix/scope_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit b7392be

Please sign in to comment.