Skip to content

Commit

Permalink
Update tests for error regions and add a few new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
cpitclaudel committed Jun 9, 2018
1 parent 22b3054 commit 9978ace
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
12 changes: 6 additions & 6 deletions flycheck-ert.el
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Defaults to `error'."
Like `with-temp-buffer', but resets the modification state of the
temporary buffer to make sure that it is properly killed even if
it has a backing file and is modified."
(declare (indent 0))
(declare (indent 0) (debug t))
`(with-temp-buffer
(unwind-protect
,(macroexp-progn body)
Expand All @@ -114,7 +114,7 @@ it has a backing file and is modified."
BODY is evaluated with `current-buffer' being a buffer with the
contents FILE-NAME."
(declare (indent 1))
(declare (indent 1) (debug t))
`(let ((file-name ,file-name))
(unless (file-exists-p file-name)
(error "%s does not exist" file-name))
Expand Down Expand Up @@ -337,9 +337,10 @@ Raise an assertion error if the buffer is not clear afterwards."
ERROR is a Flycheck error object."
(let* ((overlay (-first (lambda (ov) (equal (overlay-get ov 'flycheck-error)
error))
error))
(flycheck-overlays-in 0 (+ 1 (buffer-size)))))
(region (flycheck-error-region-for-mode error 'symbols))
(flycheck-highlighting-mode 'symbols)
(region (flycheck-error-region error))
(level (flycheck-error-level error))
(category (flycheck-error-level-overlay-category level))
(face (get category 'face))
Expand Down Expand Up @@ -436,8 +437,7 @@ resource directory."
Return non-nil if the point is at the N'th Flycheck error in the
current buffer. Otherwise return nil."
(let* ((error (nth (1- n) flycheck-current-errors))
(mode flycheck-highlighting-mode)
(region (flycheck-error-region-for-mode error mode)))
(region (flycheck-error-region error)))
(and (member error (flycheck-overlay-errors-at (point)))
(= (point) (car region)))))

Expand Down
46 changes: 46 additions & 0 deletions test/flycheck-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,26 @@


;;; Errors from syntax checks
(defun flycheck-error-line-region (err)
(flycheck--line-region
(flycheck-error-start-line err)
(flycheck-error-end-line err)
(flycheck-error-buffer err)))

(defun flycheck-error-column-region (err)
(-when-let* ((line (flycheck-error-start-line err))
(col (flycheck-error-start-column err))
(buf (flycheck-error-buffer err)))
(flycheck--column-region
(flycheck-line-column-to-position line col buf) buf)))

(defun flycheck-error-thing-region (thing err)
(-when-let* ((line (flycheck-error-start-line err))
(col (flycheck-error-start-column err))
(buf (flycheck-error-buffer err)))
(flycheck-bounds-of-thing-at-pos
thing (flycheck-line-column-to-position line col buf) buf)))

(ert-deftest flycheck-error-line-region ()
:tags '(error-api)
(flycheck-ert-with-temp-buffer
Expand Down Expand Up @@ -1333,6 +1353,10 @@
;; An incomplete expression
(should-not (flycheck-error-thing-region 'sexp (flycheck-error-new-at 2 5)))))

(defun flycheck-error-region-for-mode (err mode)
(let ((flycheck-highlighting-mode mode))
(flycheck-error-region err)))

(ert-deftest flycheck-error-region-for-mode ()
:tags '(error-api)
(flycheck-ert-with-temp-buffer
Expand Down Expand Up @@ -1366,6 +1390,28 @@
(should (= (flycheck-error-pos (flycheck-error-new-at 4 1)) 19))
(should (= (flycheck-error-pos (flycheck-error-new-at 4 nil)) 19))))

(ert-deftest flycheck-error-region ()
:tags '(error-api)
;; All these tests should be independent of the ambient `flycheck-highlighting-mode'
(flycheck-ert-with-temp-buffer
(insert " Hello\n World\n")
(should (equal (flycheck-error-region (flycheck-error-new-with-coords 1 1 1 3))
'(1 . 3)))
(should (equal (flycheck-error-region (flycheck-error-new-with-coords 1 4 1 6))
'(4 . 6)))
(should (equal (flycheck-error-region (flycheck-error-new-with-coords 1 nil 2 nil))
'(5 . 19)))
(should (equal (flycheck-error-region (flycheck-error-new-with-coords 2 4 nil 8))
'(14 . 18)))
(should (equal (flycheck-error-region (flycheck-error-new-with-coords 3 1 nil nil))
'(19 . 20)))
(should (equal (flycheck-error-region (flycheck-error-new-with-coords 4 1 12 15))
'(19 . 20)))
(should (equal (flycheck-error-region (flycheck-error-new-with-coords 4 nil 5 nil))
'(19 . 20)))))

;; (ert-deftest flycheck-error-coords ()

(ert-deftest flycheck-error-format-message-and-id/no-id ()
:tags '(error-api)
(should (string= (flycheck-error-format-message-and-id
Expand Down

0 comments on commit 9978ace

Please sign in to comment.