aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorWilhelm H Kirschbaum2023-03-12 17:10:43 +0200
committerEli Zaretskii2023-03-12 17:41:44 +0200
commitd965d030879d9ca4ef5098cb4e2e7c56128b904b (patch)
tree8ab985a3946eac5e52417f7bb32b012db3db0af5 /test
parent802e64922bcee40c8362b9627aa33a0de0c068d7 (diff)
downloademacs-d965d030879d9ca4ef5098cb4e2e7c56128b904b.tar.gz
emacs-d965d030879d9ca4ef5098cb4e2e7c56128b904b.zip
Add elixir-ts-mode (Bug#61996)
* etc/NEWS: Mention the new mode. * lisp/progmodes/elixir-ts-mode.el: New file. * test/lisp/progmodes/elixir-ts-mode-tests.el: New file. * test/lisp/progmodes/elixir-ts-mode-resources/indent.erts: New file. * admin/notes/tree-sitter/build-module/batch.sh: * admin/notes/tree-sitter/build-module/build.sh: Add Elixir support. * lisp/progmodes/eglot.el (eglot-server-programs): Add elixir-ts-mode.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/progmodes/elixir-ts-mode-resources/indent.erts308
-rw-r--r--test/lisp/progmodes/elixir-ts-mode-tests.el31
2 files changed, 339 insertions, 0 deletions
diff --git a/test/lisp/progmodes/elixir-ts-mode-resources/indent.erts b/test/lisp/progmodes/elixir-ts-mode-resources/indent.erts
new file mode 100644
index 00000000000..748455cc3f2
--- /dev/null
+++ b/test/lisp/progmodes/elixir-ts-mode-resources/indent.erts
@@ -0,0 +1,308 @@
1Code:
2 (lambda ()
3 (setq indent-tabs-mode nil)
4 (elixir-ts-mode)
5 (indent-region (point-min) (point-max)))
6
7Point-Char: $
8
9Name: Basic modules
10
11=-=
12 defmodule Foobar do
13def bar() do
14"one"
15 end
16 end
17=-=
18defmodule Foobar do
19 def bar() do
20 "one"
21 end
22end
23=-=-=
24
25Name: Map
26
27=-=
28map = %{
29 "a" => 1,
30 "b" => 2
31}
32=-=-=
33
34Name: Map in function def
35
36=-=
37def foobar() do
38 %{
39 one: "one",
40 two: "two",
41 three: "three",
42 four: "four"
43 }
44end
45=-=-=
46
47Name: Map in tuple
48
49=-=
50def foo() do
51 {:ok,
52 %{
53 state
54 | extra_arguments: extra_arguments,
55 max_children: max_children,
56 max_restarts: max_restarts,
57 max_seconds: max_seconds,
58 strategy: strategy
59 }}
60end
61=-=-=
62
63Name: Nested maps
64
65=-=
66%{
67 foo: "bar",
68 bar: %{
69 foo: "bar"
70 }
71}
72
73def foo() do
74 %{
75 foo: "bar",
76 bar: %{
77 foo: "bar"
78 }
79 }
80end
81=-=-=
82
83Name: Block assignments
84
85=-=
86foo =
87 if true do
88 "yes"
89 else
90 "no"
91 end
92=-=-=
93
94Name: Function rescue
95
96=-=
97def foo do
98 "bar"
99rescue
100 e ->
101 "bar"
102end
103=-=-=
104
105Name: With statement
106=-=
107with one <- one(),
108 two <- two(),
109 {:ok, value} <- get_value(one, two) do
110 {:ok, value}
111else
112 {:error, %{"Message" => message}} ->
113 {:error, message}
114end
115=-=-=
116
117Name: Pipe statements with fn
118
119=-=
120[1, 2]
121|> Enum.map(fn num ->
122 num + 1
123end)
124=-=-=
125
126Name: Pipe statements stab clases
127
128=-=
129[1, 2]
130|> Enum.map(fn
131 x when x < 10 -> x * 2
132 x -> x * 3
133end)
134=-=-=
135
136Name: Pipe statements params
137
138=-=
139[1, 2]
140|> foobar(
141 :one,
142 :two,
143 :three,
144 :four
145)
146=-=-=
147
148Name: Parameter maps
149
150=-=
151def something(%{
152 one: :one,
153 two: :two
154 }) do
155 {:ok, "done"}
156end
157=-=-=
158
159Name: Binary operator in else block
160
161=-=
162defp foobar() do
163 if false do
164 :foo
165 else
166 :bar |> foo
167 end
168end
169=-=-=
170
171Name: Tuple indentation
172
173=-=
174tuple = {
175 :one,
176 :two
177}
178
179{
180 :one,
181 :two
182}
183=-=-=
184
185Name: Spec and method
186
187=-=
188@spec foobar(
189 t,
190 acc,
191 (one, something -> :bar | far),
192 (two -> :bar | far)
193 ) :: any()
194 when chunk: any
195def foobar(enumerable, acc, chunk_fun, after_fun) do
196 {_, {res, acc}} =
197 case after_fun.(acc) do
198 {:one, "one"} ->
199 "one"
200
201 {:two, "two"} ->
202 "two"
203 end
204end
205=-=-=
206
207Name: Spec with multi-line result
208
209=-=
210@type result ::
211 {:done, term}
212 | {:two}
213 | {:one}
214
215@type result ::
216 {
217 :done,
218 term
219 }
220 | {:two}
221 | {:one}
222
223@type boo_bar ::
224 (foo :: pos_integer, bar :: pos_integer -> any())
225
226@spec foo_bar(
227 t,
228 (foo -> any),
229 (() -> any) | (foo, foo -> boolean) | module()
230 ) :: any
231 when foo: any
232def foo(one, fun, other)
233=-=-=
234
235Name: String concatenation in call
236
237=-=
238IO.warn(
239 "one" <>
240 "two" <>
241 "bar"
242)
243
244IO.warn(
245 "foo" <>
246 "bar"
247)
248=-=-=
249
250Name: Incomplete tuple
251
252=-=
253map = {
254:foo
255
256=-=
257map = {
258 :foo
259
260=-=-=
261
262Name: Incomplete map
263
264=-=
265map = %{
266 "a" => "a",
267=-=-=
268
269Name: Incomplete list
270
271=-=
272map = [
273:foo
274
275=-=
276map = [
277 :foo
278
279=-=-=
280
281Name: String concatenation
282
283=-=
284"one" <>
285 "two" <>
286 "three" <>
287 "four"
288=-=-=
289
290Name: Tuple with same line first node
291
292=-=
293{:one,
294 :two}
295
296{:ok,
297 fn one ->
298 one
299 |> String.upcase(one)
300 end}
301=-=-=
302
303Name: Long tuple
304
305=-=
306{"January", "February", "March", "April", "May", "June", "July", "August", "September",
307 "October", "November", "December"}
308=-=-=
diff --git a/test/lisp/progmodes/elixir-ts-mode-tests.el b/test/lisp/progmodes/elixir-ts-mode-tests.el
new file mode 100644
index 00000000000..8e546ad5cc6
--- /dev/null
+++ b/test/lisp/progmodes/elixir-ts-mode-tests.el
@@ -0,0 +1,31 @@
1;;; c-ts-mode-tests.el --- Tests for Tree-sitter-based C mode -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2023 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23(require 'ert-x)
24(require 'treesit)
25
26(ert-deftest elixir-ts-mode-test-indentation ()
27 (skip-unless (and (treesit-ready-p 'elixir) (treesit-ready-p 'heex)))
28 (ert-test-erts-file (ert-resource-file "indent.erts")))
29
30(provide 'elixir-ts-mode-tests)
31;;; elixir-ts-mode-tests.el ends here