Skip to content

M-q fix and tests #441

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

Merged
merged 2 commits into from
Jan 20, 2015
Merged
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
8 changes: 4 additions & 4 deletions haskell-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,11 @@ see documentation for that variable for more details."
(forward-sexp)
;; Find end of any comment even if forward-sexp
;; fails to find the right braces.
(backward-char 2)
(re-search-forward "-}" nil t)
(point)))
(backward-char 3)
(re-search-forward "[ \t]?-}" nil t)
(match-beginning 0)))
(fill-start (+ 2 comment-start-point))
(fill-end (- comment-end-point 2))
(fill-end comment-end-point)
(fill-paragraph-handle-comment nil))
(save-restriction
(narrow-to-region fill-start fill-end)
Expand Down
152 changes: 152 additions & 0 deletions tests/haskell-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,156 @@
(insert "Äöèąċōïá")
(string= "Äöèąċōïá" (haskell-ident-at-point)))))

(defun check-fill (expected initial)
"Check using ERT if `fill-paragraph' over `initial' gives
`expected' result. Cursor fill be positioned at '@' character or at
the beginning of the buffer.

`fill-column' will be set to 10 so that it is easy to spot issues."
(should (equal expected
(with-temp-buffer
(haskell-mode)
(setq fill-column 10)
(dolist (line initial)
(insert line)
(insert "\n"))
(goto-char (point-min))
(skip-chars-forward "^@")
(if (eobp)
(goto-char (point-min))
(delete-char 1))
(fill-paragraph nil)
(split-string (buffer-substring-no-properties (point-min) (1- (point-max))) "\n")))))

(ert-deftest fill-comment-1 ()
(check-fill '("{- a -}")
'("{- @a -}")))

(ert-deftest fill-comment-2 ()
(check-fill '("{- a b c d e"
"f g h i j"
"k -}")
'("{- @a b c d e f g h i j k -}")))

(ert-deftest fill-comment-3 ()
(check-fill '("{-"
"a"
"-}")
'("{-"
"@a"
"-}")))

(ert-deftest fill-comment-4 ()
(check-fill '("{-"
"a b c d e"
"f g h i-}")
'("{-"
"@a"
"b"
"c"
"d e f g h i-}")))

(ert-deftest fill-comment-5 ()
(check-fill '(" {-"
" a b c d e"
"f g h i"
" -}")
'(" {-" " @a b c d e f g h i" " -}")))

(ert-deftest fill-comment-6 ()
(check-fill '(" -- a b c"
" -- d e f"
" -- g h i"
" -- j k l"
" -- m n o"
" -- p q r"
" -- s t u"
" -- v")
'(" -- @a b c d e f g h i j k l m n o p q r s t u v")))

(ert-deftest fill-comment-7 ()
(check-fill '(" -- a b"
" -- c d"
" -- e f"
" -- g h"
" -- i j")
'(" -- @a b c d e f g h i j ")))

(ert-deftest fill-comment-8 ()
"Note: first letter of second line should be in the same column
as first letter in the first line.

Also should respect 10 column fill."
:expected-result :failed
(check-fill '(" {- a b"
" c d"
" e f"
" g h"
" i j"
" -}")
'(" {- @a b c d e f g h i j"
" -}")))

(ert-deftest fill-comment-9 ()
"Note: first letter in the second line position should be kept
as defined, just the content should move properly.

Also should respect 10 column fill."
:expected-result :failed
(check-fill '(" {- a b"
" c d e"
" f g h"
" i j"
" -}")
'(" {- @a"
" b c d e f g h i j"
" -}")))

(ert-deftest fill-comment-10 ()
"Note: first letter in the second line position should be kept
as defined, just the content should move properly. Following
lines should take position from second line.

Also should respect 10 column fill."
:expected-result :failed
(check-fill '(" {- a b"
" c d e"
" f g h"
" i j"
" -}")
'(" {- @a"
" b c d e"
" f g h"
" i j"
" -}")))

(ert-deftest fill-comment-11 ()
"Note: first letter in the second line position should be kept
as defined, just the content should move properly.

Also should respect 10 column fill."
:expected-result :failed
(check-fill '(" -- a b"
" -- c d e"
" -- f g h"
" -- i j")
'(" -- @a"
" -- b c d e f g h i j")))

(ert-deftest fill-comment-12 ()
"Note: first letter in the second line position should be kept
as defined, just the content should move properly. Following
lines should take position from second line.

Also should respect 10 column fill."
:expected-result :failed
(check-fill '(" -- a b"
" -- c d e"
" -- f g h"
" -- i j")
'(" -- @a"
" -- b c d e"
"--f g h"
" -- i j")))

(provide 'haskell-mode-tests)