-
-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathsmartparens-elixir-test.el
243 lines (209 loc) · 7.37 KB
/
smartparens-elixir-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
(require 'elixir-mode)
(require 'smartparens-elixir)
(defun sp-test-elixir-parse (initial sexp &optional back)
(declare (indent 1))
(sp-test-with-temp-buffer initial
(elixir-mode)
(should (equal (sp-get-thing back) sexp))))
(defun sp-test-insertion-elixir (initial keys result)
(sp-test-with-temp-buffer initial
(elixir-mode)
(execute-kbd-macro keys)
(sp-buffer-equals result)))
(ert-deftest sp-test-elixir-parse-defmodule-empty-forward ()
"Parse defmodule correctly"
(sp-test-elixir-parse "|defmodule HelloWorld do
end"
'(:beg 1 :end 28 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-defmodule-empty-backward ()
"Parse defmodule correctly"
(sp-test-elixir-parse "defmodule HelloWorld do
end|"
'(:beg 1 :end 28 :op "defmodule" :cl "end" :prefix "" :suffix "") :back))
(ert-deftest sp-test-elixir-parse-defmodule-with-method-forward ()
"Parse def correctly"
(sp-test-elixir-parse "|defmodule HelloWorld do
def hello od
IO.puts \"Hello world\"
end
end"
'(:beg 1 :end 75 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-defmodule-with-method-backward ()
"Parse def correctly"
(sp-test-elixir-parse "defmodule HelloWorld do
def hello od
IO.puts \"Hello world\"
end
end|"
'(:beg 1 :end 75 :op "defmodule" :cl "end" :prefix "" :suffix "") :back))
(ert-deftest sp-test-elixir-parse-defmodule-from-inside-forward ()
"Parse def correctly"
(sp-test-elixir-parse "defmodule HelloWorld do
def hello od
IO.puts \"Hello world\"
end|
end"
'(:beg 1 :end 75 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-def-forward ()
"Parse def correctly"
(sp-test-elixir-parse "defmodule HelloWorld do
|def hello od
IO.puts \"Hello world\"
end
end"
'(:beg 27 :end 71 :op "def" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-def-backward ()
"Parse def correctly"
(sp-test-elixir-parse "defmodule HelloWorld do
def hello od
IO.puts \"Hello world\"
end|
end"
'(:beg 27 :end 71 :op "def" :cl "end" :prefix "" :suffix "") :back))
(ert-deftest sp-test-elixir-parse-fn-multiline ()
"Parse fn-end pair"
(sp-test-elixir-parse "def la do
task = Task.async |fn ->
IO.puts \"remote print\"
:timer.sleep(1000)
end
IO.puts \"#{inspect Task.await task}\"
end"
'(:beg 31 :end 92 :op "fn" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-if-forward ()
"Parse if-end pair"
(sp-test-elixir-parse "def world do
|if true do
IO.puts \"hello\"
end
unless false do
IO.puts \"world\"
end
end"
'(:beg 16 :end 52 :op "if" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-unless-forward ()
"Parse if-end pair"
(sp-test-elixir-parse "def world do
if true do
IO.puts \"hello\"
end
|unless false do
IO.puts \"world\"
end
end"
'(:beg 56 :end 97 :op "unless" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-bodyless-def ()
"Parse bodyless def correctly"
(sp-test-elixir-parse "|defmodule HelloWorld do
def hello
def hello do
IO.puts \"Hello world\"
end
end"
'(:beg 1 :end 87 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-bodyless-def-w-keyword-list ()
"Parse bodyless defp correctly with keyword-list body"
(sp-test-elixir-parse "|defmodule HelloWorld do
def hello
def hello, do: IO.puts \"Hello world\"
end"
'(:beg 1 :end 79 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-bodyless-defp ()
"Parse bodyless defp correctly"
(sp-test-elixir-parse "|defmodule HelloWorld do
defp hello
defp hello do
IO.puts \"Hello world\"
end
end"
'(:beg 1 :end 89 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-bodyless-defp-w-keyword-list ()
"Parse bodyless defp correctly with keyword-list body"
(sp-test-elixir-parse "|defmodule HelloWorld do
defp hello
defp hello, do: IO.puts \"Hello world\"
end"
'(:beg 1 :end 81 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-keyword-def ()
"Parse def with do: keyword correctly"
(sp-test-elixir-parse "|defmodule HelloWorld do
def hello, do: IO.puts \"Hello world\"
end"
'(:beg 1 :end 67 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-multiline-keyword-def ()
"Parse multiline def with do: keyword correctly"
(sp-test-elixir-parse "|defmodule HelloWorld do
def hello,
do:
IO.puts \"Hello world\"
end"
'(:beg 1 :end 73 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-keyword-defp ()
"Parse oneline defp with do: keyword correctly"
(sp-test-elixir-parse "|defmodule HelloWorld do
defp hello, do: IO.puts \"Hello world\"
end"
'(:beg 1 :end 68 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-multiline-keyword-defp ()
"Parse multiline defp with do: keyword correctly"
(sp-test-elixir-parse "|defmodule HelloWorld do
defp hello,
do:
IO.puts \"Hello world\"
end"
'(:beg 1 :end 74 :op "defmodule" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-defimpl-with-for-keyword ()
"Parse defimpl with for: keyword."
(sp-test-elixir-parse "|defimpl Type, for: OtherType do
for n <- [1, 2, 3], do: n * n
end"
'(:beg 1 :end 68 :op "defimpl" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-parse-with ()
"Parse with statement."
(sp-test-elixir-parse "|with {:ok, val} <- foo() do
val
else
:err
end"
'(:beg 1 :end 50 :op "with" :cl "end" :prefix "" :suffix "")))
(ert-deftest sp-test-elixir-receive-block-insertion ()
(sp-test-insertion-elixir "|" "receive" "receive do
|
end"))
(ert-deftest sp-test-elixir-case-block-insertion ()
(sp-test-insertion-elixir "|" "case " "case | do
end"))
(ert-deftest sp-test-elixir-if-block-insertion-in-comment ()
(sp-test-insertion-elixir "# comment |" "if " "# comment if |"))
(ert-deftest sp-test-elixir-if-block-insertion-in-string ()
(sp-test-insertion-elixir "\"a string |" "if " "\"a string if |"))
;; The naming convention is broken but for some reason there is a
;; race-condition which makes this test to fail later. So we prefix
;; with 1-
(ert-deftest 1-sp-test-elixir-do-block-insertion-in-string ()
(sp-test-insertion-elixir "\"a string |" "do " "\"a string do |"))
(ert-deftest sp-test-elixir-forward-slurp ()
"Ensure that commas are handled properly when slurping forward"
(sp-test-with-temp-buffer "[1, [|2], :a]"
(elixir-mode)
(sp-forward-slurp-sexp)
(should (equal (buffer-string) "[1, [2, :a]]"))))
(ert-deftest sp-test-elixir-backward-slurp ()
"Ensure that commas are handled properly when slurping backward"
(sp-test-with-temp-buffer "[1,[|2],:a]"
(elixir-mode)
(sp-backward-slurp-sexp)
(should (equal (buffer-string) "[[1,2],:a]"))))
(ert-deftest sp-test-elixir-forward-barf ()
"Ensure that commas are handled properly when barfing forward"
(sp-test-with-temp-buffer "{1, {2,|:a}}"
(elixir-mode)
(sp-forward-barf-sexp)
(should (equal (buffer-string) "{1, {2},:a}"))))
(ert-deftest sp-test-elixir-backward-barf ()
"Ensure that commas are handled properly when barfing backward"
(sp-test-with-temp-buffer "{1,{2,|:a}}"
(elixir-mode)
(sp-backward-barf-sexp)
(should (equal (buffer-string) "{1,2,{:a}}"))))