33
44module Completer where
55
6- import Control.Lens ((^.) )
6+ import Control.Lens ((^.) , (^?) )
7+ import Control.Lens.Prism
78import qualified Data.ByteString as ByteString
9+ import Data.Maybe (mapMaybe )
810import qualified Data.Text as T
911import Distribution.PackageDescription.Parsec (parseGenericPackageDescriptionMaybe )
1012import Ide.Plugin.Cabal.Completion.Completer.FilePath
1113import Ide.Plugin.Cabal.Completion.Completer.Module
1214import Ide.Plugin.Cabal.Completion.Completer.Types (CompleterData (.. ))
1315import Ide.Plugin.Cabal.Completion.Completions
14- import Ide.Plugin.Cabal.Completion.Types
16+ import Ide.Plugin.Cabal.Completion.Types (CabalPrefixInfo (.. ),
17+ StanzaName )
1518import Ide.Plugin.Cabal.Parse (GenericPackageDescription )
1619import qualified Language.LSP.Protocol.Lens as L
1720import qualified Language.LSP.VFS as VFS
@@ -23,14 +26,32 @@ completerTests :: TestTree
2326completerTests =
2427 testGroup
2528 " Completer Tests"
26- [ fileCompleterTests,
29+ [ basicCompleterTests,
30+ fileCompleterTests,
2731 filePathCompletionContextTests,
2832 directoryCompleterTests,
2933 completionHelperTests,
3034 filePathExposedModulesTests,
3135 exposedModuleCompleterTests
3236 ]
3337
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+
3455fileCompleterTests :: TestTree
3556fileCompleterTests =
3657 testGroup
0 commit comments