1
- {-# LANGUAGE LambdaCase #-}
2
- {-# LANGUAGE OverloadedStrings #-}
3
- {-# LANGUAGE ScopedTypeVariables #-}
4
- {-# LANGUAGE TypeOperators #-}
1
+ {-# LANGUAGE LambdaCase #-}
2
+ {-# LANGUAGE OverloadedStrings #-}
3
+ {-# LANGUAGE TypeOperators #-}
4
+
5
+ {-# OPTIONS_GHC -Wall #-}
5
6
module Main
6
7
( main
7
- )
8
- where
8
+ ) where
9
9
10
- import Control.Lens hiding ((<.>) )
11
- import qualified Data.ByteString.Lazy as BS
12
- import qualified Data.Text.Encoding as T
10
+ import Control.Lens (Prism' , prism' , (^..) , (^?) )
11
+ import Control.Monad (void )
13
12
import qualified Ide.Plugin.Class as Class
14
13
import qualified Language.LSP.Types.Lens as J
15
14
import System.FilePath
@@ -18,14 +17,14 @@ import Test.Hls
18
17
main :: IO ()
19
18
main = defaultTestRunner tests
20
19
21
- plugin :: PluginDescriptor IdeState
22
- plugin = Class. descriptor " class"
20
+ classPlugin :: PluginDescriptor IdeState
21
+ classPlugin = Class. descriptor " class"
23
22
24
23
tests :: TestTree
25
24
tests = testGroup
26
25
" class"
27
26
[ testCase " Produces addMinimalMethodPlaceholders code actions for one instance" $ do
28
- runSessionWithServer plugin classPath $ do
27
+ runSessionWithServer classPlugin testDataDir $ do
29
28
doc <- openDoc " T1.hs" " haskell"
30
29
_ <- waitForDiagnosticsFromSource doc " typecheck"
31
30
caResults <- getAllCodeActions doc
@@ -34,23 +33,17 @@ tests = testGroup
34
33
[ Just " Add placeholders for '=='"
35
34
, Just " Add placeholders for '/='"
36
35
]
37
- , glodenTest " Creates a placeholder for '=='" " T1" " eq"
38
- $ \ (eqAction: _) -> do
36
+ , goldenWithClass " Creates a placeholder for '=='" " T1" " eq" $ \ (eqAction: _) -> do
39
37
executeCodeAction eqAction
40
- , glodenTest " Creates a placeholder for '/='" " T1" " ne"
41
- $ \ (_: neAction: _) -> do
38
+ , goldenWithClass " Creates a placeholder for '/='" " T1" " ne" $ \ (_: neAction: _) -> do
42
39
executeCodeAction neAction
43
- , glodenTest " Creates a placeholder for 'fmap'" " T2" " fmap"
44
- $ \ (_: _: fmapAction: _) -> do
40
+ , goldenWithClass " Creates a placeholder for 'fmap'" " T2" " fmap" $ \ (_: _: fmapAction: _) -> do
45
41
executeCodeAction fmapAction
46
- , glodenTest " Creates a placeholder for multiple methods 1" " T3" " 1"
47
- $ \ (mmAction: _) -> do
42
+ , goldenWithClass " Creates a placeholder for multiple methods 1" " T3" " 1" $ \ (mmAction: _) -> do
48
43
executeCodeAction mmAction
49
- , glodenTest " Creates a placeholder for multiple methods 2" " T3" " 2"
50
- $ \ (_: mmAction: _) -> do
44
+ , goldenWithClass " Creates a placeholder for multiple methods 2" " T3" " 2" $ \ (_: mmAction: _) -> do
51
45
executeCodeAction mmAction
52
- , glodenTest " Creates a placeholder for a method starting with '_'" " T4" " "
53
- $ \ (_fAction: _) -> do
46
+ , goldenWithClass " Creates a placeholder for a method starting with '_'" " T4" " " $ \ (_fAction: _) -> do
54
47
executeCodeAction _fAction
55
48
]
56
49
@@ -59,20 +52,13 @@ _CACodeAction = prism' InR $ \case
59
52
InR action -> Just action
60
53
_ -> Nothing
61
54
62
- classPath :: FilePath
63
- classPath = " test" </> " testdata"
55
+ goldenWithClass :: TestName -> FilePath -> FilePath -> ([CodeAction ] -> Session () ) -> TestTree
56
+ goldenWithClass title path desc act =
57
+ goldenWithHaskellDoc classPlugin title testDataDir path (desc <.> " expected" ) " hs" $ \ doc -> do
58
+ _ <- waitForDiagnosticsFromSource doc " typecheck"
59
+ actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc
60
+ act actions
61
+ void $ skipManyTill anyMessage (getDocumentEdit doc)
64
62
65
- glodenTest :: String -> FilePath -> FilePath -> ([CodeAction ] -> Session () ) -> TestTree
66
- glodenTest name fp deco execute
67
- = goldenGitDiff name (classPath </> fpWithDeco <.> " expected" <.> " hs" )
68
- $ runSessionWithServer plugin classPath
69
- $ do
70
- doc <- openDoc (fp <.> " hs" ) " haskell"
71
- _ <- waitForDiagnosticsFromSource doc " typecheck"
72
- actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc
73
- execute actions
74
- BS. fromStrict . T. encodeUtf8 <$> skipManyTill anyMessage (getDocumentEdit doc)
75
- where
76
- fpWithDeco
77
- | deco == " " = fp
78
- | otherwise = fp <.> deco
63
+ testDataDir :: FilePath
64
+ testDataDir = " test" </> " testdata"
0 commit comments