@@ -2,6 +2,8 @@
2-- SPDX-License-Identifier: Apache-2.0
2-- SPDX-License-Identifier: Apache-2.0
4{-# LANGUAGE DuplicateRecordFields #-}
4{-# LANGUAGE DuplicateRecordFields #-}
6+#include "ghc-api-version.h"
6module Main (main) where
8module Main (main) where
@@ -232,6 +234,7 @@ codeActionTests = testGroup "code actions"
232 , typeWildCardActionTests
234 , typeWildCardActionTests
233 , removeImportTests
235 , removeImportTests
234 , importRenameActionTests
236 , importRenameActionTests
237+ , fillTypedHoleTests
237renameActionTests :: TestTree
240renameActionTests :: TestTree
@@ -453,6 +456,75 @@ importRenameActionTests = testGroup "import rename actions"
454 liftIO $ expectedContentAfterAction @=? contentAfterAction
457 liftIO $ expectedContentAfterAction @=? contentAfterAction
459+fillTypedHoleTests :: TestTree
460+fillTypedHoleTests = let
462+ sourceCode :: T.Text -> T.Text -> T.Text -> T.Text
463+ sourceCode a b c = T.unlines
464+ [ "module Testing where"
466+ , "globalConvert :: Int -> String"
467+ , "globalConvert = undefined"
469+ , "globalInt :: Int"
472+ , "bar :: Int -> Int -> String"
473+ , "bar n parameterInt = " <> a <> " (n + " <> b <> " + " <> c <> ") where"
474+ , " localConvert = (flip replicate) 'x'"
478+ check :: T.Text -> T.Text -> T.Text -> T.Text -> T.Text -> T.Text -> T.Text -> TestTree
481+ newA newB newC = testSession (T.unpack actionTitle) $ do
482+ let originalCode = sourceCode oldA oldB oldC
483+ let expectedCode = sourceCode newA newB newC
484+ doc <- openDoc' "Testing.hs" "haskell" originalCode
485+ _ <- waitForDiagnostics
486+ actionsOrCommands <- getCodeActions doc (Range (Position 9 0) (Position 9 maxBound))
487+ let chosenAction = pickActionWithTitle actionTitle actionsOrCommands
488+ executeCodeAction chosenAction
489+ modifiedCode <- documentContents doc
490+ liftIO $ expectedCode @=? modifiedCode
492+ pickActionWithTitle title actions = head
494+ | CACodeAction action@CodeAction{ _title = actionTitle } <- actions
495+ , title == actionTitle ]
498+ testGroup "fill typed holes"
499+ [ check "replace hole `_` with show"
503+ , check "replace hole `_` with globalConvert"
505+ "globalConvert" "n" "n"
507+#if MIN_GHC_API_VERSION(8,6,0)
508+ , check "replace hole `_convertme` with localConvert"
509+ "_convertme" "n" "n"
510+ "localConvert" "n" "n"
513+ , check "replace hole `_b` with globalInt"
515+ "_a" "globalInt" "_c"
517+ , check "replace hole `_c` with globalInt"
519+ "_a" "_b" "globalInt"
521+#if MIN_GHC_API_VERSION(8,6,0)
522+ , check "replace hole `_c` with parameterInt"
524+ "_a" "_b" "parameterInt"
456----------------------------------------------------------------------
528----------------------------------------------------------------------