@@ -7,7 +7,9 @@ module Main
7
7
) where
8
8
9
9
import Control.Lens ((^.) )
10
+ import Control.Monad (when )
10
11
import Data.Aeson (Value (.. ), object , toJSON , (.=) )
12
+ import Data.Functor (void )
11
13
import Data.List (find )
12
14
import qualified Data.Map as Map
13
15
import Data.Maybe (fromJust , isJust )
@@ -30,26 +32,40 @@ tests = testGroup "hlint" [
30
32
suggestionsTests
31
33
, configTests
32
34
, ignoreHintTests
35
+ , applyHintTests
33
36
]
34
37
35
38
getIgnoreHintText :: T. Text -> T. Text
36
39
getIgnoreHintText name = " Ignore hint \" " <> name <> " \" in this module"
37
40
41
+ getApplyHintText :: T. Text -> T. Text
42
+ getApplyHintText name = " Apply hint \" " <> name <> " \" "
43
+
38
44
ignoreHintTests :: TestTree
39
45
ignoreHintTests = testGroup " hlint ignore hint tests"
40
46
[
41
- ignoreGoldenTest
47
+ ignoreHintGoldenTest
42
48
" Ignore hint in this module inserts -Wno-unrecognised-pragmas and hlint ignore pragma if warn unrecognized pragmas is off"
43
49
" UnrecognizedPragmasOff"
44
50
(Point 3 8 )
45
51
" Eta reduce"
46
- , ignoreGoldenTest
52
+ , ignoreHintGoldenTest
47
53
" Ignore hint in this module inserts only hlint ignore pragma if warn unrecognized pragmas is on"
48
54
" UnrecognizedPragmasOn"
49
55
(Point 3 9 )
50
56
" Eta reduce"
51
57
]
52
58
59
+ applyHintTests :: TestTree
60
+ applyHintTests = testGroup " hlint apply hint tests"
61
+ [
62
+ applyHintGoldenTest
63
+ " [#2612] Apply hint works when operator fixities go right-to-left"
64
+ " RightToLeftFixities"
65
+ (Point 6 13 )
66
+ " Avoid reverse"
67
+ ]
68
+
53
69
suggestionsTests :: TestTree
54
70
suggestionsTests =
55
71
testGroup " hlint suggestions" [
@@ -378,13 +394,24 @@ makeCodeActionFoundAtString :: Point -> String
378
394
makeCodeActionFoundAtString Point {.. } =
379
395
" CodeAction found at line: " <> show line <> " , column: " <> show column
380
396
381
- ignoreGoldenTest :: TestName -> FilePath -> Point -> T. Text -> TestTree
382
- ignoreGoldenTest testCaseName goldenFilename point hintName =
397
+ ignoreHintGoldenTest :: TestName -> FilePath -> Point -> T. Text -> TestTree
398
+ ignoreHintGoldenTest testCaseName goldenFilename point hintName =
399
+ goldenTest testCaseName goldenFilename point (getIgnoreHintText hintName)
400
+
401
+ applyHintGoldenTest :: TestName -> FilePath -> Point -> T. Text -> TestTree
402
+ applyHintGoldenTest testCaseName goldenFilename point hintName = do
403
+ goldenTest testCaseName goldenFilename point (getApplyHintText hintName)
404
+
405
+ goldenTest :: TestName -> FilePath -> Point -> T. Text -> TestTree
406
+ goldenTest testCaseName goldenFilename point hintText =
383
407
setupGoldenHlintTest testCaseName goldenFilename $ \ document -> do
384
408
waitForDiagnosticsFromSource document " hlint"
385
409
actions <- getCodeActions document $ pointToRange point
386
- case find ((== Just (getIgnoreHintText hintName)) . getCodeActionTitle) actions of
387
- Just (InR codeAction) -> executeCodeAction codeAction
410
+ case find ((== Just hintText) . getCodeActionTitle) actions of
411
+ Just (InR codeAction) -> do
412
+ executeCodeAction codeAction
413
+ when (isJust (codeAction ^. L. command)) $
414
+ void $ skipManyTill anyMessage $ getDocumentEdit document
388
415
_ -> liftIO $ assertFailure $ makeCodeActionNotFoundAtString point
389
416
390
417
setupGoldenHlintTest :: TestName -> FilePath -> (TextDocumentIdentifier -> Session () ) -> TestTree
0 commit comments