@@ -1934,6 +1934,28 @@ addFunctionConstraintTests = let
1934
1934
, " eq x y = x == y"
1935
1935
]
1936
1936
1937
+ missingConstraintWithForAllSourceCode :: T. Text -> T. Text
1938
+ missingConstraintWithForAllSourceCode constraint =
1939
+ T. unlines
1940
+ [ " {-# LANGUAGE ExplicitForAll #-}"
1941
+ , " module Testing where"
1942
+ , " "
1943
+ , " eq :: forall a. " <> constraint <> " a -> a -> Bool"
1944
+ , " eq x y = x == y"
1945
+ ]
1946
+
1947
+ incompleteConstraintWithForAllSourceCode :: T. Text -> T. Text
1948
+ incompleteConstraintWithForAllSourceCode constraint =
1949
+ T. unlines
1950
+ [ " {-# LANGUAGE ExplicitForAll #-}"
1951
+ , " module Testing where"
1952
+ , " "
1953
+ , " data Pair a b = Pair a b"
1954
+ , " "
1955
+ , " eq :: " <> constraint <> " => Pair a b -> Pair a b -> Bool"
1956
+ , " eq (Pair x y) (Pair x' y') = x == x' && y == y'"
1957
+ ]
1958
+
1937
1959
incompleteConstraintSourceCode :: T. Text -> T. Text
1938
1960
incompleteConstraintSourceCode constraint =
1939
1961
T. unlines
@@ -1978,8 +2000,8 @@ addFunctionConstraintTests = let
1978
2000
, " eq (Pair x y) (Pair x' y') = x == x' && y == y'"
1979
2001
]
1980
2002
1981
- check :: T. Text -> T. Text -> T. Text -> TestTree
1982
- check actionTitle originalCode expectedCode = testSession ( T. unpack actionTitle) $ do
2003
+ check :: String -> T. Text -> T. Text -> T. Text -> TestTree
2004
+ check testName actionTitle originalCode expectedCode = testSession testName $ do
1983
2005
doc <- createDoc " Testing.hs" " haskell" originalCode
1984
2006
_ <- waitForDiagnostics
1985
2007
actionsOrCommands <- getCodeActions doc (Range (Position 6 0 ) (Position 6 maxBound ))
@@ -1990,22 +2012,37 @@ addFunctionConstraintTests = let
1990
2012
1991
2013
in testGroup " add function constraint"
1992
2014
[ check
2015
+ " no preexisting constraint"
1993
2016
" Add `Eq a` to the context of the type signature for `eq`"
1994
2017
(missingConstraintSourceCode " " )
1995
2018
(missingConstraintSourceCode " Eq a => " )
1996
2019
, check
2020
+ " no preexisting constraint, with forall"
2021
+ " Add `Eq a` to the context of the type signature for `eq`"
2022
+ (missingConstraintWithForAllSourceCode " " )
2023
+ (missingConstraintWithForAllSourceCode " Eq a => " )
2024
+ , check
2025
+ " preexisting constraint, no parenthesis"
1997
2026
" Add `Eq b` to the context of the type signature for `eq`"
1998
2027
(incompleteConstraintSourceCode " Eq a" )
1999
2028
(incompleteConstraintSourceCode " (Eq a, Eq b)" )
2000
2029
, check
2030
+ " preexisting constraints in parenthesis"
2001
2031
" Add `Eq c` to the context of the type signature for `eq`"
2002
2032
(incompleteConstraintSourceCode2 " (Eq a, Eq b)" )
2003
2033
(incompleteConstraintSourceCode2 " (Eq a, Eq b, Eq c)" )
2034
+ , check
2035
+ " preexisting constraints with forall"
2036
+ " Add `Eq b` to the context of the type signature for `eq`"
2037
+ (incompleteConstraintWithForAllSourceCode " Eq a" )
2038
+ (incompleteConstraintWithForAllSourceCode " (Eq a, Eq b)" )
2004
2039
, check
2040
+ " preexisting constraint, with extra spaces in context"
2005
2041
" Add `Eq b` to the context of the type signature for `eq`"
2006
2042
(incompleteConstraintSourceCodeWithExtraCharsInContext " ( Eq a )" )
2007
2043
(incompleteConstraintSourceCodeWithExtraCharsInContext " (Eq a, Eq b)" )
2008
2044
, check
2045
+ " preexisting constraint, with newlines in type signature"
2009
2046
" Add `Eq b` to the context of the type signature for `eq`"
2010
2047
(incompleteConstraintSourceCodeWithNewlinesInTypeSignature " (Eq a)" )
2011
2048
(incompleteConstraintSourceCodeWithNewlinesInTypeSignature " (Eq a, Eq b)" )
0 commit comments