From 2c7b53c4260ec6275a82a920213e047f55a5ffcb Mon Sep 17 00:00:00 2001 From: kderme Date: Tue, 4 May 2021 12:14:25 +0300 Subject: [PATCH] Replace faulty signature test --- ghcide/test/exe/Main.hs | 58 ++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/ghcide/test/exe/Main.hs b/ghcide/test/exe/Main.hs index 7bf97280bc..828d4c9bda 100644 --- a/ghcide/test/exe/Main.hs +++ b/ghcide/test/exe/Main.hs @@ -2784,13 +2784,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 @@ -2801,13 +2827,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`" @@ -2845,9 +2864,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