Skip to content

Commit cc161d7

Browse files
committed
Test cases for haskell-sort-imports (#270)
1 parent fbdc679 commit cc161d7

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

tests/haskell-sort-imports-tests.el

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
;;; haskell-sort-imports-tests.el --- Unit tests for haskell-sort-imports
2+
3+
;; Copyright (c) 2014 Chris Done. All rights reserved.
4+
5+
;; This file is free software; you can redistribute it and/or modify
6+
;; it under the terms of the GNU General Public License as published by
7+
;; the Free Software Foundation; either version 3, or (at your option)
8+
;; any later version.
9+
10+
;; This file is distributed in the hope that it will be useful,
11+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
;; GNU General Public License for more details.
14+
15+
;; You should have received a copy of the GNU General Public License
16+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
;;; Code:
19+
20+
(require 'ert)
21+
(require 'haskell-sort-imports)
22+
23+
(ert-deftest empty-buffer ()
24+
(should (with-temp-buffer
25+
(haskell-sort-imports)
26+
t)))
27+
28+
(ert-deftest single-line ()
29+
(should (with-temp-buffer
30+
(insert "import A\n")
31+
(goto-line 1)
32+
(haskell-sort-imports)
33+
(string= (buffer-string)
34+
"import A\n"))))
35+
36+
(ert-deftest two-idem ()
37+
(should (with-temp-buffer
38+
(insert "import A
39+
import B
40+
")
41+
(goto-line 1)
42+
(haskell-sort-imports)
43+
(string= (buffer-string)
44+
"import A
45+
import B
46+
")))
47+
(should (with-temp-buffer
48+
(insert "import qualified A
49+
import B
50+
")
51+
(goto-line 1)
52+
(haskell-sort-imports)
53+
(string= (buffer-string)
54+
"import qualified A
55+
import B
56+
")))
57+
(should (with-temp-buffer
58+
(insert "import qualified \"mtl\" A
59+
import B
60+
")
61+
(goto-line 1)
62+
(haskell-sort-imports)
63+
(string= (buffer-string)
64+
"import qualified \"mtl\" A
65+
import B
66+
"))))
67+
68+
(ert-deftest two-rev ()
69+
(should (with-temp-buffer
70+
(insert "import B
71+
import A
72+
")
73+
(goto-line 1)
74+
(haskell-sort-imports)
75+
(string= (buffer-string)
76+
"import A
77+
import B
78+
"))))
79+
80+
(ert-deftest file-structure ()
81+
(should (with-temp-buffer
82+
(insert "module A where
83+
import B
84+
import A
85+
")
86+
(goto-line 2)
87+
(haskell-sort-imports)
88+
(string= (buffer-string)
89+
"module A where
90+
import A
91+
import B
92+
")))
93+
(should (with-temp-buffer
94+
(insert "module C where
95+
96+
import B
97+
import A
98+
")
99+
(goto-line 3)
100+
(haskell-sort-imports)
101+
(string= (buffer-string)
102+
"module C where
103+
104+
import A
105+
import B
106+
"))))
107+
108+
(ert-deftest bos-270 ()
109+
(should (with-temp-buffer
110+
(insert "import Data.Aeson.Encode (encode)
111+
import Data.Aeson.Types
112+
import Data.Aeson.Parser.Internal (decodeWith, decodeStrictWith,
113+
eitherDecodeWith, eitherDecodeStrictWith,
114+
jsonEOF, json, jsonEOF', json')
115+
import qualified Data.ByteString as B
116+
import qualified Data.ByteString.Lazy as L
117+
")
118+
(goto-line 1)
119+
(haskell-sort-imports)
120+
(string= (buffer-string)
121+
"import Data.Aeson.Encode (encode)
122+
import Data.Aeson.Parser.Internal (decodeWith, decodeStrictWith,
123+
eitherDecodeWith, eitherDecodeStrictWith,
124+
jsonEOF, json, jsonEOF', json')
125+
import Data.Aeson.Types
126+
import qualified Data.ByteString as B
127+
import qualified Data.ByteString.Lazy as L
128+
"))))
129+
130+
(provide 'haskell-sort-imports-tests)

0 commit comments

Comments
 (0)