diff options
-rw-r--r-- | .ghci | 2 | ||||
-rw-r--r-- | .travis.yml | 3 | ||||
-rw-r--r-- | README.markdown | 2 | ||||
-rw-r--r-- | src/StylishHaskellImports.hs | 2 | ||||
-rw-r--r-- | stylish-haskell-imports.cabal | 20 | ||||
-rw-r--r-- | tests/StylishHaskellImports/Tests.hs | 49 | ||||
-rw-r--r-- | tests/TestSuite.hs | 18 |
7 files changed, 92 insertions, 4 deletions
@@ -1 +1 @@ -:set -isrc +:set -isrc -itests diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..dc3a21d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: haskell +before_script: + - "cabal install HUnit test-framework test-framework-hunit" diff --git a/README.markdown b/README.markdown index 10d47ee..3760392 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,4 @@ stylish-haskell-imports ======================= -TODO +Align and sort imports in Haskell source code diff --git a/src/StylishHaskellImports.hs b/src/StylishHaskellImports.hs index 2022e8a..a18c577 100644 --- a/src/StylishHaskellImports.hs +++ b/src/StylishHaskellImports.hs @@ -45,7 +45,7 @@ stylishImports longest is = map stylishImport $ sort is pad str = str ++ replicate (longest - length str) ' ' stylishImport (Import n q "") = unwords - ["import", stylishQualified q, pad n] + ["import", stylishQualified q, n] stylishImport (Import n q e) = unwords ["import", stylishQualified q, pad n, e] diff --git a/stylish-haskell-imports.cabal b/stylish-haskell-imports.cabal index 4ec74fb..59cce83 100644 --- a/stylish-haskell-imports.cabal +++ b/stylish-haskell-imports.cabal @@ -16,9 +16,27 @@ Executable stylish-haskell-imports Ghc-options: -Wall -O2 Hs-source-dirs: src Main-is: Main.hs - Other-modules: StylishHaskellImports + + Other-modules: + StylishHaskellImports + + Build-depends: + base >= 4 && < 5 + +Test-suite stylish-haskell-imports-tests + Ghc-options: -Wall + Hs-source-dirs: src tests + Main-is: TestSuite.hs + Type: exitcode-stdio-1.0 + + Other-modules: + StylishHaskellImports.Tests Build-depends: + HUnit >= 1.2 && < 1.3, + test-framework >= 0.4 && < 0.7, + test-framework-hunit >= 0.2 && < 0.3, + -- Copied from regular dependencies... base >= 4 && < 5 Source-repository head diff --git a/tests/StylishHaskellImports/Tests.hs b/tests/StylishHaskellImports/Tests.hs new file mode 100644 index 0000000..15ca30e --- /dev/null +++ b/tests/StylishHaskellImports/Tests.hs @@ -0,0 +1,49 @@ +module StylishHaskellImports.Tests + ( tests + ) where + + +-------------------------------------------------------------------------------- +import Test.Framework (Test, testGroup) +import Test.Framework.Providers.HUnit (testCase) +import Test.HUnit ((@=?)) + + +-------------------------------------------------------------------------------- +import StylishHaskellImports + + +-------------------------------------------------------------------------------- +tests :: Test +tests = testGroup "StylishHaskellImports.Tests" + [ case01 + ] + + +-------------------------------------------------------------------------------- +case01 :: Test +case01 = testCase "case 01" $ expected @=? stylishHaskellImports input + where + input = unlines + [ "module Herp where" + , "" + , "import qualified Data.Map as M" + , "import Control.Monad" + , "import Data.Map (Map)" + , "" + , "import Herp.Derp.Internals" + , "" + , "herp = putStrLn \"import Hello world\"" + ] + + expected = unlines + [ "module Herp where" + , "" + , "import Control.Monad" + , "import Data.Map (Map)" + , "import qualified Data.Map as M" + , "" + , "import Herp.Derp.Internals" + , "" + , "herp = putStrLn \"import Hello world\"" + ] diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs new file mode 100644 index 0000000..36a9402 --- /dev/null +++ b/tests/TestSuite.hs @@ -0,0 +1,18 @@ +module Main + ( main + ) where + + +-------------------------------------------------------------------------------- +import Test.Framework (defaultMain) + + +-------------------------------------------------------------------------------- +import qualified StylishHaskellImports.Tests + + +-------------------------------------------------------------------------------- +main :: IO () +main = defaultMain + [ StylishHaskellImports.Tests.tests + ] |