Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests/haskell-indentation-tests.el
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(require 'ert) | ||
(require 'haskell-indentation) | ||
(require 'haskell-mode) | ||
(require 'cl-lib) | ||
|
||
|
||
(defun haskell-indentation-check-on-last-line (lines expected) | ||
(with-temp-buffer | ||
(haskell-mode) | ||
(haskell-indentation-mode) | ||
;; insert lines | ||
(dolist (line lines) | ||
(insert line) | ||
(insert "\n")) | ||
(forward-line -1) | ||
(let ((indentations (haskell-indentation-find-indentations)) | ||
(result "") ) | ||
|
||
(dotimes (i (1+ (apply #'max indentations))) | ||
(setq result (concat result (if (memq i indentations) | ||
"^" " ")))) | ||
|
||
(should (equal (car expected) result))))) | ||
|
||
|
||
(ert-deftest haskell-indentation-check-1 () | ||
"Check if '{' on its own line gets properly indented" | ||
(haskell-indentation-check-on-last-line | ||
'("function = Record" | ||
" { field = 123 }") | ||
'("^ ^"))) | ||
|
||
(ert-deftest haskell-indentation-check-2 () | ||
"Handle underscore in identifiers" | ||
(haskell-indentation-check-on-last-line | ||
'("function = do" | ||
" (_x) <- return ()" | ||
" z") | ||
'("^ ^ ^"))) |