@@ -3,26 +3,26 @@ defmodule ElixirLS.LanguageServer.Providers.CodeLens.TypeSpec.ContractTranslator
3
3
alias ElixirLS.LanguageServer.Providers.CodeLens.TypeSpec.ContractTranslator
4
4
5
5
test "translate struct when struct.t type exists" do
6
- contract = ' () -> \# {\ ' __struct__\ ' :=\ ' Elixir.DateTime\' }'
6
+ contract = ~c " () -> \# {'__struct__':='Elixir.DateTime'} "
7
7
8
8
assert "foo :: DateTime.t()" ==
9
9
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
10
10
end
11
11
12
12
test "don't translate struct when struct.t type does not exist" do
13
- contract = ' () -> \# {\ ' __struct__\ ' :=\ ' Elixir.SomeOtherStruct\' }'
13
+ contract = ~c " () -> \# {'__struct__':='Elixir.SomeOtherStruct'} "
14
14
15
15
assert "foo :: %SomeOtherStruct{}" ==
16
16
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
17
17
end
18
18
19
19
test "struct" do
20
- contract = ' () -> \# {\ ' __struct__\ ' :=atom(), atom()=>any()}'
20
+ contract = ~c " () -> \# {'__struct__':=atom(), atom()=>any()}"
21
21
assert "foo :: struct" == ContractTranslator . translate_contract ( :foo , contract , false , Atom )
22
22
end
23
23
24
24
test "drop macro env argument" do
25
- contract = ' (any(), integer()) -> integer()'
25
+ contract = ~c " (any(), integer()) -> integer()"
26
26
27
27
assert "foo(any, integer) :: integer" ==
28
28
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
@@ -32,119 +32,119 @@ defmodule ElixirLS.LanguageServer.Providers.CodeLens.TypeSpec.ContractTranslator
32
32
end
33
33
34
34
test "atom :ok" do
35
- contract = ' (any()) -> ok'
35
+ contract = ~c " (any()) -> ok"
36
36
assert "foo(any) :: :ok" == ContractTranslator . translate_contract ( :foo , contract , false , Atom )
37
37
end
38
38
39
39
test "atom true" do
40
- contract = ' (any()) -> true'
40
+ contract = ~c " (any()) -> true"
41
41
42
42
assert "foo(any) :: true" ==
43
43
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
44
44
end
45
45
46
46
test "atom _ substitution" do
47
- contract = ' (_) -> false'
47
+ contract = ~c " (_) -> false"
48
48
49
49
assert "foo(any) :: false" ==
50
50
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
51
51
end
52
52
53
53
test "do not drop when substitutions" do
54
- contract = ' (X) -> atom() when X :: any()'
54
+ contract = ~c " (X) -> atom() when X :: any()"
55
55
56
56
assert "foo(x) :: atom when x: any" ==
57
57
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
58
58
end
59
59
60
60
test "keyword" do
61
- contract = ' (any()) -> list({atom(), any()})'
61
+ contract = ~c " (any()) -> list({atom(), any()})"
62
62
63
63
assert "foo(any) :: keyword" ==
64
64
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
65
65
66
- contract = ' (any()) -> list({atom(), _})'
66
+ contract = ~c " (any()) -> list({atom(), _})"
67
67
68
68
assert "foo(any) :: keyword" ==
69
69
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
70
70
end
71
71
72
72
test "keyword(t)" do
73
- contract = ' (any()) -> list({atom(), integer()})'
73
+ contract = ~c " (any()) -> list({atom(), integer()})"
74
74
75
75
assert "foo(any) :: keyword(integer)" ==
76
76
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
77
77
end
78
78
79
79
test "[type]" do
80
- contract = ' (any()) -> list(atom())'
80
+ contract = ~c " (any()) -> list(atom())"
81
81
82
82
assert "foo(any) :: [atom]" ==
83
83
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
84
84
end
85
85
86
86
test "list" do
87
- contract = ' (any()) -> list(any())'
87
+ contract = ~c " (any()) -> list(any())"
88
88
89
89
assert "foo(any) :: list" ==
90
90
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
91
91
end
92
92
93
93
test "empty list" do
94
- contract = ' (any()) -> []'
94
+ contract = ~c " (any()) -> []"
95
95
assert "foo(any) :: []" == ContractTranslator . translate_contract ( :foo , contract , false , Atom )
96
96
end
97
97
98
98
test "[...]" do
99
- contract = ' (any()) -> nonempty_list(any())'
99
+ contract = ~c " (any()) -> nonempty_list(any())"
100
100
101
101
assert "foo(any) :: [...]" ==
102
102
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
103
103
104
- contract = ' (any()) -> nonempty_list(_)'
104
+ contract = ~c " (any()) -> nonempty_list(_)"
105
105
106
106
assert "foo(any) :: [...]" ==
107
107
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
108
108
end
109
109
110
110
test "[type, ...]" do
111
- contract = ' (any()) -> nonempty_list(atom())'
111
+ contract = ~c " (any()) -> nonempty_list(atom())"
112
112
113
113
assert "foo(any) :: [atom, ...]" ==
114
114
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
115
115
end
116
116
117
117
test "undoes conversion of :_ to any inside bitstring" do
118
- contract = ' (any()) -> <<_:2, _:_*3>>'
118
+ contract = ~c " (any()) -> <<_:2, _:_*3>>"
119
119
120
120
assert "foo(any) :: <<_::2, _::_*3>>" ==
121
121
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
122
122
end
123
123
124
124
test "function" do
125
- contract = ' (any()) -> fun((...) -> ok)'
125
+ contract = ~c " (any()) -> fun((...) -> ok)"
126
126
127
127
assert "foo(any) :: (... -> :ok)" ==
128
128
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
129
129
end
130
130
131
131
test "fun" do
132
- contract = ' (any()) -> fun((...) -> any())'
132
+ contract = ~c " (any()) -> fun((...) -> any())"
133
133
assert "foo(any) :: fun" == ContractTranslator . translate_contract ( :foo , contract , false , Atom )
134
134
end
135
135
136
136
test "empty map" do
137
- contract = ' (any()) -> \# {}'
137
+ contract = ~c " (any()) -> \# {}"
138
138
assert "foo(any) :: %{}" == ContractTranslator . translate_contract ( :foo , contract , false , Atom )
139
139
end
140
140
141
141
test "map" do
142
- contract = ' (any()) -> \# {any()=>any()}'
142
+ contract = ~c " (any()) -> \# {any()=>any()}"
143
143
assert "foo(any) :: map" == ContractTranslator . translate_contract ( :foo , contract , false , Atom )
144
144
end
145
145
146
146
test "map with fields" do
147
- contract = ' (any()) -> \# {integer()=>any(), 1:=atom(), abc:=4}'
147
+ contract = ~c " (any()) -> \# {integer()=>any(), 1:=atom(), abc:=4}"
148
148
149
149
expected =
150
150
if Version . match? ( System . version ( ) , "< 1.13.0" ) do
@@ -158,32 +158,32 @@ defmodule ElixirLS.LanguageServer.Providers.CodeLens.TypeSpec.ContractTranslator
158
158
end
159
159
160
160
test "defprotocol type t" do
161
- contract = ' (any()) -> any()'
161
+ contract = ~c " (any()) -> any()"
162
162
163
163
assert "foo(t) :: any" ==
164
164
ContractTranslator . translate_contract ( :foo , contract , false , Enumerable )
165
165
166
- contract = ' (any(), any()) -> any()'
166
+ contract = ~c " (any(), any()) -> any()"
167
167
168
168
assert "foo(t, any) :: any" ==
169
169
ContractTranslator . translate_contract ( :foo , contract , false , Enumerable )
170
170
171
- contract = ' (any()) -> any()'
171
+ contract = ~c " (any()) -> any()"
172
172
assert "foo(any) :: any" == ContractTranslator . translate_contract ( :foo , contract , false , Atom )
173
173
174
- contract = ' (any(), any()) -> any()'
174
+ contract = ~c " (any(), any()) -> any()"
175
175
176
176
assert "foo(any, any) :: any" ==
177
177
ContractTranslator . translate_contract ( :foo , contract , false , Atom )
178
178
end
179
179
180
180
test "defimpl first arg" do
181
- contract = ' (any()) -> any()'
181
+ contract = ~c " (any()) -> any()"
182
182
183
183
assert "count(list) :: any" ==
184
184
ContractTranslator . translate_contract ( :count , contract , false , Enumerable.List )
185
185
186
- contract = ' (any()) -> any()'
186
+ contract = ~c " (any()) -> any()"
187
187
188
188
assert "count(Date.Range.t()) :: any" ==
189
189
ContractTranslator . translate_contract ( :count , contract , false , Enumerable.Date.Range )
0 commit comments