[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode 66bfbc5 056/496: Add indentation tests, add mak
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode 66bfbc5 056/496: Add indentation tests, add makefile runner task |
Date: |
Sun, 29 Aug 2021 11:33:07 -0400 (EDT) |
branch: elpa/swift-mode
commit 66bfbc516c6fac317c25371ea55e8f275d05953e
Author: Chris Barrett <chris.d.barrett@me.com>
Commit: Chris Barrett <chris.d.barrett@me.com>
Add indentation tests, add makefile runner task
Run `make check` to run tests
---
Cask | 1 +
Makefile | 9 +-
test/indentation-tests.el | 234 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 243 insertions(+), 1 deletion(-)
diff --git a/Cask b/Cask
index 1bb5d9f..6b3af1d 100644
--- a/Cask
+++ b/Cask
@@ -4,5 +4,6 @@
(package-file "swift-mode.el")
(development
+ (depends-on "s")
(depends-on "flycheck")
(depends-on "flycheck-cask"))
diff --git a/Makefile b/Makefile
index 652c50f..7769b1b 100644
--- a/Makefile
+++ b/Makefile
@@ -20,6 +20,13 @@ deps : $(PKG_DIR)
$(PKG_DIR) :
$(CASK) install
+.PHONY: check
+check : deps
+ $(CASK) exec $(EMACS) $(EMACSFLAGS) \
+ $(patsubst %,-l % , $(SRCS))\
+ $(patsubst %,-l % , $(TESTS))\
+ -f ert-run-tests-batch-and-exit
+
.PHONY: install
install : $(DIST) $(USER_ELPA_D)
$(EMACS) $(EMACSFLAGS) -l package \
@@ -38,7 +45,7 @@ clean-all : clean
.PHONY: clean
clean :
- cask clean-elc
+ $(CASK) clean-elc
rm -f *.elc
rm -rf $(DIST)
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
new file mode 100644
index 0000000..f10c9eb
--- /dev/null
+++ b/test/indentation-tests.el
@@ -0,0 +1,234 @@
+;;; indentation-tests.el --- Test swift-mode indentation behaviour
+
+;; Copyright (C) 2014 Chris Barrett
+
+;; Author: Chris Barrett <chris.d.barrett@me.com>
+;; Version: 0.1
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Test swift-mode indentation behaviour
+
+;;; Code:
+
+(require 'ert)
+(require 'swift-mode)
+(require 's)
+
+(defmacro check-indentation (description before after)
+ "Declare an ert test for indentation behaviour.
+The test will check that the swift indentation command results changes the
+buffer from one state to another. It will also test that point is moved to
+an expected position.
+
+DESCRIPTION is a symbol describing the test.
+
+BEFORE is the buffer string before indenting, where a pipe (|) represents
+point.
+
+AFTER is the expected buffer string after indenting, where a pipe (|)
+represents the expected position of point."
+ (declare (indent 1))
+ (let ((fname (intern (format "indentation/%s" description))))
+ `(ert-deftest ,fname ()
+ (let* ((after ,after)
+ (expected-cursor-pos (1+ (s-index-of "|" after)))
+ (expected-state (delete ?| after))
+
+ ;; Set the offset to a consistent value for tests.
+ (swift-indent-offset 4))
+ (with-temp-buffer
+ (insert ,before)
+ (goto-char (point-min))
+ (search-forward "|")
+ (delete-char -1)
+ (swift-mode)
+ (indent-according-to-mode)
+
+ (should (equal expected-state (buffer-string)))
+ (should (equal expected-cursor-pos (point))))))))
+
+(check-indentation no-indentation-at-top-level
+ "|x"
+ "|x")
+
+(check-indentation toplevel-exprs-indented-to-same-level/1
+ "
+x
+|y
+" "
+x
+|y
+")
+
+(check-indentation toplevel-exprs-indented-to-same-level/2
+ "
+x
+ |y
+" "
+x
+|y
+")
+
+(check-indentation nested-exprs-indented-to-same-level/1
+ "
+{
+ x
+ |y
+}
+" "
+{
+ x
+ |y
+}
+")
+
+(check-indentation nested-exprs-indented-to-same-level/2
+ "
+{
+ x
+ |y
+}
+" "
+{
+ x
+ |y
+}
+")
+
+(check-indentation nested-exprs-indented-to-same-level/3
+ "
+{
+ x
+|y
+}
+" "
+{
+ x
+ |y
+}
+")
+
+(check-indentation indent-if-body
+ "
+if true {
+|x
+}
+" "
+if true {
+ |x
+}
+")
+
+(check-indentation indent-if-body--no-effect-if-already-indented
+ "
+if true {
+ |x
+}
+""
+if true {
+ |x
+}
+")
+
+(check-indentation indents-case-statements-to-same-level-as-enclosing-switch/1
+ "
+switch true {
+ |case
+}
+" "
+switch true {
+|case
+}
+")
+
+(check-indentation indents-case-statements-to-same-level-as-enclosing-switch/2
+ "
+switch true {
+ |case
+}
+" "
+switch true {
+|case
+}
+")
+
+(check-indentation indents-case-statements-to-same-level-as-enclosing-switch/3
+ "
+{
+ switch true {
+|case
+ }
+}
+" "
+{
+ switch true {
+ |case
+ }
+}
+")
+
+(check-indentation indents-case-statements-to-same-level-as-enclosing-switch/4
+ "
+{
+ switch true {
+ |case
+ }
+}
+" "
+{
+ switch true {
+ |case
+ }
+}
+")
+
+
+(check-indentation
indents-default-statements-to-same-level-as-enclosing-switch/1
+ "
+{
+ switch true {
+|default
+ }
+}
+" "
+{
+ switch true {
+ |default
+ }
+}
+")
+
+(check-indentation
indents-default-statements-to-same-level-as-enclosing-switch/2
+ "
+{
+ switch true {
+ |default
+ }
+}
+" "
+{
+ switch true {
+ |default
+ }
+}
+")
+
+(provide 'indentation-tests)
+
+;;; indentation-tests.el ends here
- [nongnu] elpa/swift-mode 02a1726 476/496: Introduce some font-lock tests, (continued)
- [nongnu] elpa/swift-mode 02a1726 476/496: Introduce some font-lock tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode abbd06e 478/496: Fix error on indenting a closing paren outside strings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode ad12a30 486/496: Remove Cask from README, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 1b47a09 495/496: Bump version to 8.3.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 561cacb 043/496: Code style, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 396f297 058/496: Fix test docstring typo, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 60956cb 081/496: fixup! Add swift repl commands to mode map, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d59cae7 355/496: Fix indentation of string interpolations, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 2aeef85 425/496: Update copyright notice, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 490ab34 051/496: Simplify indentation command, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 66bfbc5 056/496: Add indentation tests, add makefile runner task,
ELPA Syncer <=
- [nongnu] elpa/swift-mode ead0ae5 055/496: Fix spelling error in readme, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 049c6d6 439/496: Use `assoc-default`, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode ba4d981 473/496: Use seq-contains-p if available, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 86f8f62 447/496: Bump version to 8.0.1, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 90686cb 450/496: Add `some` keyword of Swift 5.1, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode acfc7fd 452/496: Fix comments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0daff60 463/496: Fix unreadable characters appearing in repl prompt, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 5597eaf 467/496: Avoid max-lisp-eval-depth in font-lock-match-expr, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8f1a697 483/496: Fix documentations, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cb6186e 474/496: Add support for font-lock-negation-char-face, ELPA Syncer, 2021/08/29