Skip to content

Commit 3d3dac7

Browse files
committed
Merge pull request #1151 from cruegge/master
Add test and fixes for forward-sexp-function
2 parents da11b78 + e8f9a82 commit 3d3dac7

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

haskell-mode.el

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,16 @@ Note that negative arguments do not work so well."
860860
(goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
861861
(backward-prefix-chars))
862862
(save-match-data
863-
(if (haskell-lexeme-looking-at-token)
864-
(if (member (match-string 0) (list "(" "[" "{"))
865-
(goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
866-
(goto-char (match-end 0)))))))
863+
(while (> arg 0)
864+
(when (haskell-lexeme-looking-at-token)
865+
(cond ((member (match-string 0) (list "(" "[" "{"))
866+
(goto-char (or (scan-sexps (point) 1) (buffer-end 1))))
867+
((member (match-string 0) (list ")" "]" "}"))
868+
(signal 'scan-error (list "Containing expression ends prematurely."
869+
(match-beginning 0)
870+
(match-end 0))))
871+
(t (goto-char (match-end 0)))))
872+
(setf arg (1- arg))))))
867873

868874

869875

tests/haskell-mode-tests.el

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,58 @@ Also should respect 10 column fill."
410410
(string= "hello world"
411411
(buffer-substring 1 (point-max))))))
412412

413+
(ert-deftest forward-sexp-function-1 ()
414+
"Check if `forward-sexp-function' behaves properly on end of
415+
sexp."
416+
(should (with-temp-buffer
417+
(haskell-mode)
418+
(insert "(foo) bar")
419+
(goto-char 5)
420+
(condition-case err
421+
(progn (forward-sexp)
422+
nil)
423+
(scan-error (equal (cddr err) (list 5 6)))))))
424+
425+
(ert-deftest forward-sexp-function-2 ()
426+
"Check if `forward-sexp-function' behaves properly on beginning
427+
of sexp."
428+
(should (with-temp-buffer
429+
(haskell-mode)
430+
(insert "(foo) bar")
431+
(goto-char 1)
432+
(forward-sexp)
433+
(eq (point) 6))))
434+
435+
(ert-deftest haskell-forward-sexp-1 ()
436+
"Check if `haskell-forward-sexp' properly moves over sexps."
437+
(should (with-temp-buffer
438+
(insert "foo = bar . baz")
439+
(goto-char 1)
440+
(haskell-forward-sexp 4)
441+
(eq (point) 12))))
442+
443+
(ert-deftest haskell-forward-sexp-2 ()
444+
"Check if `haskell-forward-sexp' properly moves over sexps."
445+
(should (with-temp-buffer
446+
(insert "foo = bar . baz")
447+
(goto-char 1)
448+
(haskell-forward-sexp 1)
449+
(eq (point) 4))))
450+
451+
(ert-deftest haskell-forward-sexp-3 ()
452+
"Check if `haskell-forward-sexp' properly moves over sexps."
453+
(should (with-temp-buffer
454+
(insert "(a b) c = d . e")
455+
(goto-char 1)
456+
(haskell-forward-sexp 5)
457+
(eq (point) 14))))
458+
459+
(ert-deftest haskell-forward-sexp-4 ()
460+
"Check if `haskell-forward-sexp' properly moves over sexps."
461+
(should (with-temp-buffer
462+
(insert "(a b) c = d . e")
463+
(goto-char 1)
464+
(haskell-forward-sexp 1)
465+
(eq (point) 6))))
466+
413467
(provide 'haskell-mode-tests)

0 commit comments

Comments
 (0)