@@ -2574,6 +2574,7 @@ addImplicitParamsConstraintTests =
2574
2574
" fCaller :: " <> mkContext contextCaller <> " ()" ,
2575
2575
" fCaller = fBase"
2576
2576
]
2577
+
2577
2578
removeRedundantConstraintsTests :: TestTree
2578
2579
removeRedundantConstraintsTests = let
2579
2580
header =
@@ -2582,6 +2583,13 @@ removeRedundantConstraintsTests = let
2582
2583
, " "
2583
2584
]
2584
2585
2586
+ headerExt :: [T. Text ] -> [T. Text ]
2587
+ headerExt exts =
2588
+ redunt : extTxt ++ [" module Testing where" ]
2589
+ where
2590
+ redunt = " {-# OPTIONS_GHC -Wredundant-constraints #-}"
2591
+ extTxt = map (\ ext -> " {-# LANGUAGE " <> ext <> " #-}" ) exts
2592
+
2585
2593
redundantConstraintsCode :: Maybe T. Text -> T. Text
2586
2594
redundantConstraintsCode mConstraint =
2587
2595
let constraint = maybe " " (\ c -> " " <> c <> " => " ) mConstraint
@@ -2604,6 +2612,25 @@ removeRedundantConstraintsTests = let
2604
2612
, " foo x = x == 1"
2605
2613
]
2606
2614
2615
+ redundantConstraintsForall :: Maybe T. Text -> T. Text
2616
+ redundantConstraintsForall mConstraint =
2617
+ let constraint = maybe " " (\ c -> " " <> c <> " => " ) mConstraint
2618
+ in T. unlines $ headerExt [" RankNTypes" ] <>
2619
+ [ " foo :: forall a. " <> constraint <> " a -> a"
2620
+ , " foo = id"
2621
+ ]
2622
+
2623
+ typeSignatureNested :: Maybe T. Text -> T. Text
2624
+ typeSignatureNested mConstraint =
2625
+ let constraint = maybe " " (\ c -> " " <> c <> " => " ) mConstraint
2626
+ in T. unlines $ header <>
2627
+ [ " f :: Int -> ()"
2628
+ , " f = g"
2629
+ , " where"
2630
+ , " g :: " <> constraint <> " a -> ()"
2631
+ , " g _ = ()"
2632
+ ]
2633
+
2607
2634
typeSignatureMultipleLines :: T. Text
2608
2635
typeSignatureMultipleLines = T. unlines $ header <>
2609
2636
[ " foo :: (Num a, Eq a, Monoid a)"
@@ -2615,7 +2642,7 @@ removeRedundantConstraintsTests = let
2615
2642
check actionTitle originalCode expectedCode = testSession (T. unpack actionTitle) $ do
2616
2643
doc <- createDoc " Testing.hs" " haskell" originalCode
2617
2644
_ <- waitForDiagnostics
2618
- actionsOrCommands <- getCodeActions doc ( Range ( Position 4 0 ) ( Position 4 maxBound ))
2645
+ actionsOrCommands <- getAllCodeActions doc
2619
2646
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
2620
2647
executeCodeAction chosenAction
2621
2648
modifiedCode <- documentContents doc
@@ -2641,6 +2668,14 @@ removeRedundantConstraintsTests = let
2641
2668
" Remove redundant constraints `(Monoid a, Show a)` from the context of the type signature for `foo`"
2642
2669
(redundantMixedConstraintsCode $ Just " Monoid a, Show a" )
2643
2670
(redundantMixedConstraintsCode Nothing )
2671
+ , check
2672
+ " Remove redundant constraint `Eq a` from the context of the type signature for `g`"
2673
+ (typeSignatureNested $ Just " Eq a" )
2674
+ (typeSignatureNested Nothing )
2675
+ , check
2676
+ " Remove redundant constraint `Eq a` from the context of the type signature for `foo`"
2677
+ (redundantConstraintsForall $ Just " Eq a" )
2678
+ (redundantConstraintsForall Nothing )
2644
2679
, checkPeculiarFormatting
2645
2680
" should do nothing when constraints contain an arbitrary number of spaces"
2646
2681
typeSignatureSpaces
0 commit comments