From 67204c2ba7dc355395d214396202b7a8267aaabe Mon Sep 17 00:00:00 2001 From: EncodePanda Date: Sat, 24 Apr 2021 00:31:11 +0200 Subject: [PATCH 1/3] Add regression test showing that issue #282 does no longer exist --- .../Haskell/Stylish/Step/Data/Tests.hs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/Language/Haskell/Stylish/Step/Data/Tests.hs b/tests/Language/Haskell/Stylish/Step/Data/Tests.hs index 524e049d..4fa9247c 100644 --- a/tests/Language/Haskell/Stylish/Step/Data/Tests.hs +++ b/tests/Language/Haskell/Stylish/Step/Data/Tests.hs @@ -73,6 +73,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Data.Tests" , testCase "case 58" case58 , testCase "case 59" case59 , testCase "case 60" case60 + , testCase "case 61 (issue 282)" case61 ] case00 :: Assertion @@ -1309,6 +1310,40 @@ case60 = assertSnippet (step defaultConfig) [ "data Foo = forall a . Bar a" ] [ "data Foo = forall a. Bar a" ] +-- | Formatting duplicates haddock comments #282 +-- +-- Regression test for https://github.com/haskell/stylish-haskell/issues/282 +case61 :: Assertion +case61 = expected @=? testStep (step sameIndentStyle) input + where + input = unlines + [ "module Herp where" + , "" + , "data Game = Game { _board :: Board -- ^ Board state" + , " , _time :: Int -- ^ Time elapsed" + , " , _paused :: Bool -- ^ Playing vs. paused" + , " , _speed :: Float -- ^ Speed in [0..1]" + , " , _interval :: TVar Int -- ^ Interval kept in TVar" + , " }" + ] + + expected = unlines + [ "module Herp where" + , "" + , "data Game = Game" + , " { _board :: Board" + , " -- ^ Board state" + , " , _time :: Int" + , " -- ^ Time elapsed" + , " , _paused :: Bool" + , " -- ^ Playing vs. paused" + , " , _speed :: Float" + , " -- ^ Speed in [0..1]" + , " , _interval :: TVar Int" + , " -- ^ Interval kept in TVar" + , " }" + ] + sameSameStyle :: Config sameSameStyle = Config SameLine SameLine 2 2 False True SameLine False True NoMaxColumns From 7fdb769283c885e9690ecc7c003c7798ae9593fa Mon Sep 17 00:00:00 2001 From: EncodePanda Date: Sat, 24 Apr 2021 00:53:40 +0200 Subject: [PATCH 2/3] Add regression tests showing that issue #273 is fixed --- .../Haskell/Stylish/Step/Data/Tests.hs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/Language/Haskell/Stylish/Step/Data/Tests.hs b/tests/Language/Haskell/Stylish/Step/Data/Tests.hs index 4fa9247c..7d959046 100644 --- a/tests/Language/Haskell/Stylish/Step/Data/Tests.hs +++ b/tests/Language/Haskell/Stylish/Step/Data/Tests.hs @@ -74,6 +74,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Data.Tests" , testCase "case 59" case59 , testCase "case 60" case60 , testCase "case 61 (issue 282)" case61 + , testCase "case 62 (issue 273)" case62 ] case00 :: Assertion @@ -1344,6 +1345,38 @@ case61 = expected @=? testStep (step sameIndentStyle) input , " }" ] +-- | Comment issues with record formatting #273 +-- +-- Regression test for https://github.com/haskell/stylish-haskell/issues/273 +case62 :: Assertion +case62 = expected @=? testStep (step sameIndentStyle) input + where + input = unlines + [ "module Herp where" + , "" + , "data Foo = Foo" + , " { -- | This is a comment above some line." + , " -- It can span multiple lines." + , " fooName :: String" + , " , fooAge :: Int" + , " -- ^ This is a comment below some line." + , " -- It can span multiple lines." + , " }" + ] + + expected = unlines + [ "module Herp where" + , "" + , "data Foo = Foo" + , " { -- | This is a comment above some line." + , " -- It can span multiple lines." + , " fooName :: String" + , " , fooAge :: Int" + , " -- ^ This is a comment below some line." + , " -- It can span multiple lines." + , " }" + ] + sameSameStyle :: Config sameSameStyle = Config SameLine SameLine 2 2 False True SameLine False True NoMaxColumns From 1d78fb3e3d76dfa27915abb8ea8c37ba065cb2da Mon Sep 17 00:00:00 2001 From: EncodePanda Date: Sat, 24 Apr 2021 01:10:43 +0200 Subject: [PATCH 3/3] Add regression test for issue #198 --- stylish-haskell.cabal | 1 + tests/Language/Haskell/Stylish/Regressions.hs | 35 +++++++++++++++++++ tests/TestSuite.hs | 2 ++ 3 files changed, 38 insertions(+) create mode 100644 tests/Language/Haskell/Stylish/Regressions.hs diff --git a/stylish-haskell.cabal b/stylish-haskell.cabal index 3dca4a40..f797c10f 100644 --- a/stylish-haskell.cabal +++ b/stylish-haskell.cabal @@ -147,6 +147,7 @@ Test-suite stylish-haskell-tests Language.Haskell.Stylish.Step.TrailingWhitespace.Tests Language.Haskell.Stylish.Step.UnicodeSyntax Language.Haskell.Stylish.Step.UnicodeSyntax.Tests + Language.Haskell.Stylish.Regressions Language.Haskell.Stylish.Tests Language.Haskell.Stylish.Tests.Util Language.Haskell.Stylish.Util diff --git a/tests/Language/Haskell/Stylish/Regressions.hs b/tests/Language/Haskell/Stylish/Regressions.hs new file mode 100644 index 00000000..90d54603 --- /dev/null +++ b/tests/Language/Haskell/Stylish/Regressions.hs @@ -0,0 +1,35 @@ +{-# LANGUAGE OverloadedLists #-} +{-# LANGUAGE OverloadedStrings #-} +module Language.Haskell.Stylish.Regressions + ( tests + ) where + +import Language.Haskell.Stylish.Step.Imports +import Language.Haskell.Stylish.Tests.Util (testStep) +import Test.Framework (Test, testGroup) +import Test.Framework.Providers.HUnit (testCase) +import Test.HUnit (Assertion, (@=?)) + + +tests :: Test +tests = testGroup "Language.Haskell.Stylish.Regressions" + [ testCase "case 00 (#198)" case00 + ] +-- | Error parsing '(,) #198 +-- +-- See https://github.com/haskell/stylish-haskell/issues/198 +case00 :: Assertion +case00 = expected @=? testStep (step (Just 80) $ importStepConfig Global) input + where + input = unlines + [ "{-# LANGUAGE TemplateHaskell #-}" + , "" + , "import Language.Haskell.TH.Syntax" + , "" + , "main = print $ showName '(,)" + ] + + expected = input + +importStepConfig :: ImportAlign -> Options +importStepConfig align = defaultOptions { importAlign = align } diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs index 501821b2..8d4b6956 100644 --- a/tests/TestSuite.hs +++ b/tests/TestSuite.hs @@ -22,6 +22,7 @@ import qualified Language.Haskell.Stylish.Step.Tabs.Tests import qualified Language.Haskell.Stylish.Step.TrailingWhitespace.Tests import qualified Language.Haskell.Stylish.Step.UnicodeSyntax.Tests import qualified Language.Haskell.Stylish.Tests +import qualified Language.Haskell.Stylish.Regressions -------------------------------------------------------------------------------- @@ -40,4 +41,5 @@ main = defaultMain , Language.Haskell.Stylish.Step.TrailingWhitespace.Tests.tests , Language.Haskell.Stylish.Step.UnicodeSyntax.Tests.tests , Language.Haskell.Stylish.Tests.tests + , Language.Haskell.Stylish.Regressions.tests ]