File: IndexUtils.hs

package info (click to toggle)
haskell-cabal-install 3.10.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 3,400 kB
  • sloc: haskell: 52,202; sh: 80; makefile: 9
file content (79 lines) | stat: -rw-r--r-- 2,939 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module UnitTests.Distribution.Client.IndexUtils where

import Distribution.Client.IndexUtils
import qualified Distribution.Compat.NonEmptySet as NES
import Distribution.Simple.Utils (toUTF8LBS)
import Distribution.Version
import Distribution.Types.Dependency
import Distribution.Types.PackageName
import Distribution.Types.LibraryName


import Test.Tasty
import Test.Tasty.HUnit

tests :: [TestTree]
tests =
    [ simpleVersionsParserTests
    ]

simpleVersionsParserTests :: TestTree
simpleVersionsParserTests = testGroup "Simple preferred-versions Parser Tests"
    [ testCase "simple deprecation dependency" $ do
        let prefs = parsePreferredVersionsWarnings (toUTF8LBS "binary < 0.9.0.0 || > 0.9.0.0")
        prefs @?=
            [ Right
                (Dependency
                    (mkPackageName "binary")
                    (unionVersionRanges
                        (earlierVersion $ mkVersion [0,9,0,0])
                        (laterVersion $ mkVersion [0,9,0,0])
                    )
                    (NES.singleton LMainLibName)
                )
            ]
    , testCase "multiple deprecation dependency" $ do
        let prefs = parsePreferredVersionsWarnings (toUTF8LBS "binary < 0.9.0.0 || > 0.9.0.0\ncontainers == 0.6.4.1")
        prefs @?=
            [ Right
                (Dependency
                    (mkPackageName "binary")
                    (unionVersionRanges
                        (earlierVersion $ mkVersion [0,9,0,0])
                        (laterVersion $ mkVersion [0,9,0,0])
                    )
                    (NES.singleton LMainLibName)
                )
            , Right
                (Dependency
                    (mkPackageName "containers")
                    (thisVersion $ mkVersion [0,6,4,1])
                    (NES.singleton LMainLibName)
                )
            ]
    , testCase "unparsable dependency" $ do
        let prefs = parsePreferredVersionsWarnings (toUTF8LBS "binary 0.9.0.0 || > 0.9.0.0")
        prefs @?=
            [ Left binaryDepParseError
            ]
    , testCase "partial parse" $ do
        let prefs = parsePreferredVersionsWarnings (toUTF8LBS "binary 0.9.0.0 || > 0.9.0.0\ncontainers == 0.6.4.1")
        prefs @?=
            [ Left binaryDepParseError
            , Right
                (Dependency
                    (mkPackageName "containers")
                    (thisVersion $ mkVersion [0,6,4,1])
                    (NES.singleton LMainLibName)
                )
            ]
    ]
    where
        binaryDepParseError = PreferredVersionsParseError
            { preferredVersionsParsecError = mconcat
                [ "\"<eitherParsec>\" (line 1, column 8):\n"
                , "unexpected '0'\n"
                , "expecting space, white space, opening paren, operator or end of input"
                ]
            , preferredVersionsOriginalDependency = "binary 0.9.0.0 || > 0.9.0.0"
            }