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

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



reply via email to

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