Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace faulty signature test #1792

Merged
merged 2 commits into from
May 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2785,13 +2785,39 @@ removeRedundantConstraintsTests = let
, " in h"
]

typeSignatureMultipleLines :: T.Text
typeSignatureMultipleLines = T.unlines $ header <>
[ "foo :: (Num a, Eq a, Monoid a)"
, "=> a -> Bool"
, "foo x = x == 1"
typeSignatureLined1 = T.unlines $ header <>
[ "foo :: Eq a =>"
, " a -> Bool"
, "foo _ = True"
]

typeSignatureLined2 = T.unlines $ header <>
[ "foo :: (Eq a, Show a)"
, " => a -> Bool"
, "foo _ = True"
]

typeSignatureOneLine = T.unlines $ header <>
[ "foo :: a -> Bool"
, "foo _ = True"
]

typeSignatureLined3 = T.unlines $ header <>
[ "foo :: ( Eq a"
, " , Show a"
, " )"
, " => a -> Bool"
, "foo x = x == x"
]

typeSignatureLined3' = T.unlines $ header <>
[ "foo :: ( Eq a"
, " )"
, " => a -> Bool"
, "foo x = x == x"
]


check :: T.Text -> T.Text -> T.Text -> TestTree
check actionTitle originalCode expectedCode = testSession (T.unpack actionTitle) $ do
doc <- createDoc "Testing.hs" "haskell" originalCode
Expand All @@ -2802,13 +2828,6 @@ removeRedundantConstraintsTests = let
modifiedCode <- documentContents doc
liftIO $ expectedCode @=? modifiedCode

checkPeculiarFormatting :: String -> T.Text -> TestTree
checkPeculiarFormatting title code = testSession title $ do
doc <- createDoc "Testing.hs" "haskell" code
_ <- waitForDiagnostics
actionsOrCommands <- getAllCodeActions doc
liftIO $ assertBool "Found some actions" (null actionsOrCommands)

in testGroup "remove redundant function constraints"
[ check
"Remove redundant constraint `Eq a` from the context of the type signature for `foo`"
Expand Down Expand Up @@ -2846,9 +2865,18 @@ removeRedundantConstraintsTests = let
"Remove redundant constraints `(Monoid a, Show a)` from the context of the type signature for `foo`"
(typeSignatureSpaces $ Just "Monoid a, Show a")
(typeSignatureSpaces Nothing)
, checkPeculiarFormatting
"should do nothing when constraints contain line feeds"
typeSignatureMultipleLines
, check
"Remove redundant constraint `Eq a` from the context of the type signature for `foo`"
typeSignatureLined1
typeSignatureOneLine
, check
"Remove redundant constraints `(Eq a, Show a)` from the context of the type signature for `foo`"
typeSignatureLined2
typeSignatureOneLine
, check
"Remove redundant constraint `Show a` from the context of the type signature for `foo`"
typeSignatureLined3
typeSignatureLined3'
]

addSigActionTests :: TestTree
Expand Down