@@ -3,112 +3,113 @@ defmodule ElixirLS.LanguageServer.Plugins.Phoenix.ScopeTest do
33 alias ElixirSense.Core.Binding
44 alias ElixirLS.LanguageServer.Plugins.Phoenix.Scope
55
6- @ moduletag requires_elixir_1_14: true
7- describe "within_scope/1" do
8- test "returns true and nil alias" do
9- buffer = """
10- scope "/" do
11- get "/",
12- """
13-
14- assert { true , nil } = Scope . within_scope ( buffer )
15- end
16-
17- test "returns true and alias when passing alias as option" do
18- buffer = """
19- scope "/", alias: ExampleWeb do
20- get "/",
21- """
22-
23- assert { true , ExampleWeb } = Scope . within_scope ( buffer )
24- end
6+ if Version . match? ( System . version ( ) , ">= 1.14.0" ) do
7+ describe "within_scope/1" do
8+ test "returns true and nil alias" do
9+ buffer = """
10+ scope "/" do
11+ get "/",
12+ """
2513
26- test "returns true and alias when passing alias as second parameter" do
27- buffer = """
28- scope "/", ExampleWeb do
29- get "/",
30- """
14+ assert { true , nil } = Scope . within_scope ( buffer )
15+ end
3116
32- assert { true , ExampleWeb } = Scope . within_scope ( buffer )
33- end
17+ test "returns true and alias when passing alias as option" do
18+ buffer = """
19+ scope "/", alias: ExampleWeb do
20+ get "/",
21+ """
3422
35- test "returns true and alias when nested within other scopes" do
36- _define_existing_atom = ExampleWeb.Admin
37- _define_existing_atom = Admin
23+ assert { true , ExampleWeb } = Scope . within_scope ( buffer )
24+ end
3825
39- buffer = """
40- scope "/", ExampleWeb do
41- scope "/admin ", Admin do
26+ test "returns true and alias when passing alias as second parameter" do
27+ buffer = """
28+ scope "/", ExampleWeb do
4229 get "/",
43- """
30+ """
4431
45- assert { true , ExampleWeb.Admin } = Scope . within_scope ( buffer )
46- end
32+ assert { true , ExampleWeb } = Scope . within_scope ( buffer )
33+ end
4734
48- test "can expand module attributes" do
49- buffer = """
50- defmodule ExampleWeb.Router do
51- import Phoenix.Router
52- @web_prefix ExampleWweb
53-
54- scope "/", @web_prefix do
55- get "/",
56- """
57-
58- binding = % Binding {
59- structs: % { } ,
60- variables: [ ] ,
61- attributes: [
62- % ElixirSense.Core.State.AttributeInfo {
63- name: :web_prefix ,
64- positions: [ { 4 , 5 } ] ,
65- type: { :atom , ExampleWeb }
66- }
67- ] ,
68- current_module: ExampleWeb.Router ,
69- specs: % { } ,
70- types: % { } ,
71- mods_funs: % { }
72- }
73-
74- assert { true , ExampleWeb } = Scope . within_scope ( buffer , binding )
75- end
35+ test "returns true and alias when nested within other scopes" do
36+ _define_existing_atom = ExampleWeb.Admin
37+ _define_existing_atom = Admin
7638
77- test "can expand variables" do
78- buffer = """
79- defmodule ExampleWeb.Router do
80- import Phoenix.Router
81- web_prefix = ExampleWweb
82-
83- scope "/", web_prefix do
84- get "/",
85- """
86-
87- binding = % Binding {
88- structs: % { } ,
89- variables: [
90- % ElixirSense.Core.State.VarInfo {
91- name: :web_prefix ,
92- positions: [ { 5 , 5 } ] ,
93- scope_id: 2 ,
94- is_definition: true ,
95- type: { :atom , ExampleWeb }
96- }
97- ] ,
98- attributes: [ ] ,
99- current_module: ExampleWeb.Router ,
100- specs: % { } ,
101- types: % { } ,
102- mods_funs: % { }
103- }
104-
105- assert { true , ExampleWeb } = Scope . within_scope ( buffer , binding )
106- end
39+ buffer = """
40+ scope "/", ExampleWeb do
41+ scope "/admin", Admin do
42+ get "/",
43+ """
10744
108- test "returns false" do
109- buffer = "get \" \\ \" ,"
45+ assert { true , ExampleWeb.Admin } = Scope . within_scope ( buffer )
46+ end
11047
111- assert { false , nil } = Scope . within_scope ( buffer )
48+ test "can expand module attributes" do
49+ buffer = """
50+ defmodule ExampleWeb.Router do
51+ import Phoenix.Router
52+ @web_prefix ExampleWweb
53+
54+ scope "/", @web_prefix do
55+ get "/",
56+ """
57+
58+ binding = % Binding {
59+ structs: % { } ,
60+ variables: [ ] ,
61+ attributes: [
62+ % ElixirSense.Core.State.AttributeInfo {
63+ name: :web_prefix ,
64+ positions: [ { 4 , 5 } ] ,
65+ type: { :atom , ExampleWeb }
66+ }
67+ ] ,
68+ current_module: ExampleWeb.Router ,
69+ specs: % { } ,
70+ types: % { } ,
71+ mods_funs: % { }
72+ }
73+
74+ assert { true , ExampleWeb } = Scope . within_scope ( buffer , binding )
75+ end
76+
77+ test "can expand variables" do
78+ buffer = """
79+ defmodule ExampleWeb.Router do
80+ import Phoenix.Router
81+ web_prefix = ExampleWweb
82+
83+ scope "/", web_prefix do
84+ get "/",
85+ """
86+
87+ binding = % Binding {
88+ structs: % { } ,
89+ variables: [
90+ % ElixirSense.Core.State.VarInfo {
91+ name: :web_prefix ,
92+ positions: [ { 5 , 5 } ] ,
93+ scope_id: 2 ,
94+ is_definition: true ,
95+ type: { :atom , ExampleWeb }
96+ }
97+ ] ,
98+ attributes: [ ] ,
99+ current_module: ExampleWeb.Router ,
100+ specs: % { } ,
101+ types: % { } ,
102+ mods_funs: % { }
103+ }
104+
105+ assert { true , ExampleWeb } = Scope . within_scope ( buffer , binding )
106+ end
107+
108+ test "returns false" do
109+ buffer = "get \" \\ \" ,"
110+
111+ assert { false , nil } = Scope . within_scope ( buffer )
112+ end
112113 end
113114 end
114115end
0 commit comments