From c26fb65ed17ef44854030f2c0afffea357012dce Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Sun, 26 Sep 2021 11:19:58 -0300 Subject: [PATCH] lua.kak: Add some test cases, and also fix a bug --- rc/filetype/lua.kak | 2 +- test/indent/lua/insert-end-only-when-needed/in | 14 +++++++++++++- .../indent/lua/insert-end-only-when-needed/out | 18 +++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/rc/filetype/lua.kak b/rc/filetype/lua.kak index 9660253d..1dd0178a 100644 --- a/rc/filetype/lua.kak +++ b/rc/filetype/lua.kak @@ -136,7 +136,7 @@ define-command -hidden lua-insert-on-new-line %[ ^\h*\b(else|elseif|do|for|function|if|while)\b|[^\n]\bfunction\b\h*[(] \ \bend\b # check that the block is empty and is not closed on a different line - execute-keys -draft i ^[^\n]*\n[^\n]*\n j ^x\b(else|elseif|end)\b + execute-keys -draft i ^[^\n]+\n[^\n]+\n j ^x\b(else|elseif|end)\b # auto insert end execute-keys -draft oxend # auto insert ) for anonymous function diff --git a/test/indent/lua/insert-end-only-when-needed/in b/test/indent/lua/insert-end-only-when-needed/in index 14415ac6..9c880220 100644 --- a/test/indent/lua/insert-end-only-when-needed/in +++ b/test/indent/lua/insert-end-only-when-needed/in @@ -3,7 +3,19 @@ end function fun2()%( ) - function fun3() if true then%( ) end + +function fun4() + if true then + return 10 + else%( ) +end + +function fun5() + if true then%( ) + return 10 +end + +local str = "while"%( ) diff --git a/test/indent/lua/insert-end-only-when-needed/out b/test/indent/lua/insert-end-only-when-needed/out index b1644048..f2b9fa25 100644 --- a/test/indent/lua/insert-end-only-when-needed/out +++ b/test/indent/lua/insert-end-only-when-needed/out @@ -6,9 +6,25 @@ function fun2() foo() end - function fun3() if true then foo() end end + +function fun4() + if true then + return 10 + else + foo() + end +end + +function fun5() + if true then + foo() + return 10 +end + +local str = "while" +foo()