aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp/progmodes
diff options
context:
space:
mode:
authorjohn muhl2025-03-21 12:15:02 -0500
committerPo Lu2025-08-25 09:59:04 +0800
commitc5656af2ff5f2ee4a683540db792ccece6db4e43 (patch)
treedd0eaaab38f36e99b9613854243da73bb5a906bd /test/lisp/progmodes
parent38a07757425c711e037c526f2c76d342a81e7c17 (diff)
downloademacs-c5656af2ff5f2ee4a683540db792ccece6db4e43.tar.gz
emacs-c5656af2ff5f2ee4a683540db792ccece6db4e43.zip
; Add tests for 'lua-mode'
* test/lisp/progmodes/lua-mode-resources/font-lock.lua: * test/lisp/progmodes/lua-mode-resources/hide-show.lua: * test/lisp/progmodes/lua-mode-resources/indent.erts: * test/lisp/progmodes/lua-mode-resources/movement.erts: * test/lisp/progmodes/lua-mode-resources/which-function.lua: * test/lisp/progmodes/lua-mode-tests.el: New file.
Diffstat (limited to 'test/lisp/progmodes')
-rw-r--r--test/lisp/progmodes/lua-mode-resources/font-lock.lua184
-rw-r--r--test/lisp/progmodes/lua-mode-resources/hide-show.lua35
-rw-r--r--test/lisp/progmodes/lua-mode-resources/indent.erts1061
-rw-r--r--test/lisp/progmodes/lua-mode-resources/movement.erts637
-rw-r--r--test/lisp/progmodes/lua-mode-resources/which-function.lua3
-rw-r--r--test/lisp/progmodes/lua-mode-tests.el60
6 files changed, 1980 insertions, 0 deletions
diff --git a/test/lisp/progmodes/lua-mode-resources/font-lock.lua b/test/lisp/progmodes/lua-mode-resources/font-lock.lua
new file mode 100644
index 00000000000..bcf77b632c2
--- /dev/null
+++ b/test/lisp/progmodes/lua-mode-resources/font-lock.lua
@@ -0,0 +1,184 @@
1#!/usr/bin/env lua
2-- ^ font-lock-comment-face
3-- Comment
4-- <- font-lock-comment-delimiter-face
5-- ^ font-lock-comment-face
6--[[
7-- ^ font-lock-comment-face
8Multi-line comment
9-- ^ font-lock-comment-face
10]]
11-- <- font-lock-comment-face
12local line_comment = "comment" -- comment
13-- ^ font-lock-comment-face
14
15-- Definition
16local function f1() end
17-- ^ font-lock-function-name-face
18local f2 = function() end
19-- ^ font-lock-function-name-face
20local tb = { f1 = function() end }
21-- ^ font-lock-function-name-face
22function tb.f2() end
23-- ^ font-lock-function-name-face
24function tb:f3() end
25-- ^ font-lock-function-name-face
26tbl.f4 = function() end
27-- ^ font-lock-function-name-face
28function x.y:z() end
29-- ^ font-lock-function-name-face
30
31-- Keyword
32if true then
33-- <- font-lock-keyword-face
34-- ^ font-lock-keyword-face
35elseif true then
36-- <- font-lock-keyword-face
37else end
38-- <- font-lock-keyword-face
39-- ^ font-lock-keyword-face
40local p = {}
41-- ^ font-lock-keyword-face
42for k,v in pairs({}) do end
43-- <- font-lock-keyword-face
44-- ^ font-lock-keyword-face
45repeat if true then break end until false
46-- <- font-lock-keyword-face
47-- ^ font-lock-keyword-face
48-- ^ font-lock-keyword-face
49while true do end
50-- <- font-lock-keyword-face
51-- ^ font-lock-keyword-face
52function fn() return true end
53-- <- font-lock-keyword-face
54-- ^ font-lock-keyword-face
55goto label1
56-- ^ font-lock-keyword-face
57::label1::
58if true and not false or nil then
59-- ^ font-lock-keyword-face
60-- ^ font-lock-keyword-face
61-- ^ font-lock-keyword-face
62end
63
64-- String
65local _
66_ = "x"
67-- ^ font-lock-string-face
68_ = 'x'
69-- ^ font-lock-string-face
70_ = "x\ty"
71-- ^ font-lock-string-face
72-- ^ font-lock-string-face
73_ = "x\"y"
74-- ^ font-lock-string-face
75-- ^ font-lock-string-face
76_ = 'x\'y'
77-- ^ font-lock-string-face
78-- ^ font-lock-string-face
79_ = "x\z
80 y"
81-- ^ font-lock-string-face
82_ = "x\0900y"
83-- ^ font-lock-string-face
84_ = "x\09y"
85-- ^ font-lock-string-face
86_ = "x\0y"
87-- ^ font-lock-string-face
88_ = "x\u{1f602}y"
89-- ^ font-lock-string-face
90_ = [[x]]
91-- ^ font-lock-string-face
92_ = [=[x]=]
93-- ^ font-lock-string-face
94
95-- Assignment
96local n = 0
97-- ^ font-lock-variable-name-face
98for i=0,9 do end
99-- ^ font-lock-variable-name-face
100
101-- Constant
102::label2::
103-- ^ font-lock-constant-face
104goto label2
105-- ^ font-lock-constant-face
106
107-- Builtin
108assert()
109-- <- font-lock-builtin-face
110bit32()
111-- <- font-lock-builtin-face
112collectgarbage()
113-- <- font-lock-builtin-face
114coroutine()
115-- <- font-lock-builtin-face
116debug()
117-- <- font-lock-builtin-face
118dofile()
119-- <- font-lock-builtin-face
120error()
121-- <- font-lock-builtin-face
122getmetatable()
123-- <- font-lock-builtin-face
124io()
125-- <- font-lock-builtin-face
126ipairs()
127-- <- font-lock-builtin-face
128load()
129-- <- font-lock-builtin-face
130loadfile()
131-- <- font-lock-builtin-face
132math()
133-- <- font-lock-builtin-face
134next()
135-- <- font-lock-builtin-face
136os()
137-- <- font-lock-builtin-face
138package()
139-- <- font-lock-builtin-face
140pairs()
141-- <- font-lock-builtin-face
142pcall()
143-- <- font-lock-builtin-face
144print()
145-- <- font-lock-builtin-face
146rawequal()
147-- <- font-lock-builtin-face
148rawget()
149-- <- font-lock-builtin-face
150rawlen()
151-- <- font-lock-builtin-face
152rawset()
153-- <- font-lock-builtin-face
154require()
155-- <- font-lock-builtin-face
156select()
157-- <- font-lock-builtin-face
158setmetatable()
159-- <- font-lock-builtin-face
160string()
161-- <- font-lock-builtin-face
162table()
163-- <- font-lock-builtin-face
164tonumber()
165-- <- font-lock-builtin-face
166tostring()
167-- <- font-lock-builtin-face
168type()
169-- <- font-lock-builtin-face
170utf8()
171-- <- font-lock-builtin-face
172warn()
173-- <- font-lock-builtin-face
174xpcall()
175-- <- font-lock-builtin-face
176print(_G)
177-- ^ font-lock-builtin-face
178print(_VERSION)
179-- ^ font-lock-builtin-face
180
181-- Variable
182function fn(x, y) end
183-- ^ font-lock-variable-name-face
184-- ^ font-lock-variable-name-face
diff --git a/test/lisp/progmodes/lua-mode-resources/hide-show.lua b/test/lisp/progmodes/lua-mode-resources/hide-show.lua
new file mode 100644
index 00000000000..a23b46437bf
--- /dev/null
+++ b/test/lisp/progmodes/lua-mode-resources/hide-show.lua
@@ -0,0 +1,35 @@
1--[[
2This is a
3comment block.
4]]
5local function fun ()
6 print("fun")
7end
8local f = (function ()
9 print(1)
10end)
11for i = 1, 10 do
12 print(i)
13end
14repeat
15 print("repeat")
16until false
17while true do
18 print("while")
19end
20do
21 print(1)
22end
23if true then
24 print(1)
25elseif false then
26 print(0)
27else
28 print(0)
29end
30function f1 (has,
31 lots,
32 of,
33 parameters)
34 print("ok")
35end
diff --git a/test/lisp/progmodes/lua-mode-resources/indent.erts b/test/lisp/progmodes/lua-mode-resources/indent.erts
new file mode 100644
index 00000000000..8b4d8dd0921
--- /dev/null
+++ b/test/lisp/progmodes/lua-mode-resources/indent.erts
@@ -0,0 +1,1061 @@
1Code:
2 (lambda ()
3 (lua-mode)
4 (setq-local indent-tabs-mode nil)
5 (setq-local lua-indent-level 2)
6 (indent-region (point-min) (point-max)))
7
8Name: Function Indent 1
9
10=-=
11function f1(n)
12print(n)
13return n + 1
14end
15=-=
16function f1(n)
17 print(n)
18 return n + 1
19end
20=-=-=
21
22Name: Function Indent 2
23
24=-=
25local function f2(n)
26print(n)
27return n * 2
28end
29=-=
30local function f2(n)
31 print(n)
32 return n * 2
33end
34=-=-=
35
36Name: Function Indent 3
37
38=-=
39local f3 = function(n)
40print(n)
41return n / 3
42end
43=-=
44local f3 = function(n)
45 print(n)
46 return n / 3
47end
48=-=-=
49
50Name: Function Indent 4
51
52=-=
53function f4(...)
54local f = function (...)
55if ok
56then print(1)
57else print(0)
58end
59end
60return f
61end
62=-=
63function f4(...)
64 local f = function (...)
65 if ok
66 then print(1)
67 else print(0)
68 end
69 end
70 return f
71end
72=-=-=
73
74Name: Function Indent 5
75
76=-=
77function f5(...)
78local f = function (...)
79if ok
80then
81print(1)
82else
83print(0)
84end
85end
86return f
87end
88=-=
89function f5(...)
90 local f = function (...)
91 if ok
92 then
93 print(1)
94 else
95 print(0)
96 end
97 end
98 return f
99end
100=-=-=
101
102Name: Function Indent 6
103
104=-=
105function f6(...)
106local f = function (...)
107if ok then
108print(1)
109else
110print(0)
111end
112end
113return f
114end
115=-=
116function f6(...)
117 local f = function (...)
118 if ok then
119 print(1)
120 else
121 print(0)
122 end
123 end
124 return f
125end
126=-=-=
127
128Name: Function Indent 7
129
130=-=
131f7(function()
132print'ok'
133end)
134=-=
135f7(function()
136 print'ok'
137end)
138=-=-=
139
140Name: Function Indent 8
141
142=-=
143;(function ()
144 return true
145 end)()
146=-=
147;(function ()
148 return true
149 end)()
150=-=-=
151
152Name: Conditional Indent 1
153
154=-=
155if true then
156print(true)
157return 1
158elseif false then
159print(false)
160return -1
161else
162print(nil)
163return 0
164end
165=-=
166if true then
167 print(true)
168 return 1
169elseif false then
170 print(false)
171 return -1
172else
173 print(nil)
174 return 0
175end
176=-=-=
177
178Name: Conditional Indent 2
179
180=-=
181if true
182 then
183 print(true)
184 return 1
185 elseif false
186 then
187 print(false)
188 return -1
189 else
190 print(nil)
191 return 0
192end
193=-=
194if true
195then
196 print(true)
197 return 1
198elseif false
199then
200 print(false)
201 return -1
202else
203 print(nil)
204 return 0
205end
206=-=-=
207
208Name: Conditional Indent 3
209
210=-=
211if true
212 then return 1
213 elseif false
214 then return -1
215 else return 0
216end
217=-=
218if true
219then return 1
220elseif false
221then return -1
222else return 0
223end
224=-=-=
225
226Name: Loop Indent 1
227
228=-=
229for k,v in pairs({}) do
230 print(k)
231 print(v)
232end
233=-=
234for k,v in pairs({}) do
235 print(k)
236 print(v)
237end
238=-=-=
239
240Name: Loop Indent 2
241
242=-=
243for i=1,10
244 do print(i)
245end
246=-=
247for i=1,10
248do print(i)
249end
250=-=-=
251
252Name: Loop Indent 3
253
254=-=
255while n < 10 do
256 n = n + 1
257 print(n)
258end
259=-=
260while n < 10 do
261 n = n + 1
262 print(n)
263end
264=-=-=
265
266Name: Loop Indent 4
267
268=-=
269while n < 10
270 do
271 n = n + 1
272 print(n)
273end
274=-=
275while n < 10
276do
277 n = n + 1
278 print(n)
279end
280=-=-=
281
282Name: Loop Indent 5
283
284=-=
285for i=0,9 do
286repeat n = n+1
287 until n > 99
288end
289=-=
290for i=0,9 do
291 repeat n = n+1
292 until n > 99
293end
294=-=-=
295
296Name: Loop Indent 6
297
298=-=
299repeat
300z = z * 2
301print(z)
302until z > 12
303=-=
304repeat
305 z = z * 2
306 print(z)
307until z > 12
308=-=-=
309
310Name: Loop Indent 7
311
312=-=
313for i,x in ipairs(t) do
314while i < 9
315do
316local n = t[x]
317repeat n = n + 1
318until n > #t
319while n < 99
320do
321print(n)
322end
323end
324print(t[i])
325end
326=-=
327for i,x in ipairs(t) do
328 while i < 9
329 do
330 local n = t[x]
331 repeat n = n + 1
332 until n > #t
333 while n < 99
334 do
335 print(n)
336 end
337 end
338 print(t[i])
339end
340=-=-=
341
342Name: Loop Indent 8
343
344=-=
345do
346local a = b
347print(a + 1)
348end
349=-=
350do
351 local a = b
352 print(a + 1)
353end
354=-=-=
355
356Name: Bracket Indent 1
357
358=-=
359fn(
360 )
361=-=
362fn(
363)
364=-=-=
365
366Name: Bracket Indent 2
367
368=-=
369tb={
370 }
371=-=
372tb={
373}
374=-=-=
375
376Name: Multi-line String Indent 1
377
378=-=
379local s = [[
380 Multi-line
381 string content
382 ]]
383=-=-=
384
385Name: Multi-line String Indent 2
386
387=-=
388function f()
389 local str = [[
390 multi-line
391 string
392 ]]
393return true
394end
395=-=
396function f()
397 local str = [[
398 multi-line
399 string
400 ]]
401 return true
402end
403=-=-=
404
405Name: Multi-line Comment Indent 1
406
407=-=
408--[[
409 Multi-line
410 comment content
411]]
412=-=-=
413
414Name: Multi-line Comment Indent 2
415
416=-=
417function f()
418 --[[
419 multi-line
420 comment
421 ]]
422 return true
423end
424=-=-=
425
426Name: Multi-line Comment Indent 3
427
428=-=
429 --[[
430 Long comment.
431 ]]
432=-=-=
433
434Name: Comment Indent 1
435
436=-=
437local fn1 = function (a, b)
438-- comment
439return a + b
440end
441=-=
442local fn1 = function (a, b)
443 -- comment
444 return a + b
445end
446=-=-=
447
448Name: Comment Indent 2
449
450=-=
451local tb1 = {
452 first = 1,
453-- comment
454 second = 2,
455}
456=-=
457local tb1 = {
458 first = 1,
459 -- comment
460 second = 2,
461}
462=-=-=
463
464Name: Comment Indent 3
465
466=-=
467local tb9 = { one = 1,
468-- comment
469 two = 2 }
470=-=
471local tb9 = { one = 1,
472 -- comment
473 two = 2 }
474=-=-=
475
476Name: Argument Indent 1
477
478=-=
479h(
480"string",
4811000
482)
483=-=
484h(
485 "string",
486 1000
487)
488=-=-=
489
490Name: Argument Indent 2
491
492=-=
493local p = h(
494"string",
495 1000
496)
497=-=
498local p = h(
499 "string",
500 1000
501)
502=-=-=
503
504Name: Argument Indent 3
505
506=-=
507fn(1,
5082,
509 3)
510=-=
511fn(1,
512 2,
513 3)
514=-=-=
515
516Name: Argument Indent 4
517
518=-=
519fn( 1, 2,
5203, 4 )
521=-=
522fn( 1, 2,
523 3, 4 )
524=-=-=
525
526Name: Argument Indent 5
527
528=-=
529f({
530x = 1,
531y = 2,
532z = 3,
533})
534=-=
535f({
536 x = 1,
537 y = 2,
538 z = 3,
539})
540=-=-=
541
542Name: Argument Indent 6
543
544=-=
545f({ x = 1,
546y = 2,
547z = 3, })
548=-=
549f({ x = 1,
550 y = 2,
551 z = 3, })
552=-=-=
553
554Name: Argument Indent 7
555
556=-=
557Test({
558a=1
559})
560=-=
561Test({
562 a=1
563})
564=-=-=
565
566Name: Argument Indent 8
567
568=-=
569Test({
570a = 1,
571b = 2,
572},
573nil)
574=-=
575Test({
576 a = 1,
577 b = 2,
578 },
579 nil)
580=-=-=
581
582Name: Argument Indent 9
583
584=-=
585Test(nil, {
586 a = 1,
587 b = 2,
588 })
589=-=
590Test(nil, {
591 a = 1,
592 b = 2,
593})
594=-=-=
595
596Name: Argument Indent 10
597
598=-=
599fn( -- comment
600 1,
601 2)
602=-=
603fn( -- comment
604 1,
605 2)
606=-=-=
607
608Name: Parameter Indent 1
609
610=-=
611function f1(
612a,
613b
614)
615print(a,b)
616end
617=-=
618function f1(
619 a,
620 b
621 )
622 print(a,b)
623end
624=-=-=
625
626Name: Parameter Indent 2
627
628=-=
629local function f2(a,
630 b)
631print(a,b)
632end
633=-=
634local function f2(a,
635 b)
636 print(a,b)
637end
638=-=-=
639
640Name: Parameter Indent 3
641
642=-=
643local f3 = function( a, b,
644 c, d )
645print(a,b,c,d)
646end
647=-=
648local f3 = function( a, b,
649 c, d )
650 print(a,b,c,d)
651end
652=-=-=
653
654Name: Parameter Indent 4
655
656=-=
657local f4 = function(-- comment
658a, b, c)
659=-=
660local f4 = function(-- comment
661 a, b, c)
662=-=-=
663
664Name: Table Indent 1
665
666=-=
667local Other = {
668 First={up={Step=true,Jump=true},
669 down={Step=true,Jump=true},
670 left={Step=true,Jump=true},
671 right={Step=true,Jump=true}},
672 Second={up={Step=true,Jump=true},
673 down={Step=true,Jump=true},
674 left={Step=true,Jump=true},
675 right={Step=true,Jump=true}},
676 Third={up={Goto=true},
677 down={Goto=true},
678 left={Goto=true},
679 right={Goto=true}}
680}
681=-=
682local Other = {
683 First={up={Step=true,Jump=true},
684 down={Step=true,Jump=true},
685 left={Step=true,Jump=true},
686 right={Step=true,Jump=true}},
687 Second={up={Step=true,Jump=true},
688 down={Step=true,Jump=true},
689 left={Step=true,Jump=true},
690 right={Step=true,Jump=true}},
691 Third={up={Goto=true},
692 down={Goto=true},
693 left={Goto=true},
694 right={Goto=true}}
695}
696=-=-=
697
698Name: Table Indent 2
699
700=-=
701local Other = {
702a = 1,
703 b = 2,
704 c = 3,
705}
706=-=
707local Other = {
708 a = 1,
709 b = 2,
710 c = 3,
711}
712=-=-=
713
714Name: Table Indent 3
715
716=-=
717local a = { -- hello world!
718 b = 10
719}
720=-=
721local a = { -- hello world!
722 b = 10
723}
724=-=-=
725
726Name: Continuation Indent 1
727
728=-=
729local very_long_variable_name =
730"ok"..
731 "ok"
732=-=
733local very_long_variable_name =
734 "ok"..
735 "ok"
736=-=-=
737
738Name: Continuation Indent 2
739
740=-=
741local n = a +
742b *
743c /
7441
745=-=
746local n = a +
747 b *
748 c /
749 1
750=-=-=
751
752Name: Continuation Indent 3
753
754=-=
755local x = "A"..
756"B"
757.."C"
758=-=
759local x = "A"..
760 "B"
761 .."C"
762=-=-=
763
764Name: Continuation Indent 4
765
766=-=
767if a
768 and b
769 and c then
770 if x
771 and y then
772 local x = 1 +
7732 *
774 3
775 end
776elseif a
777 or b
778 or c then
779end
780=-=
781if a
782 and b
783 and c then
784 if x
785 and y then
786 local x = 1 +
787 2 *
788 3
789 end
790elseif a
791 or b
792 or c then
793end
794=-=-=
795
796Code:
797 (lambda ()
798 (lua-mode)
799 (setq-local lua-indent-level 4)
800 (setq-local indent-tabs-mode nil)
801 (indent-region (point-min) (point-max)))
802
803Name: End Indent 1
804
805=-=
806function f(x)
807 for y=1,x.y do
808 for x=1,x.z do
809 if x.y and x.z then
810 if y <= x then
811 y = y + 1
812 end end end end
813 return {x,y} or {math.random(),math.random()}
814 end
815=-=
816function f(x)
817 for y=1,x.y do
818 for x=1,x.z do
819 if x.y and x.z then
820 if y <= x then
821 y = y + 1
822 end end end end
823 return {x,y} or {math.random(),math.random()}
824end
825=-=-=
826
827Name: End Indent 2
828
829=-=
830for y=1,x.y do
831 for x=1,x.z do
832 if x.y and x.z then
833 if y <= x then
834 y = y + 1
835 end
836 end end end
837=-=
838for y=1,x.y do
839 for x=1,x.z do
840 if x.y and x.z then
841 if y <= x then
842 y = y + 1
843 end
844end end end
845=-=-=
846
847Name: Nested Function Indent 1
848
849=-=
850function a(...)
851return (function (x)
852return x
853end)(foo(...))
854end
855=-=
856function a(...)
857 return (function (x)
858 return x
859 end)(foo(...))
860end
861=-=-=
862
863Name: Nested Function Indent 2
864
865=-=
866function b(n)
867local x = 1
868return function (i)
869return function (...)
870return (function (n, ...)
871return function (f, ...)
872return (function (...)
873if ... and x < 9 then
874x = x + 1
875return ...
876end end)(n(f, ...))
877end, ...
878end)(i(...))
879end end end
880=-=
881function b(n)
882 local x = 1
883 return function (i)
884 return function (...)
885 return (function (n, ...)
886 return function (f, ...)
887 return (function (...)
888 if ... and x < 9 then
889 x = x + 1
890 return ...
891 end end)(n(f, ...))
892 end, ...
893 end)(i(...))
894end end end
895=-=-=
896
897Name: Nested Function Indent 3
898
899=-=
900function c(f)
901local f1 = function (...)
902if nil ~= ... then
903return f(...)
904end
905end
906return function (i)
907return function (...)
908local fn = function (n, ...)
909local x = function (f, ...)
910return f1(n(f, ...))
911end
912return x
913end
914return fn(i(...))
915end
916end
917end
918=-=
919function c(f)
920 local f1 = function (...)
921 if nil ~= ... then
922 return f(...)
923 end
924 end
925 return function (i)
926 return function (...)
927 local fn = function (n, ...)
928 local x = function (f, ...)
929 return f1(n(f, ...))
930 end
931 return x
932 end
933 return fn(i(...))
934 end
935 end
936end
937=-=-=
938
939Name: Nested Function Indent 4
940
941=-=
942function d(f)
943local f1 = function (c, f, ...)
944if ... then
945if f(...) then
946return ...
947else
948return c(f, ...)
949end end end
950return function (i)
951return function (...)
952return (function (n, ...)
953local function j (f, ...)
954return f1(j, f, n(f, ...))
955end
956return j, ...
957end)(i(...))
958end end end
959=-=
960function d(f)
961 local f1 = function (c, f, ...)
962 if ... then
963 if f(...) then
964 return ...
965 else
966 return c(f, ...)
967 end end end
968 return function (i)
969 return function (...)
970 return (function (n, ...)
971 local function j (f, ...)
972 return f1(j, f, n(f, ...))
973 end
974 return j, ...
975 end)(i(...))
976end end end
977=-=-=
978
979Name: Nested Function Indent 5
980
981=-=
982function e (n, t)
983return function (i)
984return function (...)
985return (
986function (n, ...)
987local x, y, z = 0, {}
988return (function (f, ...)
989return (function (i, ...) return i(i, ...) end)(
990function (i, ...)
991return f(function (x, ...)
992return i(i, ...)(x, ...)
993end, ...)
994end)
995end)(function (j)
996return function(f, ...)
997return (function (c, f, ...)
998if ... then
999if n+1 == x then
1000local y1, x1 = y, x
1001y, x = {}, 0
1002return (function (...)
1003z = ...
1004return ...
1005end)(t(y1-1, x1-1, ...))
1006else
1007x = x - 1
1008return c(f,
1009(function (...)
1010z = ...
1011return ...
1012end)(t(y, x, ...)))
1013end
1014elseif x ~= 0 then
1015x = 0
1016return z, y
1017end end)(j, f, n(f, ...))
1018end end), ...
1019end)(i(...))
1020end end end
1021=-=
1022function e (n, t)
1023 return function (i)
1024 return function (...)
1025 return (
1026 function (n, ...)
1027 local x, y, z = 0, {}
1028 return (function (f, ...)
1029 return (function (i, ...) return i(i, ...) end)(
1030 function (i, ...)
1031 return f(function (x, ...)
1032 return i(i, ...)(x, ...)
1033 end, ...)
1034 end)
1035 end)(function (j)
1036 return function(f, ...)
1037 return (function (c, f, ...)
1038 if ... then
1039 if n+1 == x then
1040 local y1, x1 = y, x
1041 y, x = {}, 0
1042 return (function (...)
1043 z = ...
1044 return ...
1045 end)(t(y1-1, x1-1, ...))
1046 else
1047 x = x - 1
1048 return c(f,
1049 (function (...)
1050 z = ...
1051 return ...
1052 end)(t(y, x, ...)))
1053 end
1054 elseif x ~= 0 then
1055 x = 0
1056 return z, y
1057 end end)(j, f, n(f, ...))
1058 end end), ...
1059 end)(i(...))
1060end end end
1061=-=-=
diff --git a/test/lisp/progmodes/lua-mode-resources/movement.erts b/test/lisp/progmodes/lua-mode-resources/movement.erts
new file mode 100644
index 00000000000..04a52e6bd01
--- /dev/null
+++ b/test/lisp/progmodes/lua-mode-resources/movement.erts
@@ -0,0 +1,637 @@
1Code:
2 (lambda ()
3 (lua-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
28Code:
29 (lambda ()
30 (lua-mode)
31 (end-of-defun 1))
32
33Point-Char: |
34
35Name: end-of-defun moves to end of function declaration
36
37=-=
38local function Test()
39 if true then
40 pr|int(1)
41 else
42 print(0)
43 end
44end
45
46local t = Test()
47=-=
48local function Test()
49 if true then
50 print(1)
51 else
52 print(0)
53 end
54end
55|
56local t = Test()
57=-=-=
58
59Name: end-of-defun moves to end of function definition
60
61=-=
62local t = {
63 f = function()
64 re|turn true
65 end,
66}
67=-=
68local t = {
69 f = function()
70 return true
71| end,
72}
73=-=-=
74
75Code:
76 (lambda ()
77 (lua-mode)
78 (forward-sentence 1))
79
80Point-Char: |
81
82Name: forward-sentence moves over if statements
83
84=-=
85function f()
86 |if true then
87 print(1)
88 elseif false then
89 print(0)
90 else
91 print(2)
92 end
93end
94=-=
95function f()
96 if true then
97 print(1)
98 elseif false then
99 print(0)
100 else
101 print(2)
102 end
103end|
104=-=-=
105
106Name: forward-sentence moves over variable declaration
107
108=-=
109|local n = 1
110
111print(n)
112=-=
113local n = 1|
114
115print(n)
116=-=-=
117
118Name: forward-sentence moves over for statements
119
120=-=
121|for k, v in pairs({}) do
122 print(k, v)
123end
124
125print(1)
126=-=
127for k, v in pairs({}) do
128 print(k, v)
129end|
130
131print(1)
132=-=-=
133
134Name: forward-sentence moves over do statements
135
136=-=
137|do
138 local x = 1
139 local y = 2
140
141 print(x, y)
142end
143
144print(1)
145=-=
146do
147 local x = 1
148 local y = 2|
149
150 print(x, y)
151end
152
153print(1)
154=-=-=
155
156Name: forward-sentence moves over while statements
157
158=-=
159local i = 0
160|while i < 9 do
161 print(i)
162 i = i + 1
163end
164
165print(1)
166=-=
167local i = 0
168while i < 9 do
169 print(i)
170 i = i + 1
171end|
172
173print(1)
174=-=-=
175
176Name: forward-sentence moves over repeat statements
177
178=-=
179local i = 0
180|repeat
181 print(i)
182 i = i + 1
183until i > 9
184
185print(1)
186=-=
187local i = 0
188repeat
189 print(i)
190 i = i + 1
191until i > 9|
192
193print(1)
194=-=-=
195
196Name: forward-sentence moves over function calls
197
198=-=
199|print(1)
200=-=
201print(1)|
202=-=-=
203
204Name: forward-sentence moves over return statements
205
206=-=
207function f()
208 |return math.random()
209end
210=-=
211function f()
212 return math.random()
213end|
214=-=-=
215
216Code:
217 (lambda ()
218 (lua-mode)
219 (forward-sentence 1))
220
221Name: forward-sentence moves over table fields
222
223=-=
224local t = {
225 |a = 1,
226 b = 2,
227}
228=-=
229local t = {
230 a = 1,
231 b = 2,
232}|
233=-=-=
234
235Code:
236 (lambda ()
237 (lua-mode)
238 (backward-sentence 1))
239
240Point-Char: |
241
242Name: backward-sentence moves over if statements
243
244=-=
245function f()
246 if true then
247 print(1)
248 elseif false then
249 print(0)
250 else
251 print(2)
252 end|
253end
254=-=
255|function f()
256 if true then
257 print(1)
258 elseif false then
259 print(0)
260 else
261 print(2)
262 end
263end
264=-=-=
265
266Name: backward-sentence moves over variable declaration
267
268=-=
269local n = 1|
270
271print(n)
272=-=
273|local n = 1
274
275print(n)
276=-=-=
277
278Name: backward-sentence moves over for statements
279
280=-=
281for k, v in pairs({}) do
282 print(k, v)
283end|
284
285print(1)
286=-=
287|for k, v in pairs({}) do
288 print(k, v)
289end
290
291print(1)
292=-=-=
293
294Name: backward-sentence moves over do statements
295
296=-=
297do
298 local x = 1
299 local y = 2
300
301 print(x, y)
302end|
303
304print(1)
305=-=
306do
307 local x = 1
308 local y = 2
309
310 |print(x, y)
311end
312
313print(1)
314=-=-=
315
316Name: backward-sentence moves over while statements
317
318=-=
319local i = 0
320while i < 9 do
321 print(i)
322 i = i + 1
323end|
324
325print(1)
326=-=
327|local i = 0
328while i < 9 do
329 print(i)
330 i = i + 1
331end
332
333print(1)
334=-=-=
335
336Name: backward-sentence moves over repeat statements
337
338=-=
339local i = 0
340repeat
341 print(i)
342 i = i + 1
343until i > 9|
344
345print(1)
346=-=
347|local i = 0
348repeat
349 print(i)
350 i = i + 1
351until i > 9
352
353print(1)
354=-=-=
355
356Name: backward-sentence moves over function calls
357
358=-=
359print(1)|
360=-=
361|print(1)
362=-=-=
363
364Name: backward-sentence moves over return statements
365
366=-=
367function f()
368 return math.random()|
369end
370=-=
371|function f()
372 return math.random()
373end
374=-=-=
375
376Code:
377 (lambda ()
378 (lua-mode)
379 (backward-sentence 2))
380
381Point-Char: |
382
383Name: backward-sentence moves over table fields
384
385=-=
386local t = {
387 a = 1,
388 b = 2|,
389}
390=-=
391|local t = {
392 a = 1,
393 b = 2,
394}
395=-=-=
396
397Code:
398 (lambda ()
399 (lua-mode)
400 (forward-sexp 1))
401
402Point-Char: |
403
404Name: forward-sexp moves over arguments
405
406=-=
407print|(1, 2, 3)
408=-=
409print(1, 2, 3)|
410=-=-=
411
412Name: forward-sexp moves over parameters
413
414=-=
415function f|(a, b) end
416=-=
417function f(a, b)| end
418=-=-=
419
420Name: forward-sexp moves over strings
421
422=-=
423print(|"1, 2, 3")
424=-=
425print("1, 2, 3"|)
426=-=-=
427
428Name: forward-sexp moves over tables
429
430=-=
431local t = |{ 1,
432 2,
433 3 }
434=-=
435local t = { 1,
436 2,
437 3 }|
438=-=-=
439
440Name: forward-sexp moves over parenthesized expressions
441
442=-=
443|(function (x) return x + 1 end)(41)
444=-=
445(function (x) return x + 1 end)|(41)
446=-=-=
447
448Name: forward-sexp moves over function declarations
449
450=-=
451|function foo (x)
452 if false then
453 print "foo"
454 elseif true then
455 print "bar"
456 end
457end
458=-=
459function| foo (x)
460 if false then
461 print "foo"
462 elseif true then
463 print "bar"
464 end
465end
466=-=-=
467
468Name: forward-sexp moves over do statements
469
470=-=
471|do
472 print(a + 1)
473end
474=-=
475do|
476 print(a + 1)
477end
478=-=-=
479
480Name: forward-sexp moves over for statements
481
482=-=
483|for k,v in pairs({}) do
484 print(k, v)
485end
486=-=
487for| k,v in pairs({}) do
488 print(k, v)
489end
490=-=-=
491
492Name: forward-sexp moves over repeat statements
493
494=-=
495|repeat
496 n = n + 1
497until n > 10
498=-=
499repeat|
500 n = n + 1
501until n > 10
502=-=-=
503
504Name: forward-sexp moves over while statements
505
506=-=
507|while n < 99
508do
509 n = n+1
510end
511=-=
512while| n < 99
513do
514 n = n+1
515end
516=-=-=
517
518Code:
519 (lambda ()
520 (lua-mode)
521 (backward-sexp 1))
522
523Point-Char: |
524
525Name: backward-sexp moves over arguments
526
527=-=
528print(1, 2, 3)|
529=-=
530print|(1, 2, 3)
531=-=-=
532
533Name: backward-sexp moves over parameters
534
535=-=
536function f(a, b)| end
537=-=
538function f|(a, b) end
539=-=-=
540
541Name: backward-sexp moves over strings
542
543=-=
544print("1, 2, 3"|)
545=-=
546print(|"1, 2, 3")
547=-=-=
548
549Name: backward-sexp moves over tables
550
551=-=
552local t = { 1,
553 2,
554 3 }|
555=-=
556local t = |{ 1,
557 2,
558 3 }
559=-=-=
560
561Name: backward-sexp moves over parenthesized expressions
562
563=-=
564(function (x) return x + 1 end)|(41)
565=-=
566|(function (x) return x + 1 end)(41)
567=-=-=
568
569Name: backward-sexp moves over function declarations
570
571=-=
572function foo (x)
573 if false then
574 print "foo"
575 elseif true then
576 print "bar"
577 end
578end|
579=-=
580function foo (x)
581 if false then
582 print "foo"
583 elseif true then
584 print "bar"
585 end
586|end
587=-=-=
588
589Name: backward-sexp moves over do statements
590
591=-=
592do
593 print(a + 1)
594end|
595=-=
596do
597 print(a + 1)
598|end
599=-=-=
600
601Name: backward-sexp moves over for statements
602
603=-=
604for k,v in pairs({}) do
605 print(k, v)
606end|
607=-=
608for k,v in pairs({}) do
609 print(k, v)
610|end
611=-=-=
612
613Name: backward-sexp moves over repeat statements
614
615=-=
616repeat
617 n = n + 1
618until n > 10|
619=-=
620repeat
621 n = n + 1
622until n > |10
623=-=-=
624
625Name: backward-sexp moves over while statements
626
627=-=
628while n < 99
629do
630 n = n+1
631end|
632=-=
633while n < 99
634do
635 n = n+1
636|end
637=-=-=
diff --git a/test/lisp/progmodes/lua-mode-resources/which-function.lua b/test/lisp/progmodes/lua-mode-resources/which-function.lua
new file mode 100644
index 00000000000..621d818461c
--- /dev/null
+++ b/test/lisp/progmodes/lua-mode-resources/which-function.lua
@@ -0,0 +1,3 @@
1local function f(x)
2 print(x)
3end
diff --git a/test/lisp/progmodes/lua-mode-tests.el b/test/lisp/progmodes/lua-mode-tests.el
new file mode 100644
index 00000000000..aee3a5f47cb
--- /dev/null
+++ b/test/lisp/progmodes/lua-mode-tests.el
@@ -0,0 +1,60 @@
1;;; lua-mode-tests.el --- Tests for lua-mode -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2023-2025 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-font-lock)
24(require 'ert-x)
25(require 'hideshow)
26(require 'which-func)
27
28(ert-deftest lua-test-indentation ()
29 (ert-test-erts-file (ert-resource-file "indent.erts")))
30
31(ert-deftest lua-test-movement ()
32 (ert-test-erts-file (ert-resource-file "movement.erts")))
33
34(ert-deftest lua-test-font-lock ()
35 (let ((font-lock-maximum-decoration t))
36 (ert-font-lock-test-file (ert-resource-file "font-lock.lua") 'lua-mode)))
37
38(ert-deftest lua-test-which-function ()
39 (with-temp-buffer
40 (insert-file-contents (ert-resource-file "which-function.lua"))
41 (lua-mode)
42 (which-function-mode)
43 (goto-char (point-min))
44 (should (equal "f" (which-function)))
45 (which-function-mode -1)))
46
47(ert-deftest lua-test-hideshow ()
48 (with-temp-buffer
49 (insert-file-contents (ert-resource-file "hide-show.lua"))
50 (lua-mode)
51 (hs-minor-mode)
52 (hs-hide-all)
53 (should (= 9 (length (overlays-in (point-min) (point-max)))))
54 (hs-show-all)
55 (should (= 0 (length (overlays-in (point-min) (point-max)))))
56 (hs-minor-mode -1)))
57
58(provide 'lua-mode-tests)
59
60;;; lua-mode-tests.el ends here