From aaa3fd7249d6f36b421bbefd90397ed3420ff5bd Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Sat, 10 Jan 2015 14:55:02 +0100 Subject: [PATCH 1/5] Add tests for haskell-simple-indent-backtab. Function haskell-simple-indent-backtab is supposed to work as a dual to haskell-simple-indent, this is not the case right now. Add two expected failure test cases that build up for upcoming fix. --- tests/haskell-simple-indent-tests.el | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/haskell-simple-indent-tests.el b/tests/haskell-simple-indent-tests.el index ae9bb8f00..bb44e6340 100644 --- a/tests/haskell-simple-indent-tests.el +++ b/tests/haskell-simple-indent-tests.el @@ -13,6 +13,23 @@ (setq result (cons (current-column) result))) (reverse result)))) + +(defun find-indent-and-backtab-positions (lines-above-content) + (with-temp-buffer + (dolist (line lines-above-content) + (insert line) + (insert "\n")) + ;; cursor is at the beginning of the second line now + (let ((result-forward '()) + (result-backward '())) + (dotimes (i 10) + (haskell-simple-indent) + (setq result-forward (cons (current-column) result-forward))) + (dotimes (i 10) + (setq result-backward (cons (current-column) result-backward)) + (haskell-simple-indent-backtab)) + (list (reverse result-forward) result-backward)))) + (ert-deftest find-indent-positions-1 () (should (equal '(5 7 10 19 26 32 40 48 56 64) (find-indent-positions '("main = do putStrLn \"Hello World!\""))))) @@ -33,3 +50,16 @@ (should (equal '(2 4 5 8 16 24 32 40 48 56) (find-indent-positions '("a b c d e f g h" " long_streak"))))) + +(ert-deftest find-indent-and-backtab-positions-1 () + :expected-result :failed + (should (equal '((2 4 5 8 16 24 32 40 48 56) + (2 4 5 8 16 24 32 40 48 56)) + (find-indent-and-backtab-positions '("a b c d e f g h" + " long_streak"))))) + +(ert-deftest find-indent-and-backtab-positions-2 () + :expected-result :failed + (should (equal '((8 10 13 20 24 27 32 35 37 45) + (8 10 13 20 24 27 32 35 37 45)) + (find-indent-and-backtab-positions '("\tx <- return 123 {- This is a comment -}"))))) From ec0e327ce59198c7238486dbc43a89fe3a591141 Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Thu, 15 Jan 2015 14:48:08 +0100 Subject: [PATCH 2/5] Tabs/no-tabs tests for haskell-simple-indent. haskell-simple-indent[-backtab] behave badly only when tabs are present. Make tests exhibit that behavior. --- tests/haskell-simple-indent-tests.el | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/haskell-simple-indent-tests.el b/tests/haskell-simple-indent-tests.el index bb44e6340..7312316b2 100644 --- a/tests/haskell-simple-indent-tests.el +++ b/tests/haskell-simple-indent-tests.el @@ -14,8 +14,10 @@ (reverse result)))) -(defun find-indent-and-backtab-positions (lines-above-content) +(defun find-indent-and-backtab-positions (lines-above-content &optional prepare-buffer) (with-temp-buffer + (if prepare-buffer + (funcall prepare-buffer)) (dolist (line lines-above-content) (insert line) (insert "\n")) @@ -52,6 +54,16 @@ " long_streak"))))) (ert-deftest find-indent-and-backtab-positions-1 () + (should (equal '((2 4 5 8 16 24 32 40 48 56) + (2 4 5 8 16 24 32 40 48 56)) + ;; Note: haskell-simple-indent-backtab is broken when + ;; it encounters TABs in source file. + (find-indent-and-backtab-positions '("a b c d e f g h" + " long_streak") + (lambda () + (setq indent-tabs-mode nil)))))) + +(ert-deftest find-indent-and-backtab-positions-1a () :expected-result :failed (should (equal '((2 4 5 8 16 24 32 40 48 56) (2 4 5 8 16 24 32 40 48 56)) @@ -59,6 +71,13 @@ " long_streak"))))) (ert-deftest find-indent-and-backtab-positions-2 () + (should (equal '((8 10 13 20 24 27 32 35 37 45) + (8 10 13 20 24 27 32 35 37 45)) + (find-indent-and-backtab-positions '("\tx <- return 123 {- This is a comment -}") + (lambda () + (setq-local indent-tabs-mode nil)))))) + +(ert-deftest find-indent-and-backtab-positions-2a () :expected-result :failed (should (equal '((8 10 13 20 24 27 32 35 37 45) (8 10 13 20 24 27 32 35 37 45)) From 750946872ad03728b98328d1058eaf0eeff0f5de Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Fri, 16 Jan 2015 12:10:50 +0100 Subject: [PATCH 3/5] Add more tests for simple-indent. --- tests/haskell-simple-indent-tests.el | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/haskell-simple-indent-tests.el b/tests/haskell-simple-indent-tests.el index 7312316b2..129876e49 100644 --- a/tests/haskell-simple-indent-tests.el +++ b/tests/haskell-simple-indent-tests.el @@ -53,6 +53,16 @@ (find-indent-positions '("a b c d e f g h" " long_streak"))))) +(ert-deftest find-indent-positions-5 () + (should (equal '(2 4 6 13 15 17 19 24 32 40) + (find-indent-positions '(" f g e e iirelevant" + "a b c d" + " h idden" + " hidden" + "" + " e f g h" + ""))))) + (ert-deftest find-indent-and-backtab-positions-1 () (should (equal '((2 4 5 8 16 24 32 40 48 56) (2 4 5 8 16 24 32 40 48 56)) @@ -82,3 +92,28 @@ (should (equal '((8 10 13 20 24 27 32 35 37 45) (8 10 13 20 24 27 32 35 37 45)) (find-indent-and-backtab-positions '("\tx <- return 123 {- This is a comment -}"))))) + +(ert-deftest find-indent-and-backtab-positions-3 () + (should (equal '((2 4 6 13 15 17 19 24 32 40) + (2 4 6 13 15 17 19 24 32 40)) + (find-indent-and-backtab-positions '(" f g e e iirelevant" + "a b c d" + " h idden x" + " hidden 4 5" + "" + " e f g h" + "") + (lambda () + (setq-local indent-tabs-mode nil)))))) + +(ert-deftest find-indent-and-backtab-positions-3a () + :expected-result :failed + (should (equal '((2 4 6 13 15 17 19 24 32 40) + (2 4 6 13 15 17 19 24 32 40)) + (find-indent-and-backtab-positions '(" f g e e iirelevant" + "a b c d" + " h idden x" + " hidden 4 5" + "" + " e f g h" + ""))))) From 85021791c60084146906f78bf2c1868ba65182f9 Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Fri, 16 Jan 2015 13:29:55 +0100 Subject: [PATCH 4/5] Tests for backtab no longer fail. --- tests/haskell-simple-indent-tests.el | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/haskell-simple-indent-tests.el b/tests/haskell-simple-indent-tests.el index 129876e49..f78412585 100644 --- a/tests/haskell-simple-indent-tests.el +++ b/tests/haskell-simple-indent-tests.el @@ -74,7 +74,6 @@ (setq indent-tabs-mode nil)))))) (ert-deftest find-indent-and-backtab-positions-1a () - :expected-result :failed (should (equal '((2 4 5 8 16 24 32 40 48 56) (2 4 5 8 16 24 32 40 48 56)) (find-indent-and-backtab-positions '("a b c d e f g h" @@ -88,7 +87,6 @@ (setq-local indent-tabs-mode nil)))))) (ert-deftest find-indent-and-backtab-positions-2a () - :expected-result :failed (should (equal '((8 10 13 20 24 27 32 35 37 45) (8 10 13 20 24 27 32 35 37 45)) (find-indent-and-backtab-positions '("\tx <- return 123 {- This is a comment -}"))))) @@ -107,7 +105,6 @@ (setq-local indent-tabs-mode nil)))))) (ert-deftest find-indent-and-backtab-positions-3a () - :expected-result :failed (should (equal '((2 4 6 13 15 17 19 24 32 40) (2 4 6 13 15 17 19 24 32 40)) (find-indent-and-backtab-positions '(" f g e e iirelevant" From bf9df35b69ca6f70f0d2d8dda4c8d1bea848a14e Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Fri, 16 Jan 2015 20:02:41 +0100 Subject: [PATCH 5/5] Tests for first column handling. --- tests/haskell-simple-indent-tests.el | 31 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/haskell-simple-indent-tests.el b/tests/haskell-simple-indent-tests.el index f78412585..175adaa94 100644 --- a/tests/haskell-simple-indent-tests.el +++ b/tests/haskell-simple-indent-tests.el @@ -22,14 +22,15 @@ (insert line) (insert "\n")) ;; cursor is at the beginning of the second line now - (let ((result-forward '()) + (let ((result-forward '(0)) (result-backward '())) - (dotimes (i 10) + (dotimes (i 9) (haskell-simple-indent) (setq result-forward (cons (current-column) result-forward))) - (dotimes (i 10) + (dotimes (i 9) (setq result-backward (cons (current-column) result-backward)) (haskell-simple-indent-backtab)) + (setq result-backward (cons (current-column) result-backward)) (list (reverse result-forward) result-backward)))) (ert-deftest find-indent-positions-1 () @@ -64,8 +65,8 @@ ""))))) (ert-deftest find-indent-and-backtab-positions-1 () - (should (equal '((2 4 5 8 16 24 32 40 48 56) - (2 4 5 8 16 24 32 40 48 56)) + (should (equal '((0 2 4 5 8 16 24 32 40 48) + (0 2 4 5 8 16 24 32 40 48)) ;; Note: haskell-simple-indent-backtab is broken when ;; it encounters TABs in source file. (find-indent-and-backtab-positions '("a b c d e f g h" @@ -74,26 +75,26 @@ (setq indent-tabs-mode nil)))))) (ert-deftest find-indent-and-backtab-positions-1a () - (should (equal '((2 4 5 8 16 24 32 40 48 56) - (2 4 5 8 16 24 32 40 48 56)) + (should (equal '((0 2 4 5 8 16 24 32 40 48) + (0 2 4 5 8 16 24 32 40 48)) (find-indent-and-backtab-positions '("a b c d e f g h" " long_streak"))))) (ert-deftest find-indent-and-backtab-positions-2 () - (should (equal '((8 10 13 20 24 27 32 35 37 45) - (8 10 13 20 24 27 32 35 37 45)) + (should (equal '((0 8 10 13 20 24 27 32 35 37) + (0 8 10 13 20 24 27 32 35 37)) (find-indent-and-backtab-positions '("\tx <- return 123 {- This is a comment -}") (lambda () (setq-local indent-tabs-mode nil)))))) (ert-deftest find-indent-and-backtab-positions-2a () - (should (equal '((8 10 13 20 24 27 32 35 37 45) - (8 10 13 20 24 27 32 35 37 45)) + (should (equal '((0 8 10 13 20 24 27 32 35 37) + (0 8 10 13 20 24 27 32 35 37)) (find-indent-and-backtab-positions '("\tx <- return 123 {- This is a comment -}"))))) (ert-deftest find-indent-and-backtab-positions-3 () - (should (equal '((2 4 6 13 15 17 19 24 32 40) - (2 4 6 13 15 17 19 24 32 40)) + (should (equal '((0 2 4 6 13 15 17 19 24 32) + (0 2 4 6 13 15 17 19 24 32)) (find-indent-and-backtab-positions '(" f g e e iirelevant" "a b c d" " h idden x" @@ -105,8 +106,8 @@ (setq-local indent-tabs-mode nil)))))) (ert-deftest find-indent-and-backtab-positions-3a () - (should (equal '((2 4 6 13 15 17 19 24 32 40) - (2 4 6 13 15 17 19 24 32 40)) + (should (equal '((0 2 4 6 13 15 17 19 24 32) + (0 2 4 6 13 15 17 19 24 32)) (find-indent-and-backtab-positions '(" f g e e iirelevant" "a b c d" " h idden x"