diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-06-01 15:18:46 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-06-01 15:19:02 +0200 |
commit | f6c14d5af8e6eec541f0d2db95d0b58ed9162bc6 (patch) | |
tree | ef6173629638624a26750adaea7e852c5864aedd | |
parent | f53dcf0f60df80b5f5fa7071d1b5d6464055b503 (diff) | |
download | stylish-haskell-f6c14d5af8e6eec541f0d2db95d0b58ed9162bc6.tar.gz |
Remove BangPatterns if possible
See #4
-rw-r--r-- | src/StylishHaskell/Stylish/LanguagePragmas.hs | 8 | ||||
-rw-r--r-- | tests/StylishHaskell/Stylish/LanguagePragmas/Tests.hs | 11 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/StylishHaskell/Stylish/LanguagePragmas.hs b/src/StylishHaskell/Stylish/LanguagePragmas.hs index 60e3187..017c64d 100644 --- a/src/StylishHaskell/Stylish/LanguagePragmas.hs +++ b/src/StylishHaskell/Stylish/LanguagePragmas.hs @@ -77,6 +77,7 @@ addLanguagePragma pragma modu -- but we do a best effort. isRedundant :: H.Module H.SrcSpanInfo -> String -> Bool isRedundant m "ViewPatterns" = isRedundantViewPatterns m +isRedundant m "BangPatterns" = isRedundantBangPatterns m isRedundant _ _ = False @@ -85,3 +86,10 @@ isRedundant _ _ = False isRedundantViewPatterns :: H.Module H.SrcSpanInfo -> Bool isRedundantViewPatterns m = null [() | H.PViewPat _ _ _ <- everything m :: [H.Pat H.SrcSpanInfo]] + + +-------------------------------------------------------------------------------- +-- | Check if the BangPatterns language pragma is redundant. +isRedundantBangPatterns :: H.Module H.SrcSpanInfo -> Bool +isRedundantBangPatterns m = null + [() | H.PBangPat _ _ <- everything m :: [H.Pat H.SrcSpanInfo]] diff --git a/tests/StylishHaskell/Stylish/LanguagePragmas/Tests.hs b/tests/StylishHaskell/Stylish/LanguagePragmas/Tests.hs index c802f62..74181ee 100644 --- a/tests/StylishHaskell/Stylish/LanguagePragmas/Tests.hs +++ b/tests/StylishHaskell/Stylish/LanguagePragmas/Tests.hs @@ -48,7 +48,8 @@ case02 :: Test case02 = testCase "case 02" $ expected @=? testStylish (stylish True) input where input = unlines - [ "{-# LANGUAGE ViewPatterns #-}" + [ "{-# LANGUAGE BangPatterns #-}" + , "{-# LANGUAGE ViewPatterns #-}" , "increment ((+ 1) -> x) = x" ] @@ -63,10 +64,12 @@ case03 :: Test case03 = testCase "case 03" $ expected @=? testStylish (stylish True) input where input = unlines - [ "{-# LANGUAGE ViewPatterns #-}" - , "increment x = x + 1" + [ "{-# LANGUAGE BangPatterns #-}" + , "{-# LANGUAGE ViewPatterns #-}" + , "increment x = case x of !_ -> x + 1" ] expected = unlines - [ "increment x = x + 1" + [ "{-# LANGUAGE BangPatterns #-}" + , "increment x = case x of !_ -> x + 1" ] |