3
3
{-# LANGUAGE DisambiguateRecordFields #-}
4
4
{-# LANGUAGE NamedFieldPuns #-}
5
5
{-# LANGUAGE TypeOperators #-}
6
+ {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
6
7
module Main
7
8
( main
8
9
) where
@@ -13,6 +14,7 @@ import qualified Data.ByteString as BS
13
14
import Data.Either (isRight )
14
15
import qualified Data.Text as Text
15
16
import Ide.Plugin.Cabal
17
+ import Ide.Plugin.Cabal.Completions
16
18
import Ide.Plugin.Cabal.LicenseSuggest (licenseErrorSuggestion )
17
19
import qualified Ide.Plugin.Cabal.Parse as Lib
18
20
import qualified Language.LSP.Types.Lens as J
@@ -38,7 +40,8 @@ unitTests :: TestTree
38
40
unitTests =
39
41
testGroup " Unit Tests"
40
42
[ cabalParserUnitTests,
41
- codeActionUnitTests
43
+ codeActionUnitTests,
44
+ completionUnitTests
42
45
]
43
46
44
47
cabalParserUnitTests :: TestTree
@@ -66,6 +69,41 @@ codeActionUnitTests = testGroup "Code Action Tests"
66
69
@?= [(" MiT" ," MIT" ),(" MiT" ," MIT-0" )]
67
70
]
68
71
72
+ completionUnitTests :: TestTree
73
+ completionUnitTests = testGroup " Context Tests"
74
+ [
75
+ testCase " Empty File - Start" $ do
76
+ -- for a completely empty file, the context needs to
77
+ -- be toplevel without a specified keyword
78
+ getContext (Position 0 0 ) [" " ] @?= Just (TopLevel , None ),
79
+ testCase " Cabal version keyword - no value" $ do
80
+ -- on a file, where the "cabal-version:" keyword is already written
81
+ -- the context should still be toplevel but the keyword should be recognized
82
+ getContext (Position 0 15 ) [" cabal-version:" ] @?= Just (TopLevel , KeyWord " cabal-version:" ),
83
+ testCase " Cabal version keyword - cursor in keyword" $ do
84
+ -- on a file, where the "cabal-version:" keyword is already written
85
+ -- but the cursor is in the middle of the keyword, the keyword context
86
+ -- is cabal-version since after the keyword, the value needs to be inserted still
87
+ getContext (Position 0 5 ) [" cabal-version:" ] @?= Just (TopLevel , KeyWord " cabal-version:" ),
88
+ testCase " Cabal version keyword - no value, many spaces" $ do
89
+ -- on a file, where the "cabal-version:" keyword is already written
90
+ -- the context should still be toplevel but the keyword should be recognized
91
+ getContext (Position 0 45 ) [" cabal-version:" <> Text. replicate 50 " " ] @?= Just (TopLevel , KeyWord " cabal-version:" ),
92
+ testCase " Cabal version keyword - no value, many spaces" $ do
93
+ -- in the first line of the file, if the keyword
94
+ -- has not been written completely, the keyword context
95
+ -- should still be None
96
+ getContext (Position 0 5 ) [" cabal" ] @?= Just (TopLevel , None ),
97
+ testCase " Inside Stanza - no keyword" $ do
98
+ -- on a file, where the library stanza has been defined
99
+ -- but no keyword is defined afterwards, the stanza context should be recognized
100
+ getContext (Position 3 0 ) libraryStanza @?= Just (Stanza " library" , None ),
101
+ testCase " Inside Stanza - keyword, no value" $ do
102
+ -- on a file, where the library stanza and a keyword
103
+ -- has been defined, the keyword and stanza should be recognized
104
+ getContext (Position 4 21 ) libraryStanza @?= Just (Stanza " library" , KeyWord " build-depends:" )
105
+ ]
106
+
69
107
-- ------------------------------------------------------------------------
70
108
-- Integration Tests
71
109
-- ------------------------------------------------------------------------
@@ -180,3 +218,15 @@ runCabalSession subdir =
180
218
181
219
testDataDir :: FilePath
182
220
testDataDir = " test" </> " testdata"
221
+
222
+ -- ------------------------------------------------------------------------
223
+ -- Test Data
224
+ -- ------------------------------------------------------------------------
225
+ libraryStanza =
226
+ [
227
+ " cabal-version: 3.0" ,
228
+ " name: simple-cabal" ,
229
+ " library " ,
230
+ " " ,
231
+ " build-depends: "
232
+ ]
0 commit comments