aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorbug-gnu-emacs@gnu.org2023-09-11 10:03:13 -0500
committerEli Zaretskii2023-09-16 13:01:43 +0300
commitb6659e98a4fcaa44477b64d7782243feca020418 (patch)
treee1d3617bba53898349f50652c4c028b09af274dd /test
parent2ea98ea35c82da31ef419da3b49789ab750e8e00 (diff)
downloademacs-b6659e98a4fcaa44477b64d7782243feca020418.tar.gz
emacs-b6659e98a4fcaa44477b64d7782243feca020418.zip
bug#65673: Add lua-ts-mode
* lisp/progmodes/lua-ts-mode.el: * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: * test/lisp/progmodes/lua-ts-mode-tests.el: New files. * etc/NEWS: Mention the new mode. * lisp/progmodes/eglot.el (eglot-server-programs): * lisp/progmodes/hideshow.el (hs-special-modes-alist): Support 'lua-ts-mode'. * admin/notes/tree-sitter/build-module/batch.sh: * admin/notes/tree-sitter/build-module/build.sh: Add Lua. * test/infra/Dockerfile.emba: * test/infra/test-jobs.yml: Include lua-ts-mode tests.
Diffstat (limited to 'test')
-rw-r--r--test/infra/Dockerfile.emba1
-rw-r--r--test/infra/test-jobs.yml1
-rw-r--r--test/lisp/progmodes/lua-ts-mode-resources/indent.erts152
-rw-r--r--test/lisp/progmodes/lua-ts-mode-resources/movement.erts553
-rw-r--r--test/lisp/progmodes/lua-ts-mode-tests.el36
5 files changed, 743 insertions, 0 deletions
diff --git a/test/infra/Dockerfile.emba b/test/infra/Dockerfile.emba
index 584e4444dc1..e29098ec270 100644
--- a/test/infra/Dockerfile.emba
+++ b/test/infra/Dockerfile.emba
@@ -126,6 +126,7 @@ RUN src/emacs -Q --batch \
126 (java "https://github.com/tree-sitter/tree-sitter-java") \ 126 (java "https://github.com/tree-sitter/tree-sitter-java") \
127 (javascript "https://github.com/tree-sitter/tree-sitter-javascript") \ 127 (javascript "https://github.com/tree-sitter/tree-sitter-javascript") \
128 (json "https://github.com/tree-sitter/tree-sitter-json") \ 128 (json "https://github.com/tree-sitter/tree-sitter-json") \
129 (lua "https://github.com/MunifTanjim/tree-sitter-lua") \
129 (python "https://github.com/tree-sitter/tree-sitter-python") \ 130 (python "https://github.com/tree-sitter/tree-sitter-python") \
130 (ruby "https://github.com/tree-sitter/tree-sitter-ruby") \ 131 (ruby "https://github.com/tree-sitter/tree-sitter-ruby") \
131 (tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src") \ 132 (tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src") \
diff --git a/test/infra/test-jobs.yml b/test/infra/test-jobs.yml
index 2f6e0dab4d5..1f5d607eda4 100644
--- a/test/infra/test-jobs.yml
+++ b/test/infra/test-jobs.yml
@@ -580,6 +580,7 @@ test-src-inotify:
580 lisp/progmodes/go-ts-mode-tests.log 580 lisp/progmodes/go-ts-mode-tests.log
581 lisp/progmodes/heex-ts-mode-tests.log 581 lisp/progmodes/heex-ts-mode-tests.log
582 lisp/progmodes/java-ts-mode-tests.log 582 lisp/progmodes/java-ts-mode-tests.log
583 lisp/progmodes/lua-ts-mode-tests.log
583 lisp/progmodes/ruby-ts-mode-tests.log 584 lisp/progmodes/ruby-ts-mode-tests.log
584 lisp/progmodes/typescript-ts-mode-tests.log 585 lisp/progmodes/typescript-ts-mode-tests.log
585 src/treesit-tests.log 586 src/treesit-tests.log
diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts
new file mode 100644
index 00000000000..040225c8580
--- /dev/null
+++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts
@@ -0,0 +1,152 @@
1Code:
2 (lambda ()
3 (setq indent-tabs-mode nil)
4 (setq lua-ts-indent-offset 2)
5 (lua-ts-mode)
6 (indent-region (point-min) (point-max)))
7
8Name: Basic Indent
9
10=-=
11 print(
120,
13 1
14)
15
16local function f(o)
17 if o.x > o.y then
18 return o.x
19elseif o.y > o.z then
20 return o.y
21 else
22return o.z
23 end
24end
25
26f({
27 x = 1,
28 y = 2,
29 z = 3,
30})
31
32;(function()
33return false
34)()
35=-=
36print(
37 0,
38 1
39)
40
41local function f(o)
42 if o.x > o.y then
43 return o.x
44 elseif o.y > o.z then
45 return o.y
46 else
47 return o.z
48 end
49end
50
51f({
52 x = 1,
53 y = 2,
54 z = 3,
55})
56
57;(function()
58 return false
59)()
60=-=-=
61
62Name: Argument Indent
63
64=-=
65function h(
66string,
67number,
68options)
69print(string, number, options)
70end
71
72local p = h(
73"sring",
74 1000,
75 {
76cost = 2,
77length = 8,
78 parallelism = 4,
79})
80=-=
81function h(
82 string,
83 number,
84 options)
85 print(string, number, options)
86end
87
88local p = h(
89 "sring",
90 1000,
91 {
92 cost = 2,
93 length = 8,
94 parallelism = 4,
95 })
96=-=-=
97
98Name: Continuation Indent
99
100=-=
101function f()
102 local str = [[
103 multi-line
104 string
105 ]]
106--[[
107multi-line
108comment
109 ]]
110return true
111end
112=-=
113function f()
114 local str = [[
115 multi-line
116 string
117 ]]
118 --[[
119multi-line
120comment
121 ]]
122 return true
123end
124=-=-=
125
126Name: Loop Indent
127
128=-=
129for k, v in pairs({}) do
130 print(k, v)
131end
132
133while n < 10 do
134n = n + 1
135end
136
137repeat
138z = z * 2
139 until z > 12
140=-=
141for k, v in pairs({}) do
142 print(k, v)
143end
144
145while n < 10 do
146 n = n + 1
147end
148
149repeat
150 z = z * 2
151until z > 12
152=-=-=
diff --git a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts
new file mode 100644
index 00000000000..770aa23b18d
--- /dev/null
+++ b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts
@@ -0,0 +1,553 @@
1Code:
2 (lambda ()
3 (lua-ts-mode)
4 (beginning-of-defun 1))
5
6Point-Char: |
7
8Name: beginning-of-defun moves to start of function declaration
9
10=-=
11local function Test()
12 if true then
13 print(1)
14 else
15 print(0)
16 end|
17end
18=-=
19|local function Test()
20 if true then
21 print(1)
22 else
23 print(0)
24 end
25end
26=-=-=
27
28Name: beginning-of-defun moves to start of function definition
29
30=-=
31local t = {
32 f = function()
33 return true
34 end,
35}|
36=-=
37local t = {
38| f = function()
39 return true
40 end,
41}
42=-=-=
43
44Code:
45 (lambda ()
46 (lua-ts-mode)
47 (end-of-defun 1))
48
49Point-Char: |
50
51Name: end-of-defun moves to end of function declaration
52
53=-=
54local function Test()
55 if true then
56 pr|int(1)
57 else
58 print(0)
59 end
60end
61
62local t = Test()
63=-=
64local function Test()
65 if true then
66 print(1)
67 else
68 print(0)
69 end
70end
71|
72local t = Test()
73=-=-=
74
75Name: end-of-defun moves to end of function definition
76
77=-=
78local t = {
79 f = function()
80 re|turn true
81 end,
82}
83=-=
84local t = {
85 f = function()
86 return true
87 end|,
88}
89=-=-=
90
91Code:
92 (lambda ()
93 (lua-ts-mode)
94 (forward-sentence 1))
95
96Point-Char: |
97
98Name: forward-sentence moves over if statements
99
100=-=
101function f()
102 |if true then
103 print(1)
104 elseif false then
105 print(0)
106 else
107 print(2)
108 end
109end
110=-=
111function f()
112 if true then
113 print(1)
114 elseif false then
115 print(0)
116 else
117 print(2)
118 end|
119end
120=-=-=
121
122Name: forward-sentence moves over variable declaration
123
124=-=
125|local n = 1
126
127print(n)
128=-=
129local n = 1|
130
131print(n)
132=-=-=
133
134Name: forward-sentence moves over for statements
135
136=-=
137|for k, v in pairs({}) do
138 print(k, v)
139end
140
141print(1)
142=-=
143for k, v in pairs({}) do
144 print(k, v)
145end|
146
147print(1)
148=-=-=
149
150Name: forward-sentence moves over for statements
151
152=-=
153|do
154 local x = 1
155 local y = 2
156
157 print(x, y)
158end
159
160print(1)
161=-=
162do
163 local x = 1
164 local y = 2
165
166 print(x, y)
167end|
168
169print(1)
170=-=-=
171
172Name: forward-sentence moves over while statements
173
174=-=
175local i = 0
176|while i < 9 do
177 print(i)
178 i = i + 1
179end
180
181print(1)
182=-=
183local i = 0
184while i < 9 do
185 print(i)
186 i = i + 1
187end|
188
189print(1)
190=-=-=
191
192Name: forward-sentence moves over repeat statements
193
194=-=
195local i = 0
196|repeat
197 print(i)
198 i = i + 1
199until i > 9
200
201print(1)
202=-=
203local i = 0
204repeat
205 print(i)
206 i = i + 1
207until i > 9|
208
209print(1)
210=-=-=
211
212Name: forward-sentence moves over function calls
213
214=-=
215|print(1)
216=-=
217print(1)|
218=-=-=
219
220Name: forward-sentence moves over return statements
221
222=-=
223function f()
224 |return math.random()
225end
226=-=
227function f()
228 return math.random()|
229end
230=-=-=
231
232Code:
233 (lambda ()
234 (lua-ts-mode)
235 (forward-sentence 2))
236
237Name: forward-sentence moves over table fields
238
239=-=
240local t = {
241 |a = 1,
242 b = 2,
243}
244=-=
245local t = {
246 a = 1,
247 b = 2|,
248}
249=-=-=
250
251Code:
252 (lambda ()
253 (lua-ts-mode)
254 (backward-sentence 1))
255
256Point-Char: |
257
258Name: backward-sentence moves over if statements
259
260=-=
261function f()
262 if true then
263 print(1)
264 elseif false then
265 print(0)
266 else
267 print(2)
268 end|
269end
270=-=
271function f()
272 |if true then
273 print(1)
274 elseif false then
275 print(0)
276 else
277 print(2)
278 end
279end
280=-=-=
281
282Name: backward-sentence moves over variable declaration
283
284=-=
285local n = 1|
286
287print(n)
288=-=
289|local n = 1
290
291print(n)
292=-=-=
293
294Name: backward-sentence moves over for statements
295
296=-=
297for k, v in pairs({}) do
298 print(k, v)
299end|
300
301print(1)
302=-=
303|for k, v in pairs({}) do
304 print(k, v)
305end
306
307print(1)
308=-=-=
309
310Name: backward-sentence moves over for statements
311
312=-=
313do
314 local x = 1
315 local y = 2
316
317 print(x, y)
318end|
319
320print(1)
321=-=
322|do
323 local x = 1
324 local y = 2
325
326 print(x, y)
327end
328
329print(1)
330=-=-=
331
332Name: backward-sentence moves over while statements
333
334=-=
335local i = 0
336while i < 9 do
337 print(i)
338 i = i + 1
339end|
340
341print(1)
342=-=
343local i = 0
344|while i < 9 do
345 print(i)
346 i = i + 1
347end
348
349print(1)
350=-=-=
351
352Name: backward-sentence moves over repeat statements
353
354=-=
355local i = 0
356repeat
357 print(i)
358 i = i + 1
359until i > 9|
360
361print(1)
362=-=
363local i = 0
364|repeat
365 print(i)
366 i = i + 1
367until i > 9
368
369print(1)
370=-=-=
371
372Name: backward-sentence moves over function calls
373
374=-=
375print(1)|
376=-=
377|print(1)
378=-=-=
379
380Name: backward-sentence moves over return statements
381
382=-=
383function f()
384 return math.random()|
385end
386=-=
387function f()
388 |return math.random()
389end
390=-=-=
391
392Code:
393 (lambda ()
394 (lua-ts-mode)
395 (backward-sentence 2))
396
397Point-Char: |
398
399Name: backward-sentence moves over table fields
400
401=-=
402local t = {
403 a = 1,
404 b = 2|,
405}
406=-=
407local t = {
408 |a = 1,
409 b = 2,
410}
411=-=-=
412
413Code:
414 (lambda ()
415 (lua-ts-mode)
416 (forward-sexp 1))
417
418Point-Char: |
419
420Name: forward-sexp moves over blocks
421
422=-=
423local function Test()
424 |local t = {
425 a = 1,
426 }
427
428 if true then
429 print(1)
430 else
431 print(0)
432 end
433end
434=-=
435local function Test()
436 local t = {
437 a = 1,
438 }
439
440 if true then
441 print(1)
442 else
443 print(0)
444 end|
445end
446=-=-=
447
448Name: forward-sexp moves over arguments
449
450=-=
451print|(1, 2, 3)
452=-=
453print(1, 2, 3)|
454=-=-=
455
456Name: forward-sexp moves over parameters
457
458=-=
459function f|(a, b) end
460=-=
461function f(a, b)| end
462=-=-=
463
464Name: forward-sexp moves over strings
465
466=-=
467print("|1, 2, 3")
468=-=
469print("1, 2, 3|")
470=-=-=
471
472Name: forward-sexp moves over tables
473
474=-=
475local t = |{ 1,
476 2,
477 3 }
478=-=
479local t = { 1,
480 2,
481 3 }|
482=-=-=
483
484Code:
485 (lambda ()
486 (lua-ts-mode)
487 (backward-sexp 1))
488
489Point-Char: |
490
491Name: backward-sexp moves over blocks
492
493=-=
494local function Test()
495 local t = {
496 a = 1,
497 }
498
499 if true then
500 print(1)
501 else
502 print(0)
503 end|
504end
505=-=
506local function Test()
507 |local t = {
508 a = 1,
509 }
510
511 if true then
512 print(1)
513 else
514 print(0)
515 end
516end
517=-=-=
518
519Name: backward-sexp moves over arguments
520
521=-=
522print(1, 2, 3)|
523=-=
524print|(1, 2, 3)
525=-=-=
526
527Name: backward-sexp moves over parameters
528
529=-=
530function f(a, b)| end
531=-=
532function f|(a, b) end
533=-=-=
534
535Name: backward-sexp moves over strings
536
537=-=
538print("1, 2, 3|")
539=-=
540print("|1, 2, 3")
541=-=-=
542
543Name: backward-sexp moves over tables
544
545=-=
546local t = { 1,
547 2,
548 3 }|
549=-=
550local t = |{ 1,
551 2,
552 3 }
553=-=-=
diff --git a/test/lisp/progmodes/lua-ts-mode-tests.el b/test/lisp/progmodes/lua-ts-mode-tests.el
new file mode 100644
index 00000000000..d2105b66f6d
--- /dev/null
+++ b/test/lisp/progmodes/lua-ts-mode-tests.el
@@ -0,0 +1,36 @@
1;;; lua-ts-mode-tests.el --- Tests for lua-ts-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 lua-ts-mode-test-indentation ()
27 (skip-unless (treesit-ready-p 'lua))
28 (ert-test-erts-file (ert-resource-file "indent.erts")))
29
30(ert-deftest lua-ts-mode-test-movement ()
31 (skip-unless (treesit-ready-p 'lua))
32 (ert-test-erts-file (ert-resource-file "movement.erts")))
33
34(provide 'lua-ts-mode-tests)
35
36;;; lua-ts-mode-tests.el ends here