branch: elpa/lua-mode
commit e97861cb36509c0a206bcbcc92ebd2d8a8ddb0d0
Author: immerrr <[email protected]>
Commit: immerrr <[email protected]>
ert-tests/test-electric-mode.el: add tests for electric indentation
---
Cask | 3 ++
Makefile | 1 +
ert-tests/test-electric-mode.el | 65 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+)
diff --git a/Cask b/Cask
index 9dcc96b..8f1dd5a 100644
--- a/Cask
+++ b/Cask
@@ -2,6 +2,9 @@
(package "lua-mode" "dev" "Major mode for editing Lua")
+(development
+ (depends-on "s"))
+
;; Local Variables:
;; mode: emacs-lisp
;; End:
diff --git a/Makefile b/Makefile
index 1cacc2c..24f6f2a 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@ EMACS_BATCH=cask exec $(EMACS) --batch -Q
TESTS=
TESTS += ert-tests/test-defun-font-lock.el
TESTS += ert-tests/test-builtin-font-lock.el
+TESTS += ert-tests/test-electric-mode.el
default:
@echo version is $(VERSION)
diff --git a/ert-tests/test-electric-mode.el b/ert-tests/test-electric-mode.el
new file mode 100644
index 0000000..f05259f
--- /dev/null
+++ b/ert-tests/test-electric-mode.el
@@ -0,0 +1,65 @@
+(require 'ert)
+(require 's)
+
+(defmacro with-lua-buffer (&rest body)
+ `(with-temp-buffer
+ (switch-to-buffer (current-buffer))
+ (lua-mode)
+ (font-lock-fontify-buffer)
+ ,@body))
+
+
+(ert-deftest test-electric-brace ()
+ (with-lua-buffer
+ (execute-kbd-macro (kbd "return SPC foo SPC { C-j"))
+ (execute-kbd-macro (kbd "'baz' C-j"))
+ (should (eq (current-indentation) lua-indent-level))
+
+ (execute-kbd-macro (kbd "}"))
+ (should (eq (current-indentation) 0))))
+
+
+(ert-deftest test-electric-paren ()
+ (with-lua-buffer
+ (execute-kbd-macro (kbd "return SPC foo SPC ( C-j"))
+ (execute-kbd-macro (kbd "'baz' C-j"))
+ (should (eq (current-indentation) lua-indent-level))
+
+ (execute-kbd-macro (kbd ")"))
+ (should (eq (current-indentation) 0))))
+
+
+(ert-deftest test-electric-end ()
+ (with-lua-buffer
+ (execute-kbd-macro (kbd "if SPC foo SPC then C-j"))
+ (execute-kbd-macro (kbd "'baz' C-j"))
+ (should (eq (current-indentation) lua-indent-level))
+
+ (abbrev-mode 1)
+ (execute-kbd-macro (kbd "end C-j"))
+ (beginning-of-line 0)
+ (should (eq (current-indentation) 0))))
+
+
+(ert-deftest test-electric-else ()
+ (with-lua-buffer
+ (execute-kbd-macro (kbd "if SPC foo SPC then C-j"))
+ (execute-kbd-macro (kbd "'baz' C-j"))
+ (should (eq (current-indentation) lua-indent-level))
+
+ (abbrev-mode 1)
+ (execute-kbd-macro (kbd "else C-j"))
+ (beginning-of-line 0)
+ (should (eq (current-indentation) 0))))
+
+
+(ert-deftest test-electric-elseif ()
+ (with-lua-buffer
+ (execute-kbd-macro (kbd "if SPC foo SPC then C-j"))
+ (execute-kbd-macro (kbd "'baz' C-j"))
+ (should (eq (current-indentation) lua-indent-level))
+
+ (abbrev-mode 1)
+ (execute-kbd-macro (kbd "elseif C-j"))
+ (beginning-of-line 0)
+ (should (eq (current-indentation) 0))))