[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 1452f8e 244/468: should-lua-indent: accept string
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 1452f8e 244/468: should-lua-indent: accept strings rather than lists to simplify writing tests |
Date: |
Thu, 5 Aug 2021 04:58:46 -0400 (EDT) |
branch: elpa/lua-mode
commit 1452f8ea3e3242e55dab0d73a119f0a6a77d47c1
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
should-lua-indent: accept strings rather than lists to simplify writing
tests
---
ert-tests/lua-font-lock-test-helpers.el | 9 +-
ert-tests/test-indentation.el | 590 +++++++++++++++++++++++---------
2 files changed, 425 insertions(+), 174 deletions(-)
diff --git a/ert-tests/lua-font-lock-test-helpers.el
b/ert-tests/lua-font-lock-test-helpers.el
index ce98b32..32a44ec 100644
--- a/ert-tests/lua-font-lock-test-helpers.el
+++ b/ert-tests/lua-font-lock-test-helpers.el
@@ -90,9 +90,12 @@ This is a mere typing/reading aid for lua-mode's font-lock
tests."
(progn ,@body)
(buffer-substring-no-properties (point-min) (point-max)))
"\n" nil)))
-(defmacro should-lua-indent (strs)
- `(should
- (equal ,strs (lua-get-indented-strs ,strs))))
+
+(defmacro should-lua-indent (str)
+ `(let ((strs (split-string ,str "\n"))
+ (indent-tabs-mode nil))
+ (should
+ (equal strs (lua-get-indented-strs strs)))))
(provide 'lua-font-lock-test-helpers)
diff --git a/ert-tests/test-indentation.el b/ert-tests/test-indentation.el
index e51ed9e..3dc65a1 100644
--- a/ert-tests/test-indentation.el
+++ b/ert-tests/test-indentation.el
@@ -7,194 +7,441 @@
"lua-font-lock-test-helpers.el"))
(ert-deftest lua-indentation-assignment ()
- (should-lua-indent '("foo = 10"
- ""
- "bar = 20"))
- (should-lua-indent '("foo"
- " = 10"
- ""
- "bar = 20"))
- (should-lua-indent '("foo ="
- " 10"
- ""
- "bar = 20"))
- (should-lua-indent '("foo, baz = 10, 20"
- ""
- "bar = 20"))
- ;; FIXME: implement comma-indentation
- ;; (should-lua-indent '("foo,"
- ;; " baz = 10, 20"
- ;; ""
- ;; "bar = 20"))
- (should-lua-indent '("foo, baz"
- " = 10, 20"
- ""
- "bar = 20"))
- (should-lua-indent '("foo, baz = "
- " 10, 20"
- ""
- "bar = 20"))
- ;; FIXME: implement comma-indentation
- ;; (should-lua-indent '("foo, baz = 10,"
- ;; " 20"
- ;; ""
- ;; "bar = 20"))
- ;; (should-lua-indent '("foo, baz = "
- ;; " 10,"
- ;; " 20"
- ;; ""
- ;; "bar = 20"))
- (should-lua-indent '("local"
- " x = 5")))
+ (should-lua-indent "\
+foo = 10
+
+bar = 20")
+
+ (should-lua-indent "\
+foo
+ = 10
+
+bar = 20")
+
+ (should-lua-indent "\
+foo =
+ 10
+bar = 20"))
+
+
+;; (ert-deftest lua-indentation-assignment-with-commas ()
+;; (should-lua-indent "\
+;; foo,
+;; baz = 10, 20
+
+;; bar = 20")
+;; (should-lua-indent "\
+;; foo, baz
+;; = 10, 20
+
+;; bar = 20")
+
+;; (should-lua-indent "\
+;; foo, baz = 10,
+;; 20
+
+;; bar = 20")
+
+;; (should-lua-indent "\
+;; foo,
+;; baz =
+;; 10, 20")
+
+;; (should-lua-indent "\
+;; foo, baz =
+;; 10,
+;; 20
+
+;; bar = 20")
+
+;; (should-lua-indent "\
+;; local
+;; x = 5")
+
+;; (should-lua-indent "\
+;; local
+;; x,
+;; y = 10, 20")
+
+;; (should-lua-indent "\
+;; local
+;; x,
+;; y =
+;; 10,
+;; 20"))
(ert-deftest lua-indentation-test-issue33 ()
- (should-lua-indent
- '("a ="
- " {"
- " }"
- ""
- "b ="
- " {"
- " },"
- ""
- ""
- "a = {"
- " table_elt_indented"
- "}"
- ""
- "a = a +"
- " 5 +"
- " 10"
- ""
- "this_should_be_unindented()"
- ""
- "-- here foobar should be indented as simple continuation statement"
- "a = a +"
- " dosmth("
- " ) +"
- " foobar"
- ""
- "a ="
- " do_smth("
- " do_smth_arg"
- " )"
- ""
- "b ="
- " {"
- " table_elt0_indented,"
- " table_elt1_indented"
- " }"
- ""
- "this_should_be_unindented_too ="
- " {"
- " }"
- ""
- "this_should_be_unindented_three = etc")))
+ (should-lua-indent "\
+a =
+ {
+ }
+
+b =
+ {
+ },
+
+
+a = {
+ table_elt_indented
+}
+
+a = a +
+ 5 +
+ 10
+
+this_should_be_unindented()
+
+-- here foobar should be indented as simple continuation statement
+a = a +
+ dosmth(
+ ) +
+ foobar
+
+a =
+ do_smth(
+ do_smth_arg
+ )
+
+b =
+ {
+ table_elt0_indented,
+ table_elt1_indented
+ }
+
+this_should_be_unindented_too =
+ {
+ }
+
+this_should_be_unindented_three = etc"))
(ert-deftest lua-indentation-dot-and-colon-continuation ()
- (should-lua-indent '("foo"
- " .bar:baz(xyz)"))
- (should-lua-indent '("foo."
- " bar:baz(xyz)"))
- (should-lua-indent '("foo.bar"
- " :baz(xyz)"))
- (should-lua-indent '("foo.bar:"
- " baz(xyz)"))
- (should-lua-indent '("foo.bar"
- " .baz"
- " .qux"
- " :quux(xyz)")))
+ (should-lua-indent "\
+foo
+ .bar:baz(xyz)")
+ (should-lua-indent "\
+foo.
+ bar:baz(xyz)")
+ (should-lua-indent "\
+foo.bar
+ :baz(xyz)")
+ (should-lua-indent "\
+foo.bar:
+ baz(xyz)")
+ (should-lua-indent "\
+foo.bar
+ .baz
+ .qux
+ :quux(xyz)"))
(ert-deftest lua-indentation-binop-continuation ()
(let ((binops '("+" "-" "*" "/" "^" "%" ".."
- "<" "<=" ">" ">=" "==" "~="
- "and" "or")))
+ "<" "<=" ">" ">=" "==" "~="
+ "and" "or")))
(cl-dolist (binop binops)
- (should-lua-indent `(,(concat "a = foo " binop)
- " bar"))
- (should-lua-indent `("a = foo "
- ,(mapconcat 'identity '(" " " bar") binop))))))
+ (should-lua-indent (replace-regexp-in-string "BINOP" binop "\
+a = foo BINOP
+ bar" 'fixedcase))
+ (should-lua-indent (replace-regexp-in-string "BINOP" binop "\
+a = foo
+ BINOP bar" 'fixedcase)))))
+
(ert-deftest lua-indentation-return-continuation ()
- (should-lua-indent '("return"
- " 123"))
- (should-lua-indent '("do"
- " return"
- " 123"
- "end"))
- (should-lua-indent '("do"
- " return"
- " x +"
- " y"
- "end"))
+ (should-lua-indent "\
+return
+ 123")
+
+ (should-lua-indent "\
+do
+ return
+ 123
+end")
+
+ (should-lua-indent "\
+do
+ return
+ x +
+ y
+end")
;; make sure block-end tokens forbid continuation
- (should-lua-indent '("do"
- " return"
- "end"
- ""
- "foo = bar"))
- (should-lua-indent '("if foo == bar then"
- " return"
- "else"
- " foo = bar"
- "end"))
- (should-lua-indent '("if foo > bar then"
- " return"
- "elseif foo ~= bar then"
- " foo = bar"
- "end"))
- (should-lua-indent '("repeat"
- " return"
- "until foo == bar"
- ""
- "foo = bar")))
-
-
-(ert-deftest lua-indentation-blocks ()
+ (should-lua-indent "\
+do
+ return
+end
+
+foo = bar")
+
+ (should-lua-indent "\
+if foo == bar then
+ return
+else
+ foo = bar
+end")
+
+ (should-lua-indent "\
+if foo == bar then
+ return
+elseif foo != bar then
+ foo = bar
+end")
+
+ (should-lua-indent "\
+repeat
+ return
+until foo == bar"))
+
+
+(ert-deftest lua-indentation-do-block ()
;; FIXME: test split block-intro indentations
- (should-lua-indent '("do"
- " a = a + 1"
- "end"
- ""
- "a = 0"))
-
- (should-lua-indent '("while foo do"
- " a = a + 1"
- "end"
- ""
- "a = 0"))
-
- (should-lua-indent '("repeat"
- " a = a + 1"
- "until not foo"
- ""
- "a = 0"))
-
- (should-lua-indent '("for foo in pairs(bar) do"
- " a = a + 1"
- "end"
- ""
- "a = 0"))
-
- (should-lua-indent '("for y = 0, 10 do"
- " a = a + 1"
- "end"
- ""
- "a = 0")))
+ (should-lua-indent "\
+do
+ a = a + 1
+end
+
+a = 0")
+
+ (should-lua-indent "\
+do a = a + 1 end
+
+a = 0")
+
+ (should-lua-indent "\
+do a = a + 1
+end
+
+a = 0"))
+
+
+(ert-deftest lua-indentation-while-block ()
+ (should-lua-indent "\
+while foo do
+ a = a + 1
+end
+
+a = 0")
+
+ (should-lua-indent "\
+while foo
+do
+ a = a + 1
+end
+
+a = 0")
+
+ (should-lua-indent "\
+while
+ foo do
+ a = a + 1
+end
+
+a = 0")
+
+ (should-lua-indent "\
+while
+ foo
+ do
+ a = a + 1
+end
+
+a = 0")
+
+ (should-lua-indent "\
+while foo do a = a + 1 end
+
+a = 0")
+
+ (should-lua-indent "\
+while
+ x +
+ y > 0
+ do
+ a = a + 1
+end
+
+a = 0"))
+
+
+(ert-deftest lua-indentation-repeat-block ()
+ (should-lua-indent "\
+repeat
+ a = a + 1
+until foo
+
+a = 0")
+
+ (should-lua-indent "\
+repeat
+ a = a + 1
+until
+ foo
+
+a = 0")
+
+ (should-lua-indent "\
+repeat
+ a = a + 1
+until
+ not
+ foo
+
+a = 0")
+
+ (should-lua-indent "\
+repeat a = a + 1 until not foo
+
+a = 0"))
+
+
+
+(ert-deftest lua-indentation-for-block ()
+ (should-lua-indent "\
+for k, v in pairs(bar) do
+ a = a + 1
+end
+
+a = 0")
+
+ (should-lua-indent "\
+for k, v in pairs(bar)
+do
+ a = a + 1
+end
+
+a = 0")
+
+ (should-lua-indent "\
+for k, v in pairs(bar) do a = a + 1 end
+
+a = 0")
+
+ (should-lua-indent "\
+for
+ k, v in pairs(bar) do a = a + 1 end
+
+a = 0")
+
+ (should-lua-indent "\
+for k, v
+ in pairs(bar) do a = a + 1 end
+
+a = 0")
+
+ (should-lua-indent "\
+for y = 0, 10 do
+ a = a + 1
+end
+
+a = 0")
+
+ (should-lua-indent "\
+for y = 0, 10
+do
+ a = a + 1
+end
+
+a = 0")
+
+ (should-lua-indent "\
+for y = 0, 10 do a = a + 1 end
+
+a = 0"))
+
(ert-deftest lua-indentation-functioncall ()
- ;; FIXME: add
- ;; FIXME: test bare tablector variant
- ;; FIXME: test interaction with continuation
+ (should-lua-indent "\
+foobar(
+ a, b, c)")
+
+ (should-lua-indent "\
+foobar(
+ a, b, c
+)")
+
+ (should-lua-indent "\
+foobar(a,
+ b,
+ c)")
+
+ (should-lua-indent "\
+foobar({
+ a, b, c
+})")
+
+ (should-lua-indent "\
+foobar{
+ a, b, c
+}")
+
+ (should-lua-indent "\
+foobar(a,
+ {
+ b,
+ c
+ })")
+
+ (should-lua-indent "\
+foobar(a,
+ {
+ b,
+ c
+ }
+)")
+
+ (should-lua-indent "\
+foobar(
+ {
+ a,
+ b
+ },
+ c, d
+)")
)
+(ert-deftest lua-indentation-continuation-with-functioncall ()
+ (should-lua-indent "\
+x = foo(123,
+ 456)
+ + bar(
+ qux,
+ quux)"))
+
(ert-deftest lua-indentation-conditional ()
- ;; if exp then block {elseif exp then block} [else block] end
- ;; FIXME: add
- )
+ (should-lua-indent "\
+if foo then
+ a = a + 1
+end
+
+a = 0")
+
+ (should-lua-indent "\
+if foo then a = a + 1 end
+
+a = 0")
+
+ (should-lua-indent "\
+if foo then
+ a = a + 1
+else
+ a = a + 2
+end
+
+a = 0")
+
+
+ (should-lua-indent "\
+if foo then
+ a = a + 1
+elseif bar then
+ a = a + 2
+elseif baz then
+ a = a + 3
+end
+
+a = 0"))
+
(ert-deftest lua-indentation-defun ()
;; [local] function funcname funcbody
@@ -216,6 +463,7 @@
(ert-deftest lua-indentation-keywords-with-special-characters ()
- (should-lua-indent '("do"
- " foobar = _do"
- "end")))
+ (should-lua-indent "\
+do
+ foobar = _do
+end"))
- [nongnu] elpa/lua-mode d6c8419 202/468: Fix incorrect error highlighting in 'for x = ...' statements, (continued)
- [nongnu] elpa/lua-mode d6c8419 202/468: Fix incorrect error highlighting in 'for x = ...' statements, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 2d94dee 204/468: Don't unindent comment close-bracket if it doesn't match open-bracket, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c1fcfb6 211/468: Add NEWS file, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d0fa50d 217/468: lua-make-delimited-matcher: wrap into eval-and-compile, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b684790 219/468: Revert "Rename lua--function-name-rx, use it in font-lock keywords init", Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8e19d23 231/468: Add basic indentation tests, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6729533 234/468: Rewrite lua-send-buffer function (should fix issue #60), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode afc1ea0 235/468: Send init-code in lua-start-process, enable compilation-shell-minor-mode, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1ede907 242/468: Fix several cases for `indent-new-comment-line' (M-j), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6c55abb 245/468: Add lua-rx/-to-string wrappers to simplify writing Lua-specific regexps, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1452f8e 244/468: should-lua-indent: accept strings rather than lists to simplify writing tests,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode a0f3a6f 250/468: Simplify font-lock & imenu regexps with lua-rx, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e430d01 252/468: Remove deprecated test code from test/, put current code there instead, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1d21a10 259/468: Reorganize test structure, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode dc55356 261/468: lua-forward-regexp: make sure direction is `forward', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0a986f7 266/468: Add hideshow support for "repeat... until" blocks, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8d27d2c 268/468: fixed up tests && improved lua-kill-process, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 82daeb5 297/468: Merge pull request #88 from tarsius/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7b2c18c 305/468: Merge pull request #99 from tarsius/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6f4035a 315/468: Merge pull request #108 from ptrv/patch-1, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f2915c3 324/468: Add string tab escape test, Philip Kaludercic, 2021/08/05