validate dependabot configuration
[cabal.git] / cabal-install / tests / UnitTests / Distribution / Client / IndexUtils.hs
blobfbd5952019a382d223c92f422d439230aef878f0
1 module UnitTests.Distribution.Client.IndexUtils where
3 import Distribution.Client.IndexUtils
4 import qualified Distribution.Compat.NonEmptySet as NES
5 import Distribution.Simple.Utils (toUTF8LBS)
6 import Distribution.Types.Dependency
7 import Distribution.Types.LibraryName
8 import Distribution.Types.PackageName
9 import Distribution.Version
11 import Test.Tasty
12 import Test.Tasty.HUnit
14 tests :: [TestTree]
15 tests =
16 [ simpleVersionsParserTests
19 simpleVersionsParserTests :: TestTree
20 simpleVersionsParserTests =
21 testGroup
22 "Simple preferred-versions Parser Tests"
23 [ testCase "simple deprecation dependency" $ do
24 let prefs = parsePreferredVersionsWarnings (toUTF8LBS "binary < 0.9.0.0 || > 0.9.0.0")
25 prefs
26 @?= [ Right
27 ( Dependency
28 (mkPackageName "binary")
29 ( unionVersionRanges
30 (earlierVersion $ mkVersion [0, 9, 0, 0])
31 (laterVersion $ mkVersion [0, 9, 0, 0])
33 (NES.singleton LMainLibName)
36 , testCase "multiple deprecation dependency" $ do
37 let prefs = parsePreferredVersionsWarnings (toUTF8LBS "binary < 0.9.0.0 || > 0.9.0.0\ncontainers == 0.6.4.1")
38 prefs
39 @?= [ Right
40 ( Dependency
41 (mkPackageName "binary")
42 ( unionVersionRanges
43 (earlierVersion $ mkVersion [0, 9, 0, 0])
44 (laterVersion $ mkVersion [0, 9, 0, 0])
46 (NES.singleton LMainLibName)
48 , Right
49 ( Dependency
50 (mkPackageName "containers")
51 (thisVersion $ mkVersion [0, 6, 4, 1])
52 (NES.singleton LMainLibName)
55 , testCase "unparsable dependency" $ do
56 let prefs = parsePreferredVersionsWarnings (toUTF8LBS "binary 0.9.0.0 || > 0.9.0.0")
57 prefs
58 @?= [ Left binaryDepParseError
60 , testCase "partial parse" $ do
61 let prefs = parsePreferredVersionsWarnings (toUTF8LBS "binary 0.9.0.0 || > 0.9.0.0\ncontainers == 0.6.4.1")
62 prefs
63 @?= [ Left binaryDepParseError
64 , Right
65 ( Dependency
66 (mkPackageName "containers")
67 (thisVersion $ mkVersion [0, 6, 4, 1])
68 (NES.singleton LMainLibName)
72 where
73 binaryDepParseError =
74 PreferredVersionsParseError
75 { preferredVersionsParsecError =
76 mconcat
77 [ "\"<eitherParsec>\" (line 1, column 8):\n"
78 , "unexpected '0'\n"
79 , "expecting space, white space, opening paren, operator or end of input"
81 , preferredVersionsOriginalDependency = "binary 0.9.0.0 || > 0.9.0.0"