1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
;;; haskell-sort-imports-tests.el --- Unit tests for haskell-sort-imports -*- lexical-binding: t -*-
;; 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-char (point-min))
(haskell-sort-imports)
(string= (buffer-string)
"import A\n"))))
(ert-deftest two-idem ()
(should (with-temp-buffer
(insert "import A
import B
")
(goto-char (point-min))
(haskell-sort-imports)
(string= (buffer-string)
"import A
import B
")))
(should (with-temp-buffer
(insert "import qualified A
import B
")
(goto-char (point-min))
(haskell-sort-imports)
(string= (buffer-string)
"import qualified A
import B
")))
(should (with-temp-buffer
(insert "import qualified \"mtl\" A
import B
")
(goto-char (point-min))
(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-char (point-min))
(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-char (point-min))
(forward-line)
(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-char (point-min))
(forward-line 2)
(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-char (point-min))
(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)
|