@@ -7,7 +7,9 @@ module Main
77 ) where
88
99import Control.Lens ((^.) )
10+ import Control.Monad (when )
1011import Data.Aeson (Value (.. ), object , toJSON , (.=) )
12+ import Data.Functor (void )
1113import Data.List (find )
1214import qualified Data.Map as Map
1315import Data.Maybe (fromJust , isJust )
@@ -30,26 +32,40 @@ tests = testGroup "hlint" [
3032 suggestionsTests
3133 , configTests
3234 , ignoreHintTests
35+ , applyHintTests
3336 ]
3437
3538getIgnoreHintText :: T. Text -> T. Text
3639getIgnoreHintText name = " Ignore hint \" " <> name <> " \" in this module"
3740
41+ getApplyHintText :: T. Text -> T. Text
42+ getApplyHintText name = " Apply hint \" " <> name <> " \" "
43+
3844ignoreHintTests :: TestTree
3945ignoreHintTests = testGroup " hlint ignore hint tests"
4046 [
41- ignoreGoldenTest
47+ ignoreHintGoldenTest
4248 " Ignore hint in this module inserts -Wno-unrecognised-pragmas and hlint ignore pragma if warn unrecognized pragmas is off"
4349 " UnrecognizedPragmasOff"
4450 (Point 3 8 )
4551 " Eta reduce"
46- , ignoreGoldenTest
52+ , ignoreHintGoldenTest
4753 " Ignore hint in this module inserts only hlint ignore pragma if warn unrecognized pragmas is on"
4854 " UnrecognizedPragmasOn"
4955 (Point 3 9 )
5056 " Eta reduce"
5157 ]
5258
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+
5369suggestionsTests :: TestTree
5470suggestionsTests =
5571 testGroup " hlint suggestions" [
@@ -378,13 +394,24 @@ makeCodeActionFoundAtString :: Point -> String
378394makeCodeActionFoundAtString Point {.. } =
379395 " CodeAction found at line: " <> show line <> " , column: " <> show column
380396
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 =
383407 setupGoldenHlintTest testCaseName goldenFilename $ \ document -> do
384408 waitForDiagnosticsFromSource document " hlint"
385409 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
388415 _ -> liftIO $ assertFailure $ makeCodeActionNotFoundAtString point
389416
390417setupGoldenHlintTest :: TestName -> FilePath -> (TextDocumentIdentifier -> Session () ) -> TestTree
0 commit comments