emacs-elpa-diffs
[Top][All Lists]
Advanced

[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
+  )



reply via email to

[Prev in Thread] Current Thread [Next in Thread]