1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 12:21:25 -08:00

; 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.
This commit is contained in:
john muhl 2025-03-21 12:15:02 -05:00 committed by Po Lu
parent 38a0775742
commit c5656af2ff
6 changed files with 1980 additions and 0 deletions

View file

@ -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

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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
=-=-=

View file

@ -0,0 +1,3 @@
local function f(x)
print(x)
end

View file

@ -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 <https://www.gnu.org/licenses/>.
;;; 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