From c5656af2ff5f2ee4a683540db792ccece6db4e43 Mon Sep 17 00:00:00 2001 From: john muhl Date: Fri, 21 Mar 2025 12:15:02 -0500 Subject: [PATCH] ; 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. --- .../lua-mode-resources/font-lock.lua | 184 +++ .../lua-mode-resources/hide-show.lua | 35 + .../progmodes/lua-mode-resources/indent.erts | 1061 +++++++++++++++++ .../lua-mode-resources/movement.erts | 637 ++++++++++ .../lua-mode-resources/which-function.lua | 3 + test/lisp/progmodes/lua-mode-tests.el | 60 + 6 files changed, 1980 insertions(+) create mode 100644 test/lisp/progmodes/lua-mode-resources/font-lock.lua create mode 100644 test/lisp/progmodes/lua-mode-resources/hide-show.lua create mode 100644 test/lisp/progmodes/lua-mode-resources/indent.erts create mode 100644 test/lisp/progmodes/lua-mode-resources/movement.erts create mode 100644 test/lisp/progmodes/lua-mode-resources/which-function.lua create mode 100644 test/lisp/progmodes/lua-mode-tests.el 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 @@ +#!/usr/bin/env lua +-- ^ font-lock-comment-face +-- Comment +-- <- font-lock-comment-delimiter-face +-- ^ font-lock-comment-face +--[[ +-- ^ font-lock-comment-face +Multi-line comment +-- ^ font-lock-comment-face +]] +-- <- font-lock-comment-face +local line_comment = "comment" -- comment +-- ^ font-lock-comment-face + +-- Definition +local function f1() end +-- ^ font-lock-function-name-face +local f2 = function() end +-- ^ font-lock-function-name-face +local tb = { f1 = function() end } +-- ^ font-lock-function-name-face +function tb.f2() end +-- ^ font-lock-function-name-face +function tb:f3() end +-- ^ font-lock-function-name-face +tbl.f4 = function() end +-- ^ font-lock-function-name-face +function x.y:z() end +-- ^ font-lock-function-name-face + +-- Keyword +if true then +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +elseif true then +-- <- font-lock-keyword-face +else end +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +local p = {} +-- ^ font-lock-keyword-face +for k,v in pairs({}) do end +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +repeat if true then break end until false +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +-- ^ font-lock-keyword-face +while true do end +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +function fn() return true end +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +goto label1 +-- ^ font-lock-keyword-face +::label1:: +if true and not false or nil then +-- ^ font-lock-keyword-face +-- ^ font-lock-keyword-face +-- ^ font-lock-keyword-face +end + +-- String +local _ +_ = "x" +-- ^ font-lock-string-face +_ = 'x' +-- ^ font-lock-string-face +_ = "x\ty" +-- ^ font-lock-string-face +-- ^ font-lock-string-face +_ = "x\"y" +-- ^ font-lock-string-face +-- ^ font-lock-string-face +_ = 'x\'y' +-- ^ font-lock-string-face +-- ^ font-lock-string-face +_ = "x\z + y" +-- ^ font-lock-string-face +_ = "x\0900y" +-- ^ font-lock-string-face +_ = "x\09y" +-- ^ font-lock-string-face +_ = "x\0y" +-- ^ font-lock-string-face +_ = "x\u{1f602}y" +-- ^ font-lock-string-face +_ = [[x]] +-- ^ font-lock-string-face +_ = [=[x]=] +-- ^ font-lock-string-face + +-- Assignment +local n = 0 +-- ^ font-lock-variable-name-face +for i=0,9 do end +-- ^ font-lock-variable-name-face + +-- Constant +::label2:: +-- ^ font-lock-constant-face +goto label2 +-- ^ font-lock-constant-face + +-- Builtin +assert() +-- <- font-lock-builtin-face +bit32() +-- <- font-lock-builtin-face +collectgarbage() +-- <- font-lock-builtin-face +coroutine() +-- <- font-lock-builtin-face +debug() +-- <- font-lock-builtin-face +dofile() +-- <- font-lock-builtin-face +error() +-- <- font-lock-builtin-face +getmetatable() +-- <- font-lock-builtin-face +io() +-- <- font-lock-builtin-face +ipairs() +-- <- font-lock-builtin-face +load() +-- <- font-lock-builtin-face +loadfile() +-- <- font-lock-builtin-face +math() +-- <- font-lock-builtin-face +next() +-- <- font-lock-builtin-face +os() +-- <- font-lock-builtin-face +package() +-- <- font-lock-builtin-face +pairs() +-- <- font-lock-builtin-face +pcall() +-- <- font-lock-builtin-face +print() +-- <- font-lock-builtin-face +rawequal() +-- <- font-lock-builtin-face +rawget() +-- <- font-lock-builtin-face +rawlen() +-- <- font-lock-builtin-face +rawset() +-- <- font-lock-builtin-face +require() +-- <- font-lock-builtin-face +select() +-- <- font-lock-builtin-face +setmetatable() +-- <- font-lock-builtin-face +string() +-- <- font-lock-builtin-face +table() +-- <- font-lock-builtin-face +tonumber() +-- <- font-lock-builtin-face +tostring() +-- <- font-lock-builtin-face +type() +-- <- font-lock-builtin-face +utf8() +-- <- font-lock-builtin-face +warn() +-- <- font-lock-builtin-face +xpcall() +-- <- font-lock-builtin-face +print(_G) +-- ^ font-lock-builtin-face +print(_VERSION) +-- ^ font-lock-builtin-face + +-- Variable +function fn(x, y) end +-- ^ font-lock-variable-name-face +-- ^ 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 @@ +--[[ +This is a +comment block. +]] +local function fun () + print("fun") +end +local f = (function () + print(1) +end) +for i = 1, 10 do + print(i) +end +repeat + print("repeat") +until false +while true do + print("while") +end +do + print(1) +end +if true then + print(1) +elseif false then + print(0) +else + print(0) +end +function f1 (has, + lots, + of, + parameters) + print("ok") +end 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 @@ +Code: + (lambda () + (lua-mode) + (setq-local indent-tabs-mode nil) + (setq-local lua-indent-level 2) + (indent-region (point-min) (point-max))) + +Name: Function Indent 1 + +=-= +function f1(n) +print(n) +return n + 1 +end +=-= +function f1(n) + print(n) + return n + 1 +end +=-=-= + +Name: Function Indent 2 + +=-= +local function f2(n) +print(n) +return n * 2 +end +=-= +local function f2(n) + print(n) + return n * 2 +end +=-=-= + +Name: Function Indent 3 + +=-= +local f3 = function(n) +print(n) +return n / 3 +end +=-= +local f3 = function(n) + print(n) + return n / 3 +end +=-=-= + +Name: Function Indent 4 + +=-= +function f4(...) +local f = function (...) +if ok +then print(1) +else print(0) +end +end +return f +end +=-= +function f4(...) + local f = function (...) + if ok + then print(1) + else print(0) + end + end + return f +end +=-=-= + +Name: Function Indent 5 + +=-= +function f5(...) +local f = function (...) +if ok +then +print(1) +else +print(0) +end +end +return f +end +=-= +function f5(...) + local f = function (...) + if ok + then + print(1) + else + print(0) + end + end + return f +end +=-=-= + +Name: Function Indent 6 + +=-= +function f6(...) +local f = function (...) +if ok then +print(1) +else +print(0) +end +end +return f +end +=-= +function f6(...) + local f = function (...) + if ok then + print(1) + else + print(0) + end + end + return f +end +=-=-= + +Name: Function Indent 7 + +=-= +f7(function() +print'ok' +end) +=-= +f7(function() + print'ok' +end) +=-=-= + +Name: Function Indent 8 + +=-= +;(function () + return true + end)() +=-= +;(function () + return true + end)() +=-=-= + +Name: Conditional Indent 1 + +=-= +if true then +print(true) +return 1 +elseif false then +print(false) +return -1 +else +print(nil) +return 0 +end +=-= +if true then + print(true) + return 1 +elseif false then + print(false) + return -1 +else + print(nil) + return 0 +end +=-=-= + +Name: Conditional Indent 2 + +=-= +if true + then + print(true) + return 1 + elseif false + then + print(false) + return -1 + else + print(nil) + return 0 +end +=-= +if true +then + print(true) + return 1 +elseif false +then + print(false) + return -1 +else + print(nil) + return 0 +end +=-=-= + +Name: Conditional Indent 3 + +=-= +if true + then return 1 + elseif false + then return -1 + else return 0 +end +=-= +if true +then return 1 +elseif false +then return -1 +else return 0 +end +=-=-= + +Name: Loop Indent 1 + +=-= +for k,v in pairs({}) do + print(k) + print(v) +end +=-= +for k,v in pairs({}) do + print(k) + print(v) +end +=-=-= + +Name: Loop Indent 2 + +=-= +for i=1,10 + do print(i) +end +=-= +for i=1,10 +do print(i) +end +=-=-= + +Name: Loop Indent 3 + +=-= +while n < 10 do + n = n + 1 + print(n) +end +=-= +while n < 10 do + n = n + 1 + print(n) +end +=-=-= + +Name: Loop Indent 4 + +=-= +while n < 10 + do + n = n + 1 + print(n) +end +=-= +while n < 10 +do + n = n + 1 + print(n) +end +=-=-= + +Name: Loop Indent 5 + +=-= +for i=0,9 do +repeat n = n+1 + until n > 99 +end +=-= +for i=0,9 do + repeat n = n+1 + until n > 99 +end +=-=-= + +Name: Loop Indent 6 + +=-= +repeat +z = z * 2 +print(z) +until z > 12 +=-= +repeat + z = z * 2 + print(z) +until z > 12 +=-=-= + +Name: Loop Indent 7 + +=-= +for i,x in ipairs(t) do +while i < 9 +do +local n = t[x] +repeat n = n + 1 +until n > #t +while n < 99 +do +print(n) +end +end +print(t[i]) +end +=-= +for i,x in ipairs(t) do + while i < 9 + do + local n = t[x] + repeat n = n + 1 + until n > #t + while n < 99 + do + print(n) + end + end + print(t[i]) +end +=-=-= + +Name: Loop Indent 8 + +=-= +do +local a = b +print(a + 1) +end +=-= +do + local a = b + print(a + 1) +end +=-=-= + +Name: Bracket Indent 1 + +=-= +fn( + ) +=-= +fn( +) +=-=-= + +Name: Bracket Indent 2 + +=-= +tb={ + } +=-= +tb={ +} +=-=-= + +Name: Multi-line String Indent 1 + +=-= +local s = [[ + Multi-line + string content + ]] +=-=-= + +Name: Multi-line String Indent 2 + +=-= +function f() + local str = [[ + multi-line + string + ]] +return true +end +=-= +function f() + local str = [[ + multi-line + string + ]] + return true +end +=-=-= + +Name: Multi-line Comment Indent 1 + +=-= +--[[ + Multi-line + comment content +]] +=-=-= + +Name: Multi-line Comment Indent 2 + +=-= +function f() + --[[ + multi-line + comment + ]] + return true +end +=-=-= + +Name: Multi-line Comment Indent 3 + +=-= + --[[ + Long comment. + ]] +=-=-= + +Name: Comment Indent 1 + +=-= +local fn1 = function (a, b) +-- comment +return a + b +end +=-= +local fn1 = function (a, b) + -- comment + return a + b +end +=-=-= + +Name: Comment Indent 2 + +=-= +local tb1 = { + first = 1, +-- comment + second = 2, +} +=-= +local tb1 = { + first = 1, + -- comment + second = 2, +} +=-=-= + +Name: Comment Indent 3 + +=-= +local tb9 = { one = 1, +-- comment + two = 2 } +=-= +local tb9 = { one = 1, + -- comment + two = 2 } +=-=-= + +Name: Argument Indent 1 + +=-= +h( +"string", +1000 +) +=-= +h( + "string", + 1000 +) +=-=-= + +Name: Argument Indent 2 + +=-= +local p = h( +"string", + 1000 +) +=-= +local p = h( + "string", + 1000 +) +=-=-= + +Name: Argument Indent 3 + +=-= +fn(1, +2, + 3) +=-= +fn(1, + 2, + 3) +=-=-= + +Name: Argument Indent 4 + +=-= +fn( 1, 2, +3, 4 ) +=-= +fn( 1, 2, + 3, 4 ) +=-=-= + +Name: Argument Indent 5 + +=-= +f({ +x = 1, +y = 2, +z = 3, +}) +=-= +f({ + x = 1, + y = 2, + z = 3, +}) +=-=-= + +Name: Argument Indent 6 + +=-= +f({ x = 1, +y = 2, +z = 3, }) +=-= +f({ x = 1, + y = 2, + z = 3, }) +=-=-= + +Name: Argument Indent 7 + +=-= +Test({ +a=1 +}) +=-= +Test({ + a=1 +}) +=-=-= + +Name: Argument Indent 8 + +=-= +Test({ +a = 1, +b = 2, +}, +nil) +=-= +Test({ + a = 1, + b = 2, + }, + nil) +=-=-= + +Name: Argument Indent 9 + +=-= +Test(nil, { + a = 1, + b = 2, + }) +=-= +Test(nil, { + a = 1, + b = 2, +}) +=-=-= + +Name: Argument Indent 10 + +=-= +fn( -- comment + 1, + 2) +=-= +fn( -- comment + 1, + 2) +=-=-= + +Name: Parameter Indent 1 + +=-= +function f1( +a, +b +) +print(a,b) +end +=-= +function f1( + a, + b + ) + print(a,b) +end +=-=-= + +Name: Parameter Indent 2 + +=-= +local function f2(a, + b) +print(a,b) +end +=-= +local function f2(a, + b) + print(a,b) +end +=-=-= + +Name: Parameter Indent 3 + +=-= +local f3 = function( a, b, + c, d ) +print(a,b,c,d) +end +=-= +local f3 = function( a, b, + c, d ) + print(a,b,c,d) +end +=-=-= + +Name: Parameter Indent 4 + +=-= +local f4 = function(-- comment +a, b, c) +=-= +local f4 = function(-- comment + a, b, c) +=-=-= + +Name: Table Indent 1 + +=-= +local Other = { + First={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Second={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Third={up={Goto=true}, + down={Goto=true}, + left={Goto=true}, + right={Goto=true}} +} +=-= +local Other = { + First={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Second={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Third={up={Goto=true}, + down={Goto=true}, + left={Goto=true}, + right={Goto=true}} +} +=-=-= + +Name: Table Indent 2 + +=-= +local Other = { +a = 1, + b = 2, + c = 3, +} +=-= +local Other = { + a = 1, + b = 2, + c = 3, +} +=-=-= + +Name: Table Indent 3 + +=-= +local a = { -- hello world! + b = 10 +} +=-= +local a = { -- hello world! + b = 10 +} +=-=-= + +Name: Continuation Indent 1 + +=-= +local very_long_variable_name = +"ok".. + "ok" +=-= +local very_long_variable_name = + "ok".. + "ok" +=-=-= + +Name: Continuation Indent 2 + +=-= +local n = a + +b * +c / +1 +=-= +local n = a + + b * + c / + 1 +=-=-= + +Name: Continuation Indent 3 + +=-= +local x = "A".. +"B" +.."C" +=-= +local x = "A".. + "B" + .."C" +=-=-= + +Name: Continuation Indent 4 + +=-= +if a + and b + and c then + if x + and y then + local x = 1 + +2 * + 3 + end +elseif a + or b + or c then +end +=-= +if a + and b + and c then + if x + and y then + local x = 1 + + 2 * + 3 + end +elseif a + or b + or c then +end +=-=-= + +Code: + (lambda () + (lua-mode) + (setq-local lua-indent-level 4) + (setq-local indent-tabs-mode nil) + (indent-region (point-min) (point-max))) + +Name: End Indent 1 + +=-= +function f(x) + for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end end end end + return {x,y} or {math.random(),math.random()} + end +=-= +function f(x) + for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end end end end + return {x,y} or {math.random(),math.random()} +end +=-=-= + +Name: End Indent 2 + +=-= +for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end + end end end +=-= +for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end +end end end +=-=-= + +Name: Nested Function Indent 1 + +=-= +function a(...) +return (function (x) +return x +end)(foo(...)) +end +=-= +function a(...) + return (function (x) + return x + end)(foo(...)) +end +=-=-= + +Name: Nested Function Indent 2 + +=-= +function b(n) +local x = 1 +return function (i) +return function (...) +return (function (n, ...) +return function (f, ...) +return (function (...) +if ... and x < 9 then +x = x + 1 +return ... +end end)(n(f, ...)) +end, ... +end)(i(...)) +end end end +=-= +function b(n) + local x = 1 + return function (i) + return function (...) + return (function (n, ...) + return function (f, ...) + return (function (...) + if ... and x < 9 then + x = x + 1 + return ... + end end)(n(f, ...)) + end, ... + end)(i(...)) +end end end +=-=-= + +Name: Nested Function Indent 3 + +=-= +function c(f) +local f1 = function (...) +if nil ~= ... then +return f(...) +end +end +return function (i) +return function (...) +local fn = function (n, ...) +local x = function (f, ...) +return f1(n(f, ...)) +end +return x +end +return fn(i(...)) +end +end +end +=-= +function c(f) + local f1 = function (...) + if nil ~= ... then + return f(...) + end + end + return function (i) + return function (...) + local fn = function (n, ...) + local x = function (f, ...) + return f1(n(f, ...)) + end + return x + end + return fn(i(...)) + end + end +end +=-=-= + +Name: Nested Function Indent 4 + +=-= +function d(f) +local f1 = function (c, f, ...) +if ... then +if f(...) then +return ... +else +return c(f, ...) +end end end +return function (i) +return function (...) +return (function (n, ...) +local function j (f, ...) +return f1(j, f, n(f, ...)) +end +return j, ... +end)(i(...)) +end end end +=-= +function d(f) + local f1 = function (c, f, ...) + if ... then + if f(...) then + return ... + else + return c(f, ...) + end end end + return function (i) + return function (...) + return (function (n, ...) + local function j (f, ...) + return f1(j, f, n(f, ...)) + end + return j, ... + end)(i(...)) +end end end +=-=-= + +Name: Nested Function Indent 5 + +=-= +function e (n, t) +return function (i) +return function (...) +return ( +function (n, ...) +local x, y, z = 0, {} +return (function (f, ...) +return (function (i, ...) return i(i, ...) end)( +function (i, ...) +return f(function (x, ...) +return i(i, ...)(x, ...) +end, ...) +end) +end)(function (j) +return function(f, ...) +return (function (c, f, ...) +if ... then +if n+1 == x then +local y1, x1 = y, x +y, x = {}, 0 +return (function (...) +z = ... +return ... +end)(t(y1-1, x1-1, ...)) +else +x = x - 1 +return c(f, +(function (...) +z = ... +return ... +end)(t(y, x, ...))) +end +elseif x ~= 0 then +x = 0 +return z, y +end end)(j, f, n(f, ...)) +end end), ... +end)(i(...)) +end end end +=-= +function e (n, t) + return function (i) + return function (...) + return ( + function (n, ...) + local x, y, z = 0, {} + return (function (f, ...) + return (function (i, ...) return i(i, ...) end)( + function (i, ...) + return f(function (x, ...) + return i(i, ...)(x, ...) + end, ...) + end) + end)(function (j) + return function(f, ...) + return (function (c, f, ...) + if ... then + if n+1 == x then + local y1, x1 = y, x + y, x = {}, 0 + return (function (...) + z = ... + return ... + end)(t(y1-1, x1-1, ...)) + else + x = x - 1 + return c(f, + (function (...) + z = ... + return ... + end)(t(y, x, ...))) + end + elseif x ~= 0 then + x = 0 + return z, y + end end)(j, f, n(f, ...)) + end end), ... + end)(i(...)) +end end end +=-=-= 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 @@ +Code: + (lambda () + (lua-mode) + (beginning-of-defun 1)) + +Point-Char: | + +Name: beginning-of-defun moves to start of function declaration + +=-= +local function Test() + if true then + print(1) + else + print(0) + end| +end +=-= +|local function Test() + if true then + print(1) + else + print(0) + end +end +=-=-= + +Code: + (lambda () + (lua-mode) + (end-of-defun 1)) + +Point-Char: | + +Name: end-of-defun moves to end of function declaration + +=-= +local function Test() + if true then + pr|int(1) + else + print(0) + end +end + +local t = Test() +=-= +local function Test() + if true then + print(1) + else + print(0) + end +end +| +local t = Test() +=-=-= + +Name: end-of-defun moves to end of function definition + +=-= +local t = { + f = function() + re|turn true + end, +} +=-= +local t = { + f = function() + return true +| end, +} +=-=-= + +Code: + (lambda () + (lua-mode) + (forward-sentence 1)) + +Point-Char: | + +Name: forward-sentence moves over if statements + +=-= +function f() + |if true then + print(1) + elseif false then + print(0) + else + print(2) + end +end +=-= +function f() + if true then + print(1) + elseif false then + print(0) + else + print(2) + end +end| +=-=-= + +Name: forward-sentence moves over variable declaration + +=-= +|local n = 1 + +print(n) +=-= +local n = 1| + +print(n) +=-=-= + +Name: forward-sentence moves over for statements + +=-= +|for k, v in pairs({}) do + print(k, v) +end + +print(1) +=-= +for k, v in pairs({}) do + print(k, v) +end| + +print(1) +=-=-= + +Name: forward-sentence moves over do statements + +=-= +|do + local x = 1 + local y = 2 + + print(x, y) +end + +print(1) +=-= +do + local x = 1 + local y = 2| + + print(x, y) +end + +print(1) +=-=-= + +Name: forward-sentence moves over while statements + +=-= +local i = 0 +|while i < 9 do + print(i) + i = i + 1 +end + +print(1) +=-= +local i = 0 +while i < 9 do + print(i) + i = i + 1 +end| + +print(1) +=-=-= + +Name: forward-sentence moves over repeat statements + +=-= +local i = 0 +|repeat + print(i) + i = i + 1 +until i > 9 + +print(1) +=-= +local i = 0 +repeat + print(i) + i = i + 1 +until i > 9| + +print(1) +=-=-= + +Name: forward-sentence moves over function calls + +=-= +|print(1) +=-= +print(1)| +=-=-= + +Name: forward-sentence moves over return statements + +=-= +function f() + |return math.random() +end +=-= +function f() + return math.random() +end| +=-=-= + +Code: + (lambda () + (lua-mode) + (forward-sentence 1)) + +Name: forward-sentence moves over table fields + +=-= +local t = { + |a = 1, + b = 2, +} +=-= +local t = { + a = 1, + b = 2, +}| +=-=-= + +Code: + (lambda () + (lua-mode) + (backward-sentence 1)) + +Point-Char: | + +Name: backward-sentence moves over if statements + +=-= +function f() + if true then + print(1) + elseif false then + print(0) + else + print(2) + end| +end +=-= +|function f() + if true then + print(1) + elseif false then + print(0) + else + print(2) + end +end +=-=-= + +Name: backward-sentence moves over variable declaration + +=-= +local n = 1| + +print(n) +=-= +|local n = 1 + +print(n) +=-=-= + +Name: backward-sentence moves over for statements + +=-= +for k, v in pairs({}) do + print(k, v) +end| + +print(1) +=-= +|for k, v in pairs({}) do + print(k, v) +end + +print(1) +=-=-= + +Name: backward-sentence moves over do statements + +=-= +do + local x = 1 + local y = 2 + + print(x, y) +end| + +print(1) +=-= +do + local x = 1 + local y = 2 + + |print(x, y) +end + +print(1) +=-=-= + +Name: backward-sentence moves over while statements + +=-= +local i = 0 +while i < 9 do + print(i) + i = i + 1 +end| + +print(1) +=-= +|local i = 0 +while i < 9 do + print(i) + i = i + 1 +end + +print(1) +=-=-= + +Name: backward-sentence moves over repeat statements + +=-= +local i = 0 +repeat + print(i) + i = i + 1 +until i > 9| + +print(1) +=-= +|local i = 0 +repeat + print(i) + i = i + 1 +until i > 9 + +print(1) +=-=-= + +Name: backward-sentence moves over function calls + +=-= +print(1)| +=-= +|print(1) +=-=-= + +Name: backward-sentence moves over return statements + +=-= +function f() + return math.random()| +end +=-= +|function f() + return math.random() +end +=-=-= + +Code: + (lambda () + (lua-mode) + (backward-sentence 2)) + +Point-Char: | + +Name: backward-sentence moves over table fields + +=-= +local t = { + a = 1, + b = 2|, +} +=-= +|local t = { + a = 1, + b = 2, +} +=-=-= + +Code: + (lambda () + (lua-mode) + (forward-sexp 1)) + +Point-Char: | + +Name: forward-sexp moves over arguments + +=-= +print|(1, 2, 3) +=-= +print(1, 2, 3)| +=-=-= + +Name: forward-sexp moves over parameters + +=-= +function f|(a, b) end +=-= +function f(a, b)| end +=-=-= + +Name: forward-sexp moves over strings + +=-= +print(|"1, 2, 3") +=-= +print("1, 2, 3"|) +=-=-= + +Name: forward-sexp moves over tables + +=-= +local t = |{ 1, + 2, + 3 } +=-= +local t = { 1, + 2, + 3 }| +=-=-= + +Name: forward-sexp moves over parenthesized expressions + +=-= +|(function (x) return x + 1 end)(41) +=-= +(function (x) return x + 1 end)|(41) +=-=-= + +Name: forward-sexp moves over function declarations + +=-= +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-= +function| foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-=-= + +Name: forward-sexp moves over do statements + +=-= +|do + print(a + 1) +end +=-= +do| + print(a + 1) +end +=-=-= + +Name: forward-sexp moves over for statements + +=-= +|for k,v in pairs({}) do + print(k, v) +end +=-= +for| k,v in pairs({}) do + print(k, v) +end +=-=-= + +Name: forward-sexp moves over repeat statements + +=-= +|repeat + n = n + 1 +until n > 10 +=-= +repeat| + n = n + 1 +until n > 10 +=-=-= + +Name: forward-sexp moves over while statements + +=-= +|while n < 99 +do + n = n+1 +end +=-= +while| n < 99 +do + n = n+1 +end +=-=-= + +Code: + (lambda () + (lua-mode) + (backward-sexp 1)) + +Point-Char: | + +Name: backward-sexp moves over arguments + +=-= +print(1, 2, 3)| +=-= +print|(1, 2, 3) +=-=-= + +Name: backward-sexp moves over parameters + +=-= +function f(a, b)| end +=-= +function f|(a, b) end +=-=-= + +Name: backward-sexp moves over strings + +=-= +print("1, 2, 3"|) +=-= +print(|"1, 2, 3") +=-=-= + +Name: backward-sexp moves over tables + +=-= +local t = { 1, + 2, + 3 }| +=-= +local t = |{ 1, + 2, + 3 } +=-=-= + +Name: backward-sexp moves over parenthesized expressions + +=-= +(function (x) return x + 1 end)|(41) +=-= +|(function (x) return x + 1 end)(41) +=-=-= + +Name: backward-sexp moves over function declarations + +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +|end +=-=-= + +Name: backward-sexp moves over do statements + +=-= +do + print(a + 1) +end| +=-= +do + print(a + 1) +|end +=-=-= + +Name: backward-sexp moves over for statements + +=-= +for k,v in pairs({}) do + print(k, v) +end| +=-= +for k,v in pairs({}) do + print(k, v) +|end +=-=-= + +Name: backward-sexp moves over repeat statements + +=-= +repeat + n = n + 1 +until n > 10| +=-= +repeat + n = n + 1 +until n > |10 +=-=-= + +Name: backward-sexp moves over while statements + +=-= +while n < 99 +do + n = n+1 +end| +=-= +while n < 99 +do + n = n+1 +|end +=-=-= 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 @@ +local function f(x) + print(x) +end 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 @@ +;;; lua-mode-tests.el --- Tests for lua-mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2023-2025 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Code: + +(require 'ert) +(require 'ert-font-lock) +(require 'ert-x) +(require 'hideshow) +(require 'which-func) + +(ert-deftest lua-test-indentation () + (ert-test-erts-file (ert-resource-file "indent.erts"))) + +(ert-deftest lua-test-movement () + (ert-test-erts-file (ert-resource-file "movement.erts"))) + +(ert-deftest lua-test-font-lock () + (let ((font-lock-maximum-decoration t)) + (ert-font-lock-test-file (ert-resource-file "font-lock.lua") 'lua-mode))) + +(ert-deftest lua-test-which-function () + (with-temp-buffer + (insert-file-contents (ert-resource-file "which-function.lua")) + (lua-mode) + (which-function-mode) + (goto-char (point-min)) + (should (equal "f" (which-function))) + (which-function-mode -1))) + +(ert-deftest lua-test-hideshow () + (with-temp-buffer + (insert-file-contents (ert-resource-file "hide-show.lua")) + (lua-mode) + (hs-minor-mode) + (hs-hide-all) + (should (= 9 (length (overlays-in (point-min) (point-max))))) + (hs-show-all) + (should (= 0 (length (overlays-in (point-min) (point-max))))) + (hs-minor-mode -1))) + +(provide 'lua-mode-tests) + +;;; lua-mode-tests.el ends here