Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage&prints by actually checking indentation #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions test/tla-pcal-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
;; in the test file
(let ((lines (read-lines (test-file-path (concat test-name "." mode))))
(indent-func (if (equal mode "pcal")
#'pcal-mode--indent-column
#'tla-mode--indent-column)))
#'pcal-mode-indent-line
#'tla-mode-indent-line)))
(run-indent-test lines indent-func)))

(ert-deftest pcal-mode--indent-column-test () (indent-test "indent-columns" "pcal"))
Expand All @@ -73,19 +73,19 @@
(insert line "\n"))
(goto-char (point-min))
(forward-line n) ; Add something in to place point at various places in line?
(let ((expected-indent 0))
(save-excursion
(beginning-of-line)
(skip-chars-forward " ")
(setq expected-indent (current-column))
(beginning-of-line)
(delete-horizontal-space))
(let* ((pcal-mode-indent-offset 2) ; dynamic binding because of defvar
(actual-indent (funcall indent-func))
(exp-line (elt lines n)))
(let ((expected-indent (current-indentation))
(pcal-mode-indent-offset 2)
(indent-tabs-mode nil))
(delete-horizontal-space)
(funcall indent-func)
(let ((actual-indent (current-indentation))
(exp-line (elt lines n))
(actual-line (buffer-substring-no-properties
(line-beginning-position)
(line-end-position))))
;; Add enough extra data to make clear where the failure happened
(should (equal (list expected-indent (list 'line n) exp-line)
(list actual-indent (list 'line n) exp-line))))))))
(list actual-indent (list 'line n) actual-line))))))))

(ert-deftest tla-mode--keep-conjucts-indented ()
(let ((test-lines
Expand Down
11 changes: 4 additions & 7 deletions tla-pcal-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,8 @@
(defun tla-mode-indent-line ()
"Indent the current line according to TLA+ rules."
(interactive)
(save-excursion
(beginning-of-line)
(let ((col (tla-mode--indent-column)))
(when col
(indent-line-to col)))))
(when-let ((col (tla-mode--indent-column)))
(indent-line-to col)))

(defcustom pcal-mode-indent-offset 2
"Amount of columns to indent lines in PlusCal code."
Expand Down Expand Up @@ -226,7 +223,7 @@
".*;"
"Regexp for matching the end of a statement.")

(defvar pcal-mode--statement-begin-re
(defvar pcal-mode--variables-begin-re
(concat "^[[:blank:]]*variables?\\>")
"Regexp for matching the start of a statement.")

Expand Down Expand Up @@ -284,7 +281,7 @@ nil if the syntax isn't recognized for indentation."
(setq current (current-indentation)))
((looking-at-p pcal-mode--statement-end-re)
(setq after-stmt t))
((looking-at-p pcal-mode--statement-begin-re)
((looking-at-p pcal-mode--variables-begin-re)
(if after-stmt
(setq current (current-indentation))
(setq current (+ (current-indentation) pcal-mode-indent-offset))))
Expand Down