Skip to content

Commit

Permalink
Test cases for haskell-sort-imports (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdone committed May 19, 2014
1 parent fbdc679 commit cc161d7
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions tests/haskell-sort-imports-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
;;; haskell-sort-imports-tests.el --- Unit tests for haskell-sort-imports

;; Copyright (c) 2014 Chris Done. All rights reserved.

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)
(require 'haskell-sort-imports)

(ert-deftest empty-buffer ()
(should (with-temp-buffer
(haskell-sort-imports)
t)))

(ert-deftest single-line ()
(should (with-temp-buffer
(insert "import A\n")
(goto-line 1)
(haskell-sort-imports)
(string= (buffer-string)
"import A\n"))))

(ert-deftest two-idem ()
(should (with-temp-buffer
(insert "import A
import B
")
(goto-line 1)
(haskell-sort-imports)
(string= (buffer-string)
"import A
import B
")))
(should (with-temp-buffer
(insert "import qualified A
import B
")
(goto-line 1)
(haskell-sort-imports)
(string= (buffer-string)
"import qualified A
import B
")))
(should (with-temp-buffer
(insert "import qualified \"mtl\" A
import B
")
(goto-line 1)
(haskell-sort-imports)
(string= (buffer-string)
"import qualified \"mtl\" A
import B
"))))

(ert-deftest two-rev ()
(should (with-temp-buffer
(insert "import B
import A
")
(goto-line 1)
(haskell-sort-imports)
(string= (buffer-string)
"import A
import B
"))))

(ert-deftest file-structure ()
(should (with-temp-buffer
(insert "module A where
import B
import A
")
(goto-line 2)
(haskell-sort-imports)
(string= (buffer-string)
"module A where
import A
import B
")))
(should (with-temp-buffer
(insert "module C where
import B
import A
")
(goto-line 3)
(haskell-sort-imports)
(string= (buffer-string)
"module C where
import A
import B
"))))

(ert-deftest bos-270 ()
(should (with-temp-buffer
(insert "import Data.Aeson.Encode (encode)
import Data.Aeson.Types
import Data.Aeson.Parser.Internal (decodeWith, decodeStrictWith,
eitherDecodeWith, eitherDecodeStrictWith,
jsonEOF, json, jsonEOF', json')
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
")
(goto-line 1)
(haskell-sort-imports)
(string= (buffer-string)
"import Data.Aeson.Encode (encode)
import Data.Aeson.Parser.Internal (decodeWith, decodeStrictWith,
eitherDecodeWith, eitherDecodeStrictWith,
jsonEOF, json, jsonEOF', json')
import Data.Aeson.Types
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
"))))

(provide 'haskell-sort-imports-tests)

0 comments on commit cc161d7

Please sign in to comment.