3
3
4
4
module Completer where
5
5
6
- import Control.Lens ((^.) )
6
+ import Control.Lens ((^.) , (^?) )
7
+ import Control.Lens.Prism
7
8
import qualified Data.ByteString as ByteString
9
+ import Data.Maybe (mapMaybe )
8
10
import qualified Data.Text as T
9
11
import Distribution.PackageDescription.Parsec (parseGenericPackageDescriptionMaybe )
10
12
import Ide.Plugin.Cabal.Completion.Completer.FilePath
11
13
import Ide.Plugin.Cabal.Completion.Completer.Module
12
14
import Ide.Plugin.Cabal.Completion.Completer.Types (CompleterData (.. ))
13
15
import Ide.Plugin.Cabal.Completion.Completions
14
- import Ide.Plugin.Cabal.Completion.Types
16
+ import Ide.Plugin.Cabal.Completion.Types (CabalPrefixInfo (.. ),
17
+ StanzaName )
15
18
import Ide.Plugin.Cabal.Parse (GenericPackageDescription )
16
19
import qualified Language.LSP.Protocol.Lens as L
17
20
import qualified Language.LSP.VFS as VFS
@@ -23,14 +26,32 @@ completerTests :: TestTree
23
26
completerTests =
24
27
testGroup
25
28
" Completer Tests"
26
- [ fileCompleterTests,
29
+ [ basicCompleterTests,
30
+ fileCompleterTests,
27
31
filePathCompletionContextTests,
28
32
directoryCompleterTests,
29
33
completionHelperTests,
30
34
filePathExposedModulesTests,
31
35
exposedModuleCompleterTests
32
36
]
33
37
38
+ basicCompleterTests :: TestTree
39
+ basicCompleterTests =
40
+ testGroup
41
+ " Basic Completer Tests"
42
+ [ runCabalTestCaseSession " In stanza context - stanza should not be suggested" " " $ do
43
+ doc <- openDoc " completer.cabal" " cabal"
44
+ compls <- getCompletions doc (Position 11 7 )
45
+ let complTexts = mapMaybe (^? L. textEdit . _Just . _L . L. newText) compls
46
+ liftIO $ assertBool " does not suggest library" $ " library" `notElem` complTexts
47
+ liftIO $ assertBool " suggests library keyword" $ " extra-libraries:" `elem` complTexts
48
+ , runCabalTestCaseSession " In top level context - stanza should be suggested" " " $ do
49
+ doc <- openDoc " completer.cabal" " cabal"
50
+ compls <- getCompletions doc (Position 8 2 )
51
+ let complTexts = mapMaybe (^? L. textEdit . _Just . _L . L. newText) compls
52
+ liftIO $ assertBool " suggests benchmark" $ " benchmark" `elem` complTexts
53
+ ]
54
+
34
55
fileCompleterTests :: TestTree
35
56
fileCompleterTests =
36
57
testGroup
0 commit comments