File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
lib/Language/Haskell/Stylish
tests/Language/Haskell/Stylish/Step/Imports Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -201,10 +201,13 @@ moduleImportGroups = go [] Nothing . moduleImports
201201 -> [NonEmpty (Located Import )]
202202 go acc _ [] = ne acc
203203 go acc mbCurrentLine (imp : impRest) =
204- let l2 = getStartLineUnsafe imp in
204+ let
205+ lStart = getStartLineUnsafe imp
206+ lEnd = getEndLineUnsafe imp in
205207 case mbCurrentLine of
206- Just l1 | l1 + 1 < l2 -> ne acc ++ go [imp] (Just l2) impRest
207- _ -> go (acc ++ [imp]) (Just l2) impRest
208+ Just lPrevEnd | lPrevEnd + 1 < lStart
209+ -> ne acc ++ go [imp] (Just lEnd) impRest
210+ _ -> go (acc ++ [imp]) (Just lEnd) impRest
208211
209212 ne [] = []
210213 ne (x : xs) = [x :| xs]
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Imports.Tests"
5959 , testCase " case 26 (issue 185)" case26
6060 , testCase " case 27" case27
6161 , testCase " case 28" case28
62+ , testCase " case 29" case29
6263 ]
6364
6465
@@ -911,3 +912,25 @@ case28 = expected @=? testSnippet (step (Just 80) $ fromImportAlign Global) inpu
911912 , " import Data.Set (empty, intersect)"
912913 , " import Data.Set (empty, nub)"
913914 ]
915+
916+
917+ --------------------------------------------------------------------------------
918+ case29 :: Assertion
919+ case29 = expected @=? testSnippet (step Nothing $ fromImportAlign Group ) input'
920+ where
921+ -- Check that "Group" mode recognizes groups with multi-line imports
922+ input' = Snippet
923+ [ " import Foo (foo)"
924+ , " import BarBar ( bar"
925+ , " , kek)"
926+ , " import Abcd ()"
927+ , " "
928+ , " import A (A)"
929+ ]
930+ expected = Snippet
931+ [ " import Abcd ()"
932+ , " import BarBar (bar, kek)"
933+ , " import Foo (foo)"
934+ , " "
935+ , " import A (A)"
936+ ]
You can’t perform that action at this time.
0 commit comments