summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-05 11:05:28 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-05 11:05:28 +0100
commit1354152db499f942f20c6a433a9c26bf3ddb927e (patch)
tree8e18879e66d9e69c4a9eb7fe67c3efdb29e7ffe0
parentf9c412f27e5c839d2ddfddfee4d381e7ea75e057 (diff)
downloadstylish-haskell-1354152db499f942f20c6a433a9c26bf3ddb927e.tar.gz
Micro cleanup
-rw-r--r--src/Language/Haskell/Stylish/Step/Imports.hs12
-rw-r--r--tests/Language/Haskell/Stylish/Step/Imports/Tests.hs27
2 files changed, 27 insertions, 12 deletions
diff --git a/src/Language/Haskell/Stylish/Step/Imports.hs b/src/Language/Haskell/Stylish/Step/Imports.hs
index 476e6ec..6ad95fc 100644
--- a/src/Language/Haskell/Stylish/Step/Imports.hs
+++ b/src/Language/Haskell/Stylish/Step/Imports.hs
@@ -146,8 +146,8 @@ prettyImport columns padQualified padName longest imp =
--------------------------------------------------------------------------------
prettyImportGroup :: Int -> Align -> Bool -> Int -> [H.ImportDecl LineBlock]
- -> Lines
-prettyImportGroup columns align padQual' longest imps =
+ -> Lines
+prettyImportGroup columns align fileAlign longest imps =
concatMap (prettyImport columns padQual padName longest') $
sortBy compareImports imps
where
@@ -159,9 +159,9 @@ prettyImportGroup columns align padQual' longest imps =
padQual = case align of
Global -> True
+ File -> fileAlign
Group -> any H.importQualified imps
None -> False
- File -> padQual'
--------------------------------------------------------------------------------
@@ -172,8 +172,8 @@ step columns = makeStep "Imports" . step' columns
--------------------------------------------------------------------------------
step' :: Int -> Align -> Lines -> Module -> Lines
step' columns align ls (module', _) = flip applyChanges ls
- [ change block (const $ prettyImportGroup columns align padQual
- longest importGroup)
+ [ change block $ const $
+ prettyImportGroup columns align fileAlign longest importGroup
| (block, importGroup) <- groups
]
where
@@ -181,6 +181,6 @@ step' columns align ls (module', _) = flip applyChanges ls
longest = longestImport imps
groups = groupAdjacent imps
- padQual = case align of
+ fileAlign = case align of
File -> any H.importQualified imps
_ -> False
diff --git a/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs b/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
index d3b205a..c62fe0f 100644
--- a/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
+++ b/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
@@ -24,6 +24,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Imports.Tests"
, testCase "case 04" case04
, testCase "case 05" case05
, testCase "case 06" case06
+ , testCase "case 07" case07
]
@@ -123,15 +124,29 @@ case05 = input' @=? testStep (step 80 Group) input'
input' = "import Distribution.PackageDescription.Configuration " ++
"(finalizePackageDescription)\n"
+
--------------------------------------------------------------------------------
case06 :: Assertion
-case06 = expected @=? testStep (step 80 File) input'
+case06 = input' @=? testStep (step 80 File) input'
where
- input' =
- "import Data.Aeson.Types (object, typeMismatch, FromJSON(..)," ++
- "ToJSON(..), Value(..), parseEither, (.!=), (.:), (.:?), (.=))"
+ input' = unlines
+ [ "import Bar.Qux"
+ , "import Foo.Bar"
+ ]
+
+
+--------------------------------------------------------------------------------
+case07 :: Assertion
+case07 = expected @=? testStep (step 80 File) input'
+ where
+ input' = unlines
+ [ "import Bar.Qux"
+ , ""
+ , "import qualified Foo.Bar"
+ ]
expected = unlines
- [ "import Data.Aeson.Types (FromJSON (..), ToJSON (..), Value (..), object,"
- , " parseEither, typeMismatch, (.!=), (.:), (.:?), (.=))"
+ [ "import Bar.Qux"
+ , ""
+ , "import qualified Foo.Bar"
]