diff --git a/purescript-sort-imports.el b/purescript-sort-imports.el index c635ada..796eee8 100644 --- a/purescript-sort-imports.el +++ b/purescript-sort-imports.el @@ -32,11 +32,9 @@ (defvar purescript-sort-imports-regexp (concat "^import[ ]+" - "\\(qualified \\)?" - "[ ]*\\(\"[^\"]*\" \\)?" + "\\(\"[^\"]*\" \\)?" "[ ]*\\([A-Za-z0-9_.']*.*\\)")) -;;;###autoload (defun purescript-sort-imports () "Sort the import list at point. It sorts the current group i.e. an import list separated by blank lines on either side. @@ -68,9 +66,8 @@ within that region." (defun purescript-sort-imports-normalize (i) "Normalize an import, if possible, so that it can be sorted." - (if (string-match purescript-sort-imports-regexp - i) - (match-string 3 i) + (if (string-match purescript-sort-imports-regexp i) + (match-string 2 i) i)) (defun purescript-sort-imports-collect-imports () diff --git a/tests/purescript-sort-imports-tests.el b/tests/purescript-sort-imports-tests.el index e24fec1..fd5de6b 100644 --- a/tests/purescript-sort-imports-tests.el +++ b/tests/purescript-sort-imports-tests.el @@ -21,88 +21,88 @@ (require 'purescript-sort-imports) (ert-deftest empty-buffer () - (should (with-temp-buffer - (purescript-sort-imports) - t))) + (with-temp-buffer + (purescript-sort-imports) + t)) (ert-deftest single-line () - (should (with-temp-buffer - (insert "import A\n") - (goto-char (point-min)) - (purescript-sort-imports) - (string= (buffer-string) + (with-temp-buffer + (insert "import A\n") + (goto-char (point-min)) + (purescript-sort-imports) + (should (string= (buffer-string) "import A\n")))) (ert-deftest two-idem () - (should (with-temp-buffer - (insert "import A + (with-temp-buffer + (insert "import A import B ") - (goto-char (point-min)) - (purescript-sort-imports) - (string= (buffer-string) + (goto-char (point-min)) + (purescript-sort-imports) + (should (string= (buffer-string) "import A import B "))) - (should (with-temp-buffer - (insert "import qualified A + (with-temp-buffer + (insert "import A (A, B, C) import B ") - (goto-char (point-min)) - (purescript-sort-imports) - (string= (buffer-string) - "import qualified A + (goto-char (point-min)) + (purescript-sort-imports) + (should (string= (buffer-string) + "import A (A, B, C) import B "))) - (should (with-temp-buffer - (insert "import qualified \"mtl\" A + (with-temp-buffer + (insert "import A (mtl) import B ") - (goto-char (point-min)) - (purescript-sort-imports) - (string= (buffer-string) - "import qualified \"mtl\" A + (goto-char (point-min)) + (purescript-sort-imports) + (should (string= (buffer-string) + "import A (mtl) import B ")))) (ert-deftest two-rev () - (should (with-temp-buffer - (insert "import B + (with-temp-buffer + (insert "import B import A ") - (goto-char (point-min)) - (purescript-sort-imports) - (string= (buffer-string) + (goto-char (point-min)) + (purescript-sort-imports) + (should (string= (buffer-string) "import A import B ")))) (ert-deftest file-structure () - (should (with-temp-buffer - (insert "module A where + (with-temp-buffer + (insert "module A where import B import A ") - ;; test at line 2 - (goto-char (point-min)) - (forward-line 1) - (purescript-sort-imports) - (string= (buffer-string) + ;; test at line 2 + (goto-char (point-min)) + (forward-line 1) + (purescript-sort-imports) + (should (string= (buffer-string) "module A where import A import B "))) - (should (with-temp-buffer - (insert "module C where + (with-temp-buffer + (insert "module C where import B import A ") - ;; test at line 3 - (goto-char (point-min)) - (forward-line 2) - (purescript-sort-imports) - (string= (buffer-string) + ;; test at line 3 + (goto-char (point-min)) + (forward-line 2) + (purescript-sort-imports) + (should (string= (buffer-string) "module C where import A @@ -110,25 +110,25 @@ import B ")))) (ert-deftest bos-270 () - (should (with-temp-buffer - (insert "import Data.Aeson.Encode (encode) + (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 +import Data.ByteString as B +import Data.ByteString.Lazy as L ") - (goto-char (point-min)) - (purescript-sort-imports) - (string= (buffer-string) + (goto-char (point-min)) + (purescript-sort-imports) + (should (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 +import Data.ByteString as B +import Data.ByteString.Lazy as L ")))) (provide 'purescript-sort-imports-tests)