summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorŁukasz Gołębiewski <lukasz.golebiewski@gmail.com>2020-01-23 17:43:04 +0100
committerGitHub <noreply@github.com>2020-01-23 17:43:04 +0100
commit8065c3c074719bd13db67b5ec74db560609a4e64 (patch)
treeb4cd6715cd196eecabe488caaab6b9a24ab637a1 /tests
parent1a869950eba47e30ebe84e118f404ef9a62e9cc6 (diff)
downloadstylish-haskell-8065c3c074719bd13db67b5ec74db560609a4e64.tar.gz
Support for records formatting (#256)
* Initial test describing simplest scenario for Data step Co-authored-by: Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> * [sanity-check] Delete data defs * Extract changeDecl Co-authored-by: Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> * First green test :-) * Cover case where there are more then one field in data type declaration Co-authored-by: Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> * Add case03 where a type variable is present * Add case04 - multiple declarations * Make case04 pass * Extend tests with case05 Co-authored-by: Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> * Add pending case06 Co-authored-by: Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> * Fix case 06 Co-authored-by: Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> * Add case07 Co-authored-by: Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> * Add second phantom case * Add records to config * Make indent size configurable for records Co-authored-by: Paweł Szulc <paul.szulc@gmail.com> * Fix warnings in Data.hs * Process derivings during record formatting Co-authored-by: Paweł Szulc <paul.szulc@gmail.com> * Do not format when context is present Co-authored-by: Paweł Szulc <paul.szulc@gmail.com> * Add case 11 - deriving with DerivingStrategies * Bugfix: do not remove empty data declarations Co-authored-by: Paweł Szulc <paul.szulc@gmail.com> * Update README example with ability to format records * Add case12 (Point) * Fix case 12 * Factor out processName * Apply hlint suggestions * Extract constructors helper function * Make 'indent' global * Remove unused Stylish.records method * Fix Config formatting in Config.hs * Extract processConstructor function Co-authored-by: Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> * Refactor datas function Co-authored-by: Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> * Include comments with AST. Two tests are still failing... * Fix cases 15 and 16 * Do not format records when comments within Co-authored-by: Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> * Clean-up Data.hs * Refactor Data.hs Co-authored-by: Pawel Szulc <paul.szulc@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Language/Haskell/Stylish/Config/Tests.hs2
-rw-r--r--tests/Language/Haskell/Stylish/Step/Data/Tests.hs368
-rw-r--r--tests/TestSuite.hs2
3 files changed, 372 insertions, 0 deletions
diff --git a/tests/Language/Haskell/Stylish/Config/Tests.hs b/tests/Language/Haskell/Stylish/Config/Tests.hs
index ebaef54..f8869ce 100644
--- a/tests/Language/Haskell/Stylish/Config/Tests.hs
+++ b/tests/Language/Haskell/Stylish/Config/Tests.hs
@@ -165,6 +165,8 @@ dotStylish = unlines $
, " align: false"
, " remove_redundant: true"
, " - trailing_whitespace: {}"
+ , " - records: {}"
+ , "indent: 2"
, "columns: 110"
, "language_extensions:"
, " - TemplateHaskell"
diff --git a/tests/Language/Haskell/Stylish/Step/Data/Tests.hs b/tests/Language/Haskell/Stylish/Step/Data/Tests.hs
new file mode 100644
index 0000000..b152819
--- /dev/null
+++ b/tests/Language/Haskell/Stylish/Step/Data/Tests.hs
@@ -0,0 +1,368 @@
+module Language.Haskell.Stylish.Step.Data.Tests
+ ( tests
+ ) where
+
+import Language.Haskell.Stylish.Step.Data
+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.Step.Data.Tests"
+ [ testCase "case 00" case00
+ , testCase "case 01" case01
+ , testCase "case 02" case02
+ , testCase "case 03" case03
+ , testCase "case 04" case04
+ , testCase "case 05" case05
+ , testCase "case 06" case06
+ , testCase "case 07" case07
+ , testCase "case 08" case08
+ , testCase "case 09" case09
+ , testCase "case 10" case10
+ , testCase "case 11" case11
+ , testCase "case 12" case12
+ , testCase "case 13" case13
+ , testCase "case 14" case14
+ , testCase "case 15" case15
+ , testCase "case 16" case16
+ , testCase "case 17" case17
+ , testCase "case 18" case18
+ ]
+
+case00 :: Assertion
+case00 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo"
+ ]
+
+ expected = input
+
+case01 :: Assertion
+case01 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo { a :: Int }"
+ ]
+
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo"
+ , " { a :: Int"
+ , " }"
+ ]
+
+case02 :: Assertion
+case02 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo { a :: Int, a2 :: String }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo"
+ , " { a :: Int"
+ , " , a2 :: String"
+ , " }"
+ ]
+
+case03 :: Assertion
+case03 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a = Foo { a :: a, a2 :: String }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a = Foo"
+ , " { a :: a"
+ , " , a2 :: String"
+ , " }"
+ ]
+
+case04 :: Assertion
+case04 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a = Foo { a :: a, a2 :: String } | Bar { b :: a }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a = Foo"
+ , " { a :: a"
+ , " , a2 :: String"
+ , " }"
+ , " | Bar"
+ , " { b :: a"
+ , " }"
+ ]
+
+case05 :: Assertion
+case05 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo {"
+ , " a :: Int"
+ , " , a2 :: String"
+ , " }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo"
+ , " { a :: Int"
+ , " , a2 :: String"
+ , " }"
+ ]
+
+case06 :: Assertion
+case06 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo Int String"
+ ]
+ expected = input
+
+case07 :: Assertion
+case07 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Phantom a = Phantom"
+ ]
+ expected = input
+
+case08 :: Assertion
+case08 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Phantom a ="
+ , " Phantom"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Phantom a = Phantom"
+ ]
+
+case09 :: Assertion
+case09 = expected @=? testStep (step 4) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a b = Foo { a :: a, a2 :: String } | Bar { b :: a, c:: b }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a b = Foo"
+ , " { a :: a"
+ , " , a2 :: String"
+ , " }"
+ , " | Bar"
+ , " { b :: a"
+ , " , c :: b"
+ , " }"
+ ]
+
+case10 :: Assertion
+case10 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo { a :: Int } deriving (Eq, Generic) deriving (Show)"
+ ]
+
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo"
+ , " { a :: Int"
+ , " }"
+ , " deriving (Eq, Generic)"
+ , " deriving (Show)"
+ ]
+
+case11 :: Assertion
+case11 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "{-# LANGUAGE DerivingStrategies #-}"
+ , "module Herp where"
+ , ""
+ , "data Foo = Foo { a :: Int } deriving stock (Show)"
+ ]
+
+ expected = unlines
+ [ "{-# LANGUAGE DerivingStrategies #-}"
+ , "module Herp where"
+ , ""
+ , "data Foo = Foo"
+ , " { a :: Int"
+ , " }"
+ , " deriving stock (Show)"
+ ]
+
+case12 :: Assertion
+case12 = expected @=? testStep (step 4) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Point = Point { pointX, pointY :: Double , pointName :: String} deriving (Show)"
+ ]
+
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Point = Point"
+ , " { pointX, pointY :: Double"
+ , " , pointName :: String"
+ , " }"
+ , " deriving (Show)"
+ ]
+
+case13 :: Assertion
+case13 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "-- this is a comment"
+ , "data Foo = Foo { a :: Int }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "-- this is a comment"
+ , "data Foo = Foo"
+ , " { a :: Int"
+ , " }"
+ ]
+
+case14 :: Assertion
+case14 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "{- this is"
+ , " a comment -}"
+ , "data Foo = Foo { a :: Int }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "{- this is"
+ , " a comment -}"
+ , "data Foo = Foo"
+ , " { a :: Int"
+ , " }"
+ ]
+
+case15 :: Assertion
+case15 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo {"
+ , " a :: Int -- ^ comment"
+ , " }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo = Foo {"
+ , " a :: Int -- ^ comment"
+ , " }"
+ ]
+
+case16 :: Assertion
+case16 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a = Foo"
+ , " { a :: a,"
+ , "-- ^ comment"
+ , " a2 :: String"
+ , " }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a = Foo"
+ , " { a :: a,"
+ , "-- ^ comment"
+ , " a2 :: String"
+ , " }"
+ ]
+
+case17 :: Assertion
+case17 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a = Foo"
+ , " { a :: a, -- comment"
+ , " a2 :: String"
+ , " }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a = Foo"
+ , " { a :: a, -- comment"
+ , " a2 :: String"
+ , " }"
+ ]
+
+case18 :: Assertion
+case18 = expected @=? testStep (step 2) input
+ where
+ input = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a = Foo"
+ , " { a :: a,"
+ , "-- comment "
+ , " a2 :: String"
+ , " }"
+ ]
+ expected = unlines
+ [ "module Herp where"
+ , ""
+ , "data Foo a = Foo"
+ , " { a :: a,"
+ , "-- comment "
+ , " a2 :: String"
+ , " }"
+ ]
diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs
index b5bec90..a6f51ea 100644
--- a/tests/TestSuite.hs
+++ b/tests/TestSuite.hs
@@ -11,6 +11,7 @@ import Test.Framework (default
--------------------------------------------------------------------------------
import qualified Language.Haskell.Stylish.Config.Tests
import qualified Language.Haskell.Stylish.Parse.Tests
+import qualified Language.Haskell.Stylish.Step.Data.Tests
import qualified Language.Haskell.Stylish.Step.Imports.Tests
import qualified Language.Haskell.Stylish.Step.LanguagePragmas.Tests
import qualified Language.Haskell.Stylish.Step.SimpleAlign.Tests
@@ -25,6 +26,7 @@ main :: IO ()
main = defaultMain
[ Language.Haskell.Stylish.Parse.Tests.tests
, Language.Haskell.Stylish.Config.Tests.tests
+ , Language.Haskell.Stylish.Step.Data.Tests.tests
, Language.Haskell.Stylish.Step.Imports.Tests.tests
, Language.Haskell.Stylish.Step.LanguagePragmas.Tests.tests
, Language.Haskell.Stylish.Step.SimpleAlign.Tests.tests