1 {-# LANGUAGE OverloadedStrings #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 module UnitTests
.Distribution
.Client
.DescribedInstances
where
6 import Distribution
.Client
.Compat
.Prelude
8 import Data
.List
((\\))
9 import Distribution
.Described
11 import Distribution
.Types
.PackageId
(PackageIdentifier
)
12 import Distribution
.Types
.PackageName
(PackageName
)
13 import Distribution
.Types
.VersionRange
(VersionRange
)
15 import Distribution
.Client
.BuildReports
.Types
(InstallOutcome
, Outcome
)
16 import Distribution
.Client
.Glob
(RootedGlob
)
17 import Distribution
.Client
.IndexUtils
.ActiveRepos
(ActiveRepoEntry
, ActiveRepos
, CombineStrategy
)
18 import Distribution
.Client
.IndexUtils
.IndexState
(RepoIndexState
, TotalIndexState
)
19 import Distribution
.Client
.IndexUtils
.Timestamp
(Timestamp
)
20 import Distribution
.Client
.Targets
(UserConstraint
)
21 import Distribution
.Client
.Types
(RepoName
)
22 import Distribution
.Client
.Types
.AllowNewer
(RelaxDepSubject
, RelaxDeps
, RelaxedDep
)
24 -------------------------------------------------------------------------------
26 -------------------------------------------------------------------------------
28 instance Described InstallOutcome
where
32 , "DependencyFailed" <> RESpaces1
<> describe
(Proxy
:: Proxy PackageIdentifier
)
42 instance Described Outcome
where
45 [ fromString
(prettyShow o
)
46 | o
<- [minBound .. maxBound :: Outcome
]
49 -------------------------------------------------------------------------------
51 -------------------------------------------------------------------------------
53 -- This instance is incorrect as it may generate C:\dir\{foo,bar}
54 instance Described RootedGlob
where
55 describe _
= REUnion
[root
, relative
, homedir
]
60 , reChars
(['a
' .. 'z
'] ++ ['A
' .. 'Z
']) <> ":" <> reChars
"/\\"
63 homedir
= "~/" <> REOpt pieces
66 pieces
:: GrammarRegex void
67 pieces
= REMunch1 sep piece
<> REOpt
"/"
69 piece
:: GrammarRegex void
77 , "{" <> REMunch1
"," (REVar Nothing
) <> "}"
80 sep
:: GrammarRegex void
83 wildcard
:: GrammarRegex void
86 normal
= reChars
$ ['\0' .. '\128'] \\ "*{},/\\"
87 escape
= fromString
"\\" <> reChars
"*{},"
89 -------------------------------------------------------------------------------
91 -------------------------------------------------------------------------------
93 instance Described RelaxedDep
where
95 REOpt
(describeRelaxDepScope
<> ":" <> REOpt
("^"))
96 <> describe
(Proxy
:: Proxy RelaxDepSubject
)
98 describeRelaxDepScope
=
102 , RENamed
"package-name" (describe
(Proxy
:: Proxy PackageName
))
103 , RENamed
"package-id" (describe
(Proxy
:: Proxy PackageIdentifier
))
106 instance Described RelaxDepSubject
where
111 , RENamed
"package-name" (describe
(Proxy
:: Proxy PackageName
))
114 instance Described RelaxDeps
where
120 , RECommaNonEmpty
(describe
(Proxy
:: Proxy RelaxedDep
))
123 -------------------------------------------------------------------------------
125 -------------------------------------------------------------------------------
127 instance Described ActiveRepos
where
131 , RECommaNonEmpty
(describe
(Proxy
:: Proxy ActiveRepoEntry
))
134 instance Described ActiveRepoEntry
where
137 [ ":rest" <> strategy
138 , REOpt
":repo:" <> describe
(Proxy
:: Proxy RepoName
) <> strategy
141 strategy
= REOpt
$ ":" <> describe
(Proxy
:: Proxy CombineStrategy
)
143 instance Described CombineStrategy
where
151 -------------------------------------------------------------------------------
153 -------------------------------------------------------------------------------
155 instance Described UserConstraint
where
158 [ describeConstraintScope
159 , describeConstraintProperty
162 describeConstraintScope
:: GrammarRegex void
163 describeConstraintScope
=
165 [ "any." <> describePN
166 , "setup." <> describePN
168 , describePN
<> ":setup." <> describePN
171 describeConstraintProperty
:: GrammarRegex void
172 describeConstraintProperty
=
174 [ RESpaces
<> RENamed
"version-range" (describe
(Proxy
:: Proxy VersionRange
))
175 , RESpaces1
<> describeConstraintProperty
'
178 describeConstraintProperty
' :: GrammarRegex void
179 describeConstraintProperty
' =
185 , describeFlagAssignmentNonEmpty
188 describePN
:: GrammarRegex void
189 describePN
= RENamed
"package-name" (describe
(Proxy
:: Proxy PackageName
))
191 -------------------------------------------------------------------------------
193 -------------------------------------------------------------------------------
195 instance Described TotalIndexState
where
199 [ describe
(Proxy
:: Proxy RepoName
) <> RESpaces1
<> ris
203 ris
= describe
(Proxy
:: Proxy RepoIndexState
)
205 instance Described RepoName
where
206 describe _
= lead
<> rest
208 lead
= RECharSet
$ csAlpha
<> "_-."
209 rest
= reMunchCS
$ csAlphaNum
<> "_-."
211 instance Described RepoIndexState
where
215 , RENamed
"timestamp" (describe
(Proxy
:: Proxy Timestamp
))
218 instance Described Timestamp
where
225 posix
= reChar
'@' <> reMunch1CS
"0123456789"
226 utc
= RENamed
"date" date
<> reChar
'T
' <> RENamed
"time" time
<> reChar
'Z
'
231 [ leapYear
<> reChar
'-' <> leapMD
232 , commonYear
<> reChar
'-' <> commonMD
236 -- \* divisible by 400
237 -- \* not divisible by 100 and divisible by 4
241 , digit
<> digit
<> div4not0
244 -- common year: either
245 -- \* not divisible by 400 but divisible by 100
246 -- \* not divisible by 4
250 , digit
<> digit
<> notDiv4
255 [ "0" <> reChars
"048"
256 , "1" <> reChars
"26"
257 , "2" <> reChars
"048"
258 , "3" <> reChars
"26"
259 , "4" <> reChars
"048"
260 , "5" <> reChars
"26"
261 , "6" <> reChars
"048"
262 , "7" <> reChars
"26"
263 , "8" <> reChars
"048"
264 , "9" <> reChars
"26"
269 [ "0" <> reChars
"48" -- no zero
270 , "1" <> reChars
"26"
271 , "2" <> reChars
"048"
272 , "3" <> reChars
"26"
273 , "4" <> reChars
"048"
274 , "5" <> reChars
"26"
275 , "6" <> reChars
"048"
276 , "7" <> reChars
"26"
277 , "8" <> reChars
"048"
278 , "9" <> reChars
"26"
283 [ "0" <> reChars
"1235679"
284 , "1" <> reChars
"01345789"
285 , "2" <> reChars
"1235679"
286 , "3" <> reChars
"01345789"
287 , "4" <> reChars
"1235679"
288 , "5" <> reChars
"01345789"
289 , "6" <> reChars
"1235679"
290 , "7" <> reChars
"01345789"
291 , "8" <> reChars
"1235679"
292 , "9" <> reChars
"01345789"
297 [jan
, fe
', mar
, apr
, may
, jun
, jul
, aug
, sep
, oct
, nov
, dec
]
301 [jan
, feb
, mar
, apr
, may
, jun
, jul
, aug
, sep
, oct
, nov
, dec
]
319 ["0" <> digit1
, "1" <> digit
, "2" <> reChars
"012345678"]
322 ["0" <> digit1
, "1" <> digit
, "2" <> digit
]
325 ["0" <> digit1
, "1" <> digit
, "2" <> digit
, "30"]
328 ["0" <> digit1
, "1" <> digit
, "2" <> digit
, "30", "31"]
330 time
= ho
<> reChar
':' <> minSec
<> reChar
':' <> minSec
337 , "2" <> reChars
"0123"
341 minSec
= reChars
"012345" <> digit
343 digit
= reChars
"0123456789"
344 digit1
= reChars
"123456789"