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