@@ -1188,73 +1188,71 @@ renameActionTests = testGroup "rename actions"
1188
1188
1189
1189
typeWildCardActionTests :: TestTree
1190
1190
typeWildCardActionTests = testGroup " type wildcard actions"
1191
- [ testSession " global signature" $ do
1192
- let content = T. unlines
1193
- [ " module Testing where"
1194
- , " func :: _"
1195
- , " func x = x"
1196
- ]
1197
- doc <- createDoc " Testing.hs" " haskell" content
1198
- _ <- waitForDiagnostics
1199
- actionsOrCommands <- getAllCodeActions doc
1200
- let [addSignature] = [action | InR action@ CodeAction { _title = actionTitle } <- actionsOrCommands
1201
- , " Use type signature" `T.isInfixOf` actionTitle
1202
- ]
1203
- executeCodeAction addSignature
1204
- contentAfterAction <- documentContents doc
1205
- let expectedContentAfterAction = T. unlines
1206
- [ " module Testing where"
1207
- , " func :: (p -> p)"
1208
- , " func x = x"
1209
- ]
1210
- liftIO $ expectedContentAfterAction @=? contentAfterAction
1211
- , testSession " multi-line message" $ do
1212
- let content = T. unlines
1213
- [ " module Testing where"
1214
- , " func :: _"
1215
- , " func x y = x + y"
1216
- ]
1217
- doc <- createDoc " Testing.hs" " haskell" content
1218
- _ <- waitForDiagnostics
1219
- actionsOrCommands <- getAllCodeActions doc
1220
- let [addSignature] = [action | InR action@ CodeAction { _title = actionTitle } <- actionsOrCommands
1221
- , " Use type signature" `T.isInfixOf` actionTitle
1222
- ]
1223
- executeCodeAction addSignature
1224
- contentAfterAction <- documentContents doc
1225
- let expectedContentAfterAction = T. unlines
1226
- [ " module Testing where"
1227
- , " func :: (Integer -> Integer -> Integer)"
1228
- , " func x y = x + y"
1229
- ]
1230
- liftIO $ expectedContentAfterAction @=? contentAfterAction
1231
- , testSession " local signature" $ do
1232
- let content = T. unlines
1233
- [ " module Testing where"
1234
- , " func :: Int -> Int"
1235
- , " func x ="
1236
- , " let y :: _"
1237
- , " y = x * 2"
1238
- , " in y"
1239
- ]
1240
- doc <- createDoc " Testing.hs" " haskell" content
1241
- _ <- waitForDiagnostics
1242
- actionsOrCommands <- getAllCodeActions doc
1243
- let [addSignature] = [action | InR action@ CodeAction { _title = actionTitle } <- actionsOrCommands
1244
- , " Use type signature" `T.isInfixOf` actionTitle
1245
- ]
1246
- executeCodeAction addSignature
1247
- contentAfterAction <- documentContents doc
1248
- let expectedContentAfterAction = T. unlines
1249
- [ " module Testing where"
1250
- , " func :: Int -> Int"
1251
- , " func x ="
1252
- , " let y :: (Int)"
1253
- , " y = x * 2"
1254
- , " in y"
1255
- ]
1256
- liftIO $ expectedContentAfterAction @=? contentAfterAction
1191
+ [ testUseTypeSignature " global signature"
1192
+ [ " func :: _"
1193
+ , " func x = x"
1194
+ ]
1195
+ [ " func :: (p -> p)"
1196
+ , " func x = x"
1197
+ ]
1198
+ , testUseTypeSignature " local signature"
1199
+ [ " func :: Int -> Int"
1200
+ , " func x ="
1201
+ , " let y :: _"
1202
+ , " y = x * 2"
1203
+ , " in y"
1204
+ ]
1205
+ [ " func :: Int -> Int"
1206
+ , " func x ="
1207
+ , " let y :: Int"
1208
+ , " y = x * 2"
1209
+ , " in y"
1210
+ ]
1211
+ , testUseTypeSignature " multi-line message"
1212
+ [ " func :: _"
1213
+ , " func x y = x + y"
1214
+ ]
1215
+ [ " func :: (Integer -> Integer -> Integer)"
1216
+ , " func x y = x + y"
1217
+ ]
1218
+ , testUseTypeSignature " type in parentheses"
1219
+ [ " func :: a -> _"
1220
+ , " func x = (x, const x)"
1221
+ ]
1222
+ [ " func :: a -> (a, b -> a)"
1223
+ , " func x = (x, const x)"
1224
+ ]
1225
+ , testUseTypeSignature " type in brackets"
1226
+ [ " func :: _ -> Maybe a"
1227
+ , " func xs = head xs"
1228
+ ]
1229
+ [ " func :: [Maybe a] -> Maybe a"
1230
+ , " func xs = head xs"
1231
+ ]
1232
+ , testUseTypeSignature " unit type"
1233
+ [ " func :: IO _"
1234
+ , " func = putChar 'H'"
1235
+ ]
1236
+ [ " func :: IO ()"
1237
+ , " func = putChar 'H'"
1238
+ ]
1257
1239
]
1240
+ where
1241
+ -- | Test session of given name, checking action "Use type signature..."
1242
+ -- on a test file with given content and comparing to expected result.
1243
+ testUseTypeSignature name textIn textOut = testSession name $ do
1244
+ let fileStart = " module Testing where"
1245
+ content = T. unlines $ fileStart : textIn
1246
+ expectedContentAfterAction = T. unlines $ fileStart : textOut
1247
+ doc <- createDoc " Testing.hs" " haskell" content
1248
+ _ <- waitForDiagnostics
1249
+ actionsOrCommands <- getAllCodeActions doc
1250
+ let [addSignature] = [action | InR action@ CodeAction { _title = actionTitle } <- actionsOrCommands
1251
+ , " Use type signature" `T.isInfixOf` actionTitle
1252
+ ]
1253
+ executeCodeAction addSignature
1254
+ contentAfterAction <- documentContents doc
1255
+ liftIO $ expectedContentAfterAction @=? contentAfterAction
1258
1256
1259
1257
{-# HLINT ignore "Use nubOrd" #-}
1260
1258
removeImportTests :: TestTree
0 commit comments