|
| 1 | +{-# LANGUAGE OverloadedLists #-} |
| 2 | +{-# LANGUAGE OverloadedStrings #-} |
| 3 | +module Language.Haskell.Stylish.Step.Signature.Tests |
| 4 | + ( tests |
| 5 | + ) where |
| 6 | + |
| 7 | +import Language.Haskell.Stylish.Step.Signature |
| 8 | +import Language.Haskell.Stylish.Tests.Util (assertSnippet, testStep) |
| 9 | +import Test.Framework (Test, testGroup) |
| 10 | +import Test.Framework.Providers.HUnit (testCase) |
| 11 | +import Test.HUnit (Assertion, (@=?)) |
| 12 | + |
| 13 | +tests :: Test |
| 14 | +tests = testGroup "Language.Haskell.Stylish.Step.Signature.Tests" |
| 15 | + [ testCase "do not wrap signature if it fits max column length" case00 |
| 16 | + -- , testCase "wrap signature if it does not fit max column length" case01 |
| 17 | + -- , testCase "how it behaves when there is a list of constraints" case02 |
| 18 | + -- , testCase "how it behaves when there is a explicit forall" case03 |
| 19 | + -- , testCase "how it behaves when there is a explicit forall" case04 |
| 20 | + -- , testCase "how it behaves when there is a large function in the argument" case05 |
| 21 | + ] |
| 22 | + |
| 23 | +config :: Int -> Config |
| 24 | +config maxColumnLength = Config |
| 25 | + { maxColumnLength = maxColumnLength |
| 26 | + } |
| 27 | + |
| 28 | +case00 :: Assertion |
| 29 | +case00 = expected @=? testStep (step $ config 80) input |
| 30 | + where |
| 31 | + input = unlines |
| 32 | + [ "module Herp where" |
| 33 | + , "" |
| 34 | + , "fooBar :: a -> b -> a" |
| 35 | + , "fooBar v _ = v" |
| 36 | + ] |
| 37 | + expected = input |
| 38 | + |
| 39 | +case01 :: Assertion |
| 40 | +case01 = expected @=? testStep (step $ config 20) input |
| 41 | + where |
| 42 | + input = unlines |
| 43 | + [ "module Herp where" |
| 44 | + , "" |
| 45 | + , "fooBar :: a -> b -> a" |
| 46 | + , "fooBar v _ = v" |
| 47 | + ] |
| 48 | + expected = unlines |
| 49 | + [ "module Herp where" |
| 50 | + , "" |
| 51 | + , "fooBar ::" |
| 52 | + , " a" |
| 53 | + , " -> b" |
| 54 | + , " -> a" |
| 55 | + , "fooBar v _ = v" |
| 56 | + ] |
| 57 | + |
| 58 | +case02 :: Assertion |
| 59 | +case02 = expected @=? testStep (step $ config 20) input |
| 60 | + where |
| 61 | + input = unlines |
| 62 | + [ "module Herp where" |
| 63 | + , "" |
| 64 | + , "fooBar :: (Eq a, Show b) => a -> b -> a" |
| 65 | + , "fooBar v _ = v" |
| 66 | + ] |
| 67 | + expected = unlines |
| 68 | + [ "module Herp where" |
| 69 | + , "" |
| 70 | + , "fooBar ::" |
| 71 | + , " (Eq a, Show b)" |
| 72 | + , " => a" |
| 73 | + , " -> b" |
| 74 | + , " -> a" |
| 75 | + , "fooBar v _ = v" |
| 76 | + ] |
| 77 | + |
| 78 | +case03 :: Assertion |
| 79 | +case03 = expected @=? testStep (step $ config 20) input |
| 80 | + where |
| 81 | + input = unlines |
| 82 | + [ "module Herp where" |
| 83 | + , "" |
| 84 | + , "fooBar :: forall a . b. (Eq a, Show b) => a -> b -> a" |
| 85 | + , "fooBar v _ = v" |
| 86 | + ] |
| 87 | + expected = unlines |
| 88 | + [ "module Herp where" |
| 89 | + , "" |
| 90 | + , "fooBar ::" |
| 91 | + , " forall a . b." |
| 92 | + , " (Eq a, Show b)" |
| 93 | + , " => a" |
| 94 | + , " -> b" |
| 95 | + , " -> a" |
| 96 | + , "fooBar v _ = v" |
| 97 | + ] |
| 98 | + |
| 99 | +case04 :: Assertion |
| 100 | +case04 = expected @=? testStep (step $ config 20) input |
| 101 | + where |
| 102 | + input = unlines |
| 103 | + [ "module Herp where" |
| 104 | + , "" |
| 105 | + , "fooBar :: forall a . b. c. (Eq a, Show b, Ord c) => a -> b -> c -> a" |
| 106 | + , "fooBar v _ _ = v" |
| 107 | + ] |
| 108 | + expected = unlines |
| 109 | + [ "module Herp where" |
| 110 | + , "" |
| 111 | + , "fooBar ::" |
| 112 | + , " forall a . b. (" |
| 113 | + , " Eq a" |
| 114 | + , " , Show b" |
| 115 | + , " , Ord c)" |
| 116 | + , " )" |
| 117 | + , " => a" |
| 118 | + , " -> b" |
| 119 | + , " -> a" |
| 120 | + , "fooBar v _ = v" |
| 121 | + ] |
| 122 | + |
| 123 | +case05 :: Assertion |
| 124 | +case05 = expected @=? testStep (step $ config 20) input |
| 125 | + where |
| 126 | + input = unlines |
| 127 | + [ "module Herp where" |
| 128 | + , "" |
| 129 | + , "fooBar :: => a -> (forall c. Eq c => c -> a -> a) -> a" |
| 130 | + , "fooBar v _ = v" |
| 131 | + ] |
| 132 | + expected = unlines |
| 133 | + [ "module Herp where" |
| 134 | + , "" |
| 135 | + , "fooBar ::" |
| 136 | + , " => a" |
| 137 | + , " -> ( forall c. Eq c" |
| 138 | + , " => c" |
| 139 | + , " -> a" |
| 140 | + , " -> a" |
| 141 | + , " )" |
| 142 | + , " -> a" |
| 143 | + , "fooBar v _ = v" |
| 144 | + ] |
0 commit comments