[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 8e19d23 231/468: Add basic indentation tests
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 8e19d23 231/468: Add basic indentation tests |
Date: |
Thu, 5 Aug 2021 04:58:42 -0400 (EDT) |
branch: elpa/lua-mode
commit 8e19d2336638520485ad4bbeca5082e5222bbcdd
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Add basic indentation tests
---
Makefile | 1 +
ert-tests/lua-font-lock-test-helpers.el | 24 ++++
ert-tests/test-indentation.el | 210 ++++++++++++++++++++++++++++++++
3 files changed, 235 insertions(+)
diff --git a/Makefile b/Makefile
index 24f6f2a..3496186 100644
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,7 @@ TESTS=
TESTS += ert-tests/test-defun-font-lock.el
TESTS += ert-tests/test-builtin-font-lock.el
TESTS += ert-tests/test-electric-mode.el
+TESTS += ert-tests/test-indentation.el
default:
@echo version is $(VERSION)
diff --git a/ert-tests/lua-font-lock-test-helpers.el
b/ert-tests/lua-font-lock-test-helpers.el
index d0495f8..e52fc0f 100644
--- a/ert-tests/lua-font-lock-test-helpers.el
+++ b/ert-tests/lua-font-lock-test-helpers.el
@@ -52,4 +52,28 @@ This is a mere typing/reading aid for lua-mode's font-lock
tests."
;; suppress fontification messages in emacs23 output
(setq font-lock-verbose nil)
+
+(defmacro with-lua-buffer (&rest body)
+ `(with-temp-buffer
+ (switch-to-buffer (current-buffer))
+ (lua-mode)
+ (font-lock-fontify-buffer)
+ ,@body))
+
+(defun lua-get-indented-strs (strs)
+ (butlast
+ (split-string
+ (with-lua-buffer
+ (insert (replace-regexp-in-string
+ "^\\s *" "" (mapconcat (lambda (x) (concat x "\n")) strs "")))
+ (indent-region (point-min) (point-max))
+ (buffer-substring-no-properties
+ (point-min) (point-max)))
+ "\n" nil)))
+
+(defmacro should-lua-indent (strs)
+ `(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
new file mode 100644
index 0000000..f3122bf
--- /dev/null
+++ b/ert-tests/test-indentation.el
@@ -0,0 +1,210 @@
+(require 'cl)
+(require 'ert)
+(require 'lua-font-lock-test-helpers
+ ;; let's try a bit to help Emacs find the helpers, just in case
+ (concat (file-name-directory (or load-file-name (buffer-file-name)
+ default-directory))
+ "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")))
+
+(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")))
+
+
+(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)")))
+
+
+(ert-deftest lua-indentation-binop-continuation ()
+ (let ((binops '("+" "-" "*" "/" "^" "%" ".."
+ "<" "<=" ">" ">=" "==" "~="
+ "and" "or")))
+ (cl-dolist (binop binops)
+ (should-lua-indent `(,(concat "a = foo " binop)
+ " bar"))
+ (should-lua-indent `("a = foo "
+ ,(mapconcat 'identity '(" " " bar") binop))))))
+
+(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"))
+
+ ;; 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 ()
+ ;; 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")))
+
+(ert-deftest lua-indentation-functioncall ()
+ ;; FIXME: add
+ ;; FIXME: test bare tablector variant
+ ;; FIXME: test interaction with continuation
+ )
+
+(ert-deftest lua-indentation-conditional ()
+ ;; if exp then block {elseif exp then block} [else block] end
+ ;; FIXME: add
+ )
+
+(ert-deftest lua-indentation-defun ()
+ ;; [local] function funcname funcbody
+ ;; FIXME: add
+ )
+
+(ert-deftest lua-indentation-alignment ()
+ ;; FIXME: add
+ )
+
+(ert-deftest lua-indentation-tablector ()
+ ;; FIXME: add
+ )
- [nongnu] elpa/lua-mode b1dc70c 158/468: lua-font-lock-keywords: highlight builtin symbols (issue #15), (continued)
- [nongnu] elpa/lua-mode b1dc70c 158/468: lua-font-lock-keywords: highlight builtin symbols (issue #15), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 52dcf7b 167/468: Merge pull request #35 from vhallac/fix-34, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a3016a2 176/468: Avoid polluting "global namespace" when striving for backward compatibility, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b124dd0 194/468: Add field containing commit SHA expanded during archive creation., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 64c1e94 197/468: lua--builtins: add "self" as keyword, Philip Kaludercic, 2021/08/05
- [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 <=
- [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, 2021/08/05
- [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