|
| 1 | +;;; haskell-utils-tests.el --- Tests for Haskell utilities package |
| 2 | + |
| 3 | +;; Copyright © 2016 Athur Fayzrakhmanov. All rights reserved. |
| 4 | + |
| 5 | +;; This file is part of haskell-mode package. |
| 6 | +;; You can contact with authors using GitHub issue tracker: |
| 7 | +;; https://github.com/haskell/haskell-mode/issues |
| 8 | + |
| 9 | +;; This file is free software; you can redistribute it and/or modify |
| 10 | +;; it under the terms of the GNU General Public License as published by |
| 11 | +;; the Free Software Foundation; either version 3, or (at your option) |
| 12 | +;; any later version. |
| 13 | + |
| 14 | +;; This file is distributed in the hope that it will be useful, |
| 15 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +;; GNU General Public License for more details. |
| 18 | + |
| 19 | +;; You should have received a copy of the GNU General Public License |
| 20 | +;; along with GNU Emacs; see the file COPYING. If not, write to |
| 21 | +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 22 | +;; Boston, MA 02110-1301, USA. |
| 23 | + |
| 24 | +;;; Commentary: |
| 25 | + |
| 26 | +;; This package provides regression tests for haskell-utils package. |
| 27 | + |
| 28 | +;;; Code: |
| 29 | + |
1 | 30 | (require 'ert)
|
2 | 31 | (require 'haskell-utils)
|
3 | 32 |
|
4 | 33 | (defun insert-lines (&rest lines)
|
| 34 | + "Insert all LINES in current buffer." |
5 | 35 | (dolist (line lines)
|
6 | 36 | (insert (concat line "\n"))))
|
7 | 37 |
|
8 | 38 | (ert-deftest simple-import-parse ()
|
9 | 39 | (should (equal "A.B.C"
|
10 |
| - (with-temp-buffer |
11 |
| - (insert-lines "import A.B.C") |
12 |
| - (goto-char (point-min)) |
13 |
| - (forward-line 0) |
14 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 40 | + (with-temp-buffer |
| 41 | + (insert-lines "import A.B.C") |
| 42 | + (goto-char (point-min)) |
| 43 | + (forward-line 0) |
| 44 | + (haskell-utils-parse-import-statement-at-point))))) |
15 | 45 |
|
16 | 46 | (ert-deftest qualified-import-parse ()
|
17 | 47 | (should (equal "A.B.C"
|
18 |
| - (with-temp-buffer |
19 |
| - (insert-lines "import qualified A.B.C") |
20 |
| - (goto-char (point-min)) |
21 |
| - (forward-line 0) |
22 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 48 | + (with-temp-buffer |
| 49 | + (insert-lines "import qualified A.B.C") |
| 50 | + (goto-char (point-min)) |
| 51 | + (forward-line 0) |
| 52 | + (haskell-utils-parse-import-statement-at-point))))) |
23 | 53 |
|
24 | 54 | (ert-deftest qualified-as-import-parse ()
|
25 | 55 | (should (equal "AAA.Bc.Cx"
|
26 |
| - (with-temp-buffer |
27 |
| - (insert-lines "import qualified AAA.Bc.Cx as Something") |
28 |
| - (goto-char (point-min)) |
29 |
| - (forward-line 0) |
30 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 56 | + (with-temp-buffer |
| 57 | + (insert-lines "import qualified AAA.Bc.Cx as Something") |
| 58 | + (goto-char (point-min)) |
| 59 | + (forward-line 0) |
| 60 | + (haskell-utils-parse-import-statement-at-point))))) |
31 | 61 |
|
32 | 62 | (ert-deftest international-characters-import-parse ()
|
33 | 63 | (should (equal "Żółć"
|
34 |
| - (with-temp-buffer |
35 |
| - (insert-lines "import Żółć") |
36 |
| - (goto-char (point-min)) |
37 |
| - (forward-line 0) |
38 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 64 | + (with-temp-buffer |
| 65 | + (insert-lines "import Żółć") |
| 66 | + (goto-char (point-min)) |
| 67 | + (forward-line 0) |
| 68 | + (haskell-utils-parse-import-statement-at-point))))) |
39 | 69 |
|
40 | 70 | (ert-deftest commented-out-import-parse ()
|
41 | 71 | (should (equal nil
|
42 |
| - (with-temp-buffer |
43 |
| - (insert-lines "-- import Nothing") |
44 |
| - (goto-char (point-min)) |
45 |
| - (forward-line 0) |
46 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 72 | + (with-temp-buffer |
| 73 | + (insert-lines "-- import Nothing") |
| 74 | + (goto-char (point-min)) |
| 75 | + (forward-line 0) |
| 76 | + (haskell-utils-parse-import-statement-at-point))))) |
47 | 77 |
|
48 | 78 | (ert-deftest non-import-import-parse ()
|
49 | 79 | (should (equal nil
|
50 |
| - (with-temp-buffer |
51 |
| - (insert-lines "something import Nothing") |
52 |
| - (goto-char (point-min)) |
53 |
| - (forward-line 0) |
54 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 80 | + (with-temp-buffer |
| 81 | + (insert-lines "something import Nothing") |
| 82 | + (goto-char (point-min)) |
| 83 | + (forward-line 0) |
| 84 | + (haskell-utils-parse-import-statement-at-point))))) |
55 | 85 |
|
56 | 86 | (ert-deftest many-spaces-import-parse ()
|
57 | 87 | (should (equal "M"
|
58 |
| - (with-temp-buffer |
59 |
| - (insert-lines "\t import\t qualified \t\tM\tas G") |
60 |
| - (goto-char (point-min)) |
61 |
| - (forward-line 0) |
62 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 88 | + (with-temp-buffer |
| 89 | + (insert-lines "\t import\t qualified \t\tM\tas G") |
| 90 | + (goto-char (point-min)) |
| 91 | + (forward-line 0) |
| 92 | + (haskell-utils-parse-import-statement-at-point))))) |
63 | 93 |
|
64 | 94 | (ert-deftest using-underscores-import-parse ()
|
65 | 95 | (should (equal "Module_1.S_3_3_"
|
66 |
| - (with-temp-buffer |
67 |
| - (insert-lines "import Module_1.S_3_3_") |
68 |
| - (goto-char (point-min)) |
69 |
| - (forward-line 0) |
70 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 96 | + (with-temp-buffer |
| 97 | + (insert-lines "import Module_1.S_3_3_") |
| 98 | + (goto-char (point-min)) |
| 99 | + (forward-line 0) |
| 100 | + (haskell-utils-parse-import-statement-at-point))))) |
71 | 101 |
|
72 | 102 | (ert-deftest slightly-malformed-import-parse ()
|
73 | 103 | (should (equal "q.Module...qwerqwe..."
|
74 |
| - (with-temp-buffer |
75 |
| - (insert-lines "import q.Module...qwerqwe...") |
76 |
| - (goto-char (point-min)) |
77 |
| - (forward-line 0) |
78 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 104 | + (with-temp-buffer |
| 105 | + (insert-lines "import q.Module...qwerqwe...") |
| 106 | + (goto-char (point-min)) |
| 107 | + (forward-line 0) |
| 108 | + (haskell-utils-parse-import-statement-at-point))))) |
79 | 109 |
|
80 | 110 | (ert-deftest package-import-parse ()
|
81 | 111 | (should (equal "B"
|
82 |
| - (with-temp-buffer |
83 |
| - (insert-lines "import \"package-1.2.3\" B") |
84 |
| - (goto-char (point-min)) |
85 |
| - (forward-line 0) |
86 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 112 | + (with-temp-buffer |
| 113 | + (insert-lines "import \"package-1.2.3\" B") |
| 114 | + (goto-char (point-min)) |
| 115 | + (forward-line 0) |
| 116 | + (haskell-utils-parse-import-statement-at-point))))) |
87 | 117 |
|
88 | 118 | (ert-deftest safe-haskell-import-parse ()
|
89 | 119 | (should (equal "B"
|
90 |
| - (with-temp-buffer |
91 |
| - (insert-lines "import safe B") |
92 |
| - (goto-char (point-min)) |
93 |
| - (forward-line 0) |
94 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 120 | + (with-temp-buffer |
| 121 | + (insert-lines "import safe B") |
| 122 | + (goto-char (point-min)) |
| 123 | + (forward-line 0) |
| 124 | + (haskell-utils-parse-import-statement-at-point))))) |
95 | 125 |
|
96 | 126 | (ert-deftest full-import-parse ()
|
97 | 127 | (should (equal "Data.Char.Unicode_v_7"
|
98 |
| - (with-temp-buffer |
99 |
| - (insert-lines "import safe qualified \"unicode-7.0\" Data.Char.Unicode_v_7 as U (func)") |
100 |
| - (goto-char (point-min)) |
101 |
| - (forward-line 0) |
102 |
| - (haskell-utils-parse-import-statement-at-point))))) |
| 128 | + (with-temp-buffer |
| 129 | + (insert-lines "import safe qualified \"unicode-7.0\" Data.Char.Unicode_v_7 as U (func)") |
| 130 | + (goto-char (point-min)) |
| 131 | + (forward-line 0) |
| 132 | + (haskell-utils-parse-import-statement-at-point))))) |
| 133 | + |
| 134 | +(ert-deftest type-at-command-composition () |
| 135 | + "Test haskell-utils-compose-type-at-command. |
| 136 | +Test only position conversion to line and column numbers, do not |
| 137 | +test last string compontent, it is used in `:type-at` command to |
| 138 | +provide user friendly output only and could be any string, even |
| 139 | +empty one. Very likely the way how its composed for multilne |
| 140 | +strings will change in future." |
| 141 | + (with-temp-buffer |
| 142 | + (insert-lines "module A where" |
| 143 | + "" |
| 144 | + "int :: Int" |
| 145 | + "int = 369" |
| 146 | + "" |
| 147 | + "act =" |
| 148 | + " do print int" |
| 149 | + " return int") |
| 150 | + (goto-char (point-min)) |
| 151 | + (let (test-a-points |
| 152 | + test-b-points |
| 153 | + test-a-result |
| 154 | + test-b-result) |
| 155 | + ;; go to third line, e.g. `int` definition |
| 156 | + (forward-line 3) |
| 157 | + (setq test-a-points (point)) |
| 158 | + ;; go to at the end of `int` definition, i.e. point stands at whitespace |
| 159 | + (forward-char 3) |
| 160 | + (setq test-a-points `(,test-a-points . ,(point))) |
| 161 | + (goto-char (line-beginning-position)) |
| 162 | + ;; go to do-block line |
| 163 | + (forward-line 3) |
| 164 | + ;; go to `do` keyword beginning |
| 165 | + (forward-char 2) |
| 166 | + (setq test-b-points (point)) |
| 167 | + ;; go to the end of do-block |
| 168 | + (goto-char (point-max)) |
| 169 | + ;; note `insert-line' inserts one extra newline, go up one line |
| 170 | + (forward-line -1) |
| 171 | + (goto-char (line-end-position)) |
| 172 | + (setq test-b-points `(,test-b-points . ,(point))) |
| 173 | + (setq test-a-result |
| 174 | + (haskell-utils-compose-type-at-command test-a-points)) |
| 175 | + (setq test-b-result |
| 176 | + (haskell-utils-compose-type-at-command test-b-points)) |
| 177 | + (should (string-prefix-p ":type-at nil 4 1 4 4" test-a-result)) |
| 178 | + (should (string-prefix-p ":type-at nil 7 3 8 16" test-b-result))))) |
| 179 | +;;; haskell-utils-tests.el ends here |
0 commit comments