@@ -7,15 +7,15 @@ import Data.Function ((&))
7
7
import Data.Map.Strict qualified as Map
8
8
import Data.SemVer (version )
9
9
import Data.SemVer.Internal (Identifier (.. ))
10
- import Data.Text (Text )
10
+ import Data.Text (Text , empty )
11
11
import Data.Text.IO qualified as TIO
12
12
import DepTypes (DepType (GoType ), Dependency (.. ), VerConstraint (CEq ))
13
13
import Effect.Grapher (direct , evalGrapher )
14
14
import Graphing (Graphing (.. ))
15
15
import Strategy.Go.Gomod (Gomod (.. ), PackageVersion (.. ), Require (.. ), buildGraph , gomodParser )
16
16
import Strategy.Go.Types (graphingGolang )
17
17
import Test.Hspec (Spec , describe , it , runIO , shouldBe )
18
- import Test.Hspec.Megaparsec (shouldParse )
18
+ import Test.Hspec.Megaparsec (shouldFailOn , shouldParse )
19
19
import Text.Megaparsec (runParser )
20
20
import Text.RawString.QQ (r )
21
21
@@ -57,6 +57,16 @@ trivialGraph = run . evalGrapher $ do
57
57
direct $ dep " github.com/pkg/overridden" " overridden"
58
58
direct $ dep " github.com/pkg/three/v3" " v3.0.0"
59
59
60
+ emptyGomod :: Gomod
61
+ emptyGomod =
62
+ Gomod
63
+ { modName = " "
64
+ , modRequires = []
65
+ , modReplaces = Map. empty
66
+ , modLocalReplaces = Map. empty
67
+ , modExcludes = []
68
+ }
69
+
60
70
localReplaceGomod :: Gomod
61
71
localReplaceGomod =
62
72
Gomod
@@ -193,6 +203,9 @@ spec_parse = do
193
203
it " parses a trivial example" $ do
194
204
runParser gomodParser " " trivialInput `shouldParse` trivialGomod
195
205
206
+ it " parses empty go.mod" $ do
207
+ runParser gomodParser " " Data.Text. empty `shouldParse` emptyGomod
208
+
196
209
it " parses each edge case" $ do
197
210
runParser gomodParser " " edgecaseInput `shouldParse` edgeCaseGomod
198
211
@@ -211,6 +224,9 @@ spec_parse = do
211
224
runParser gomodParser " " goModWithRetractComment3 `shouldParse` gomodWithRetract
212
225
runParser gomodParser " " goModWithRetractComment4 `shouldParse` gomodWithRetract
213
226
227
+ it " fails to parse invalid go.mod" $ do
228
+ runParser gomodParser " " `shouldFailOn` " invalid input"
229
+
214
230
gomodWithRetract :: Gomod
215
231
gomodWithRetract =
216
232
Gomod
0 commit comments