Skip to content

Commit 3c5c952

Browse files
committed
fix some tests
1 parent 2074b00 commit 3c5c952

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

ghcide/test/exe/Main.hs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ typeWildCardActionTests = testGroup "type wildcard actions"
846846
]
847847
doc <- createDoc "Testing.hs" "haskell" content
848848
_ <- waitForDiagnostics
849-
actionsOrCommands <- getCodeActions doc (Range (Position 2 1) (Position 2 10))
849+
actionsOrCommands <- getAllCodeActions doc
850850
let [addSignature] = [action | InR action@CodeAction { _title = actionTitle } <- actionsOrCommands
851851
, "Use type signature" `T.isInfixOf` actionTitle
852852
]
@@ -866,7 +866,7 @@ typeWildCardActionTests = testGroup "type wildcard actions"
866866
]
867867
doc <- createDoc "Testing.hs" "haskell" content
868868
_ <- waitForDiagnostics
869-
actionsOrCommands <- getCodeActions doc (Range (Position 2 1) (Position 2 10))
869+
actionsOrCommands <- getAllCodeActions doc
870870
let [addSignature] = [action | InR action@CodeAction { _title = actionTitle } <- actionsOrCommands
871871
, "Use type signature" `T.isInfixOf` actionTitle
872872
]
@@ -889,7 +889,7 @@ typeWildCardActionTests = testGroup "type wildcard actions"
889889
]
890890
doc <- createDoc "Testing.hs" "haskell" content
891891
_ <- waitForDiagnostics
892-
actionsOrCommands <- getCodeActions doc (Range (Position 4 1) (Position 4 10))
892+
actionsOrCommands <- getAllCodeActions doc
893893
let [addSignature] = [action | InR action@CodeAction { _title = actionTitle } <- actionsOrCommands
894894
, "Use type signature" `T.isInfixOf` actionTitle
895895
]
@@ -1111,7 +1111,7 @@ removeImportTests = testGroup "remove import actions"
11111111
doc <- createDoc "ModuleC.hs" "haskell" content
11121112
_ <- waitForDiagnostics
11131113
[_, _, _, _, InR action@CodeAction { _title = actionTitle }]
1114-
<- getCodeActions doc (Range (Position 2 0) (Position 2 5))
1114+
<- nub <$> getAllCodeActions doc
11151115
liftIO $ "Remove all redundant imports" @=? actionTitle
11161116
executeCodeAction action
11171117
contentAfterAction <- documentContents doc
@@ -1149,7 +1149,7 @@ extendImportTests = testGroup "extend import actions"
11491149
, "import ModuleA as A (stuffB)"
11501150
, "main = print (stuffA, stuffB)"
11511151
])
1152-
(Range (Position 3 17) (Position 3 18))
1152+
(Range (Position 2 17) (Position 2 18))
11531153
["Add stuffA to the import list of ModuleA"]
11541154
(T.unlines
11551155
[ "module ModuleB where"
@@ -1169,7 +1169,7 @@ extendImportTests = testGroup "extend import actions"
11691169
, "import ModuleA as A (stuffB)"
11701170
, "main = print (stuffB .* stuffB)"
11711171
])
1172-
(Range (Position 3 17) (Position 3 18))
1172+
(Range (Position 2 17) (Position 2 18))
11731173
["Add (.*) to the import list of ModuleA"]
11741174
(T.unlines
11751175
[ "module ModuleB where"
@@ -1206,7 +1206,7 @@ extendImportTests = testGroup "extend import actions"
12061206
, "b :: A"
12071207
, "b = Constructor"
12081208
])
1209-
(Range (Position 2 5) (Position 2 5))
1209+
(Range (Position 3 5) (Position 3 5))
12101210
["Add A(Constructor) to the import list of ModuleA"]
12111211
(T.unlines
12121212
[ "module ModuleB where"
@@ -1225,7 +1225,7 @@ extendImportTests = testGroup "extend import actions"
12251225
, "b :: A"
12261226
, "b = Constructor"
12271227
])
1228-
(Range (Position 2 5) (Position 2 5))
1228+
(Range (Position 3 5) (Position 3 5))
12291229
["Add A(Constructor) to the import list of ModuleA"]
12301230
(T.unlines
12311231
[ "module ModuleB where"
@@ -1245,7 +1245,7 @@ extendImportTests = testGroup "extend import actions"
12451245
, "b :: A"
12461246
, "b = ConstructorFoo"
12471247
])
1248-
(Range (Position 2 5) (Position 2 5))
1248+
(Range (Position 3 5) (Position 3 5))
12491249
["Add A(ConstructorFoo) to the import list of ModuleA"]
12501250
(T.unlines
12511251
[ "module ModuleB where"
@@ -1266,7 +1266,7 @@ extendImportTests = testGroup "extend import actions"
12661266
, "import qualified ModuleA as A (stuffB)"
12671267
, "main = print (A.stuffA, A.stuffB)"
12681268
])
1269-
(Range (Position 3 17) (Position 3 18))
1269+
(Range (Position 2 17) (Position 2 18))
12701270
["Add stuffA to the import list of ModuleA"]
12711271
(T.unlines
12721272
[ "module ModuleB where"
@@ -1682,9 +1682,7 @@ suggestImportDisambiguationTests = testGroup "suggest import disambiguation acti
16821682
doc <- openDoc file "haskell"
16831683
waitForProgressDone
16841684
void $ expectDiagnostics [(file, [(DsError, loc, "Ambiguous occurrence") | loc <- locs])]
1685-
contents <- documentContents doc
1686-
let range = Range (Position 0 0) (Position (length $ T.lines contents) 0)
1687-
actions <- getCodeActions doc range
1685+
actions <- getAllCodeActions doc
16881686
k doc actions
16891687
withHideFunction = withTarget ("HideFunction" <.> "hs")
16901688

@@ -1891,7 +1889,7 @@ insertNewDefinitionTests = testGroup "insert new definition actions"
18911889
_ <- waitForDiagnostics
18921890
InR action@CodeAction { _title = actionTitle } : _
18931891
<- sortOn (\(InR CodeAction{_title=x}) -> x) <$>
1894-
getCodeActions docB (R 1 0 1 50)
1892+
getCodeActions docB (R 0 0 0 50)
18951893
liftIO $ actionTitle @?= "Define select :: [Bool] -> Bool"
18961894
executeCodeAction action
18971895
contentAfterAction <- documentContents docB
@@ -1915,7 +1913,7 @@ insertNewDefinitionTests = testGroup "insert new definition actions"
19151913
_ <- waitForDiagnostics
19161914
InR action@CodeAction { _title = actionTitle } : _
19171915
<- sortOn (\(InR CodeAction{_title=x}) -> x) <$>
1918-
getCodeActions docB (R 1 0 1 50)
1916+
getCodeActions docB (R 0 0 0 50)
19191917
liftIO $ actionTitle @?= "Define select :: [Bool] -> Bool"
19201918
executeCodeAction action
19211919
contentAfterAction <- documentContents docB
@@ -2063,15 +2061,15 @@ deleteUnusedDefinitionTests = testGroup "delete unused definition action"
20632061
docId <- createDoc "A.hs" "haskell" source
20642062
expectDiagnostics [ ("A.hs", [(DsWarning, pos, "not used")]) ]
20652063

2066-
(action, title) <- extractCodeAction docId "Delete"
2064+
(action, title) <- extractCodeAction docId "Delete" pos
20672065

20682066
liftIO $ title @?= expectedTitle
20692067
executeCodeAction action
20702068
contentAfterAction <- documentContents docId
20712069
liftIO $ contentAfterAction @?= expectedResult
20722070

2073-
extractCodeAction docId actionPrefix = do
2074-
[action@CodeAction { _title = actionTitle }] <- findCodeActionsByPrefix docId (R 0 0 0 0) [actionPrefix]
2071+
extractCodeAction docId actionPrefix (l, c) = do
2072+
[action@CodeAction { _title = actionTitle }] <- findCodeActionsByPrefix docId (R l c l c) [actionPrefix]
20752073
return (action, actionTitle)
20762074

20772075
addTypeAnnotationsToLiteralsTest :: TestTree
@@ -2196,15 +2194,16 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
21962194
docId <- createDoc "A.hs" "haskell" source
21972195
expectDiagnostics [ ("A.hs", diag) ]
21982196

2199-
(action, title) <- extractCodeAction docId "Add type annotation"
2197+
let cursors = map snd3 diag
2198+
(action, title) <- extractCodeAction docId "Add type annotation" (minimum cursors) (maximum cursors)
22002199

22012200
liftIO $ title @?= expectedTitle
22022201
executeCodeAction action
22032202
contentAfterAction <- documentContents docId
22042203
liftIO $ contentAfterAction @?= expectedResult
22052204

2206-
extractCodeAction docId actionPrefix = do
2207-
[action@CodeAction { _title = actionTitle }] <- findCodeActionsByPrefix docId (R 0 0 0 0) [actionPrefix]
2205+
extractCodeAction docId actionPrefix (l,c) (l', c')= do
2206+
[action@CodeAction { _title = actionTitle }] <- findCodeActionsByPrefix docId (R l c l' c') [actionPrefix]
22082207
return (action, actionTitle)
22092208

22102209

@@ -2250,7 +2249,7 @@ importRenameActionTests = testGroup "import rename actions"
22502249
]
22512250
doc <- createDoc "Testing.hs" "haskell" content
22522251
_ <- waitForDiagnostics
2253-
actionsOrCommands <- getCodeActions doc (Range (Position 2 8) (Position 2 16))
2252+
actionsOrCommands <- getCodeActions doc (Range (Position 1 8) (Position 1 16))
22542253
let [changeToMap] = [action | InR action@CodeAction{ _title = actionTitle } <- actionsOrCommands, ("Data." <> modname) `T.isInfixOf` actionTitle ]
22552254
executeCodeAction changeToMap
22562255
contentAfterAction <- documentContents doc
@@ -2380,7 +2379,7 @@ addInstanceConstraintTests = let
23802379
check actionTitle originalCode expectedCode = testSession (T.unpack actionTitle) $ do
23812380
doc <- createDoc "Testing.hs" "haskell" originalCode
23822381
_ <- waitForDiagnostics
2383-
actionsOrCommands <- getCodeActions doc (Range (Position 6 0) (Position 6 68))
2382+
actionsOrCommands <- getAllCodeActions doc
23842383
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
23852384
executeCodeAction chosenAction
23862385
modifiedCode <- documentContents doc
@@ -2532,7 +2531,7 @@ checkCodeAction :: String -> T.Text -> T.Text -> T.Text -> TestTree
25322531
checkCodeAction testName actionTitle originalCode expectedCode = testSession testName $ do
25332532
doc <- createDoc "Testing.hs" "haskell" originalCode
25342533
_ <- waitForDiagnostics
2535-
actionsOrCommands <- getCodeActions doc (Range (Position 6 0) (Position 6 maxBound))
2534+
actionsOrCommands <- getAllCodeActions doc
25362535
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
25372536
executeCodeAction chosenAction
25382537
modifiedCode <- documentContents doc
@@ -2615,7 +2614,7 @@ removeRedundantConstraintsTests = let
26152614
check actionTitle originalCode expectedCode = testSession (T.unpack actionTitle) $ do
26162615
doc <- createDoc "Testing.hs" "haskell" originalCode
26172616
_ <- waitForDiagnostics
2618-
actionsOrCommands <- getCodeActions doc (Range (Position 4 0) (Position 4 maxBound))
2617+
actionsOrCommands <- getAllCodeActions doc
26192618
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
26202619
executeCodeAction chosenAction
26212620
modifiedCode <- documentContents doc
@@ -2625,7 +2624,7 @@ removeRedundantConstraintsTests = let
26252624
checkPeculiarFormatting title code = testSession title $ do
26262625
doc <- createDoc "Testing.hs" "haskell" code
26272626
_ <- waitForDiagnostics
2628-
actionsOrCommands <- getCodeActions doc (Range (Position 4 0) (Position 4 maxBound))
2627+
actionsOrCommands <- getAllCodeActions doc
26292628
liftIO $ assertBool "Found some actions" (null actionsOrCommands)
26302629

26312630
in testGroup "remove redundant function constraints"
@@ -2769,7 +2768,7 @@ exportUnusedTests = testGroup "export unused actions"
27692768
, " ) where"
27702769
, "foo = id"
27712770
, "bar = foo"])
2772-
(R 4 0 4 3)
2771+
(R 5 0 5 3)
27732772
"Export ‘bar’"
27742773
(Just $ T.unlines
27752774
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"

0 commit comments

Comments
 (0)