-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new step Signature that will format function signatures
The step is a NOP still but additional tests were already created specifing how we anticipate the step to behave. This step is heavily inspired by https://github.com/input-output-hk/ouroboros-network/blob/bf8579cc2ff2a7bc4ba23150eff659cfd1c6ccca/ouroboros-consensus/docs/StyleGuide.md
- Loading branch information
1 parent
03b34d3
commit 2b80feb
Showing
4 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Language.Haskell.Stylish.Step.Signature where | ||
|
||
import Language.Haskell.Stylish.Step | ||
|
||
data Config = Config | ||
{ maxColumnLength :: Int | ||
} | ||
|
||
step :: Config -> Step | ||
step _ = makeStep "Signature" (\ls _ -> ls) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
{-# LANGUAGE OverloadedLists #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Language.Haskell.Stylish.Step.Signature.Tests | ||
( tests | ||
) where | ||
|
||
import Language.Haskell.Stylish.Step.Signature | ||
import Language.Haskell.Stylish.Tests.Util (assertSnippet, testStep) | ||
import Test.Framework (Test, testGroup) | ||
import Test.Framework.Providers.HUnit (testCase) | ||
import Test.HUnit (Assertion, (@=?)) | ||
|
||
tests :: Test | ||
tests = testGroup "Language.Haskell.Stylish.Step.Signature.Tests" | ||
[ testCase "do not wrap signature if it fits max column length" case00 | ||
-- , testCase "wrap signature if it does not fit max column length" case01 | ||
-- , testCase "how it behaves when there is a list of constraints" case02 | ||
-- , testCase "how it behaves when there is a explicit forall" case03 | ||
-- , testCase "how it behaves when there is a explicit forall" case04 | ||
-- , testCase "how it behaves when there is a large function in the argument" case05 | ||
] | ||
|
||
config :: Int -> Config | ||
config maxColumnLength = Config | ||
{ maxColumnLength = maxColumnLength | ||
} | ||
|
||
case00 :: Assertion | ||
case00 = expected @=? testStep (step $ config 80) input | ||
where | ||
input = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar :: a -> b -> a" | ||
, "fooBar v _ = v" | ||
] | ||
expected = input | ||
|
||
case01 :: Assertion | ||
case01 = expected @=? testStep (step $ config 20) input | ||
where | ||
input = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar :: a -> b -> a" | ||
, "fooBar v _ = v" | ||
] | ||
expected = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar ::" | ||
, " a" | ||
, " -> b" | ||
, " -> a" | ||
, "fooBar v _ = v" | ||
] | ||
|
||
case02 :: Assertion | ||
case02 = expected @=? testStep (step $ config 20) input | ||
where | ||
input = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar :: (Eq a, Show b) => a -> b -> a" | ||
, "fooBar v _ = v" | ||
] | ||
expected = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar ::" | ||
, " (Eq a, Show b)" | ||
, " => a" | ||
, " -> b" | ||
, " -> a" | ||
, "fooBar v _ = v" | ||
] | ||
|
||
case03 :: Assertion | ||
case03 = expected @=? testStep (step $ config 20) input | ||
where | ||
input = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar :: forall a . b. (Eq a, Show b) => a -> b -> a" | ||
, "fooBar v _ = v" | ||
] | ||
expected = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar ::" | ||
, " forall a . b." | ||
, " (Eq a, Show b)" | ||
, " => a" | ||
, " -> b" | ||
, " -> a" | ||
, "fooBar v _ = v" | ||
] | ||
|
||
case04 :: Assertion | ||
case04 = expected @=? testStep (step $ config 20) input | ||
where | ||
input = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar :: forall a . b. c. (Eq a, Show b, Ord c) => a -> b -> c -> a" | ||
, "fooBar v _ _ = v" | ||
] | ||
expected = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar ::" | ||
, " forall a . b. (" | ||
, " Eq a" | ||
, " , Show b" | ||
, " , Ord c)" | ||
, " )" | ||
, " => a" | ||
, " -> b" | ||
, " -> a" | ||
, "fooBar v _ = v" | ||
] | ||
|
||
case05 :: Assertion | ||
case05 = expected @=? testStep (step $ config 20) input | ||
where | ||
input = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar :: => a -> (forall c. Eq c => c -> a -> a) -> a" | ||
, "fooBar v _ = v" | ||
] | ||
expected = unlines | ||
[ "module Herp where" | ||
, "" | ||
, "fooBar ::" | ||
, " => a" | ||
, " -> ( forall c. Eq c" | ||
, " => c" | ||
, " -> a" | ||
, " -> a" | ||
, " )" | ||
, " -> a" | ||
, "fooBar v _ = v" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters