From 3d3865a4e605ca9a1ceacdcdab6c19df17de0079 Mon Sep 17 00:00:00 2001 From: Moritz Drexl Date: Tue, 13 Dec 2016 22:48:20 +0100 Subject: keep `safe` and `{-# SOURCE #-}` import annotations --- lib/Language/Haskell/Stylish/Step/Imports.hs | 10 ++++++++++ tests/Language/Haskell/Stylish/Step/Imports/Tests.hs | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/Language/Haskell/Stylish/Step/Imports.hs b/lib/Language/Haskell/Stylish/Step/Imports.hs index 334fa15..08918ae 100644 --- a/lib/Language/Haskell/Stylish/Step/Imports.hs +++ b/lib/Language/Haskell/Stylish/Step/Imports.hs @@ -235,6 +235,8 @@ prettyImport columns Options{..} padQualified padName longest imp base' baseName importAs hasHiding' = unwords $ concat $ filter (not . null) [ ["import"] + , source + , safe , qualified , show <$> maybeToList (H.importPkg imp) , [baseName] @@ -262,6 +264,14 @@ prettyImport columns Options{..} padQualified padName longest imp | padQualified = [" "] | otherwise = [] + safe + | H.importSafe imp = ["safe"] + | otherwise = [] + + source + | H.importSrc imp = ["{-# SOURCE #-}"] + | otherwise = [] + mapSpecs f = case importSpecs of Nothing -> [] -- Import everything Just [] -> ["()"] -- Instance only imports diff --git a/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs b/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs index 5ca60de..86a4141 100644 --- a/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs +++ b/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs @@ -46,6 +46,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Imports.Tests" , testCase "case 19b" case19b , testCase "case 19d" case19c , testCase "case 19d" case19d + , testCase "case 20" case20 ] @@ -512,3 +513,19 @@ case19input = unlines , "" , "import Data.List (foldl', intercalate, intersperse)" ] + +-------------------------------------------------------------------------------- +case20 :: Assertion +case20 = expected + @=? testStep (step 80 defaultOptions) input' + where + expected = unlines + [ "import qualified Data.Map as Map" + , "import Data.Set (empty)" + , "import {-# SOURCE #-} qualified Data.Text as T" + ] + input' = unlines + [ "import {-# SOURCE #-} qualified Data.Text as T" + , "import qualified Data.Map as Map" + , "import Data.Set (empty)" + ] -- cgit v1.2.3