1
+ {-# LANGUAGE CPP #-}
1
2
{-# OPTIONS_GHC -fno-warn-orphans
2
3
-fno-warn-incomplete-patterns
3
4
-fno-warn-deprecations
@@ -21,79 +22,89 @@ import Data.Maybe (isJust, fromJust)
21
22
import Data.List (sort , sortBy , nub )
22
23
import Data.Ord (comparing )
23
24
import Data.Function (on )
25
+ #if MIN_VERSION_base(4,6,0)
26
+ import Text.Read (readMaybe )
27
+ #endif
24
28
25
29
versionTests :: [TestTree ]
26
30
versionTests =
27
- zipWith (\ n p -> testProperty (" Range Property " ++ show n) p) [1 :: Int .. ]
28
- -- properties to validate the test framework
29
- [ property prop_nonNull
30
- , property prop_gen_intervals1
31
- , property prop_gen_intervals2
32
- -- , property prop_equivalentVersionRange --FIXME: runs out of test cases
33
- , property prop_intermediateVersion
34
-
35
31
-- test 'Version' type
36
- , property prop_VersionId
37
- , property prop_VersionId2
38
- , property prop_VersionEq
39
- , property prop_VersionEq2
40
- , property prop_VersionOrd
41
- , property prop_VersionOrd2
42
-
43
- -- the basic syntactic version range functions
44
- , property prop_anyVersion
45
- , property prop_noVersion
46
- , property prop_thisVersion
47
- , property prop_notThisVersion
48
- , property prop_laterVersion
49
- , property prop_orLaterVersion
50
- , property prop_earlierVersion
51
- , property prop_orEarlierVersion
52
- , property prop_unionVersionRanges
53
- , property prop_intersectVersionRanges
54
- , property prop_differenceVersionRanges
55
- , property prop_invertVersionRange
56
- , property prop_withinVersion
57
- , property prop_foldVersionRange
58
- , property prop_foldVersionRange'
59
-
60
- -- the semantic query functions
61
- -- , property prop_isAnyVersion1 --FIXME: runs out of test cases
62
- -- , property prop_isAnyVersion2 --FIXME: runs out of test cases
63
- -- , property prop_isNoVersion --FIXME: runs out of test cases
64
- -- , property prop_isSpecificVersion1 --FIXME: runs out of test cases
65
- -- , property prop_isSpecificVersion2 --FIXME: runs out of test cases
66
- , property prop_simplifyVersionRange1
67
- , property prop_simplifyVersionRange1'
68
- -- , property prop_simplifyVersionRange2 --FIXME: runs out of test cases
69
- -- , property prop_simplifyVersionRange2' --FIXME: runs out of test cases
70
- -- , property prop_simplifyVersionRange2'' --FIXME: actually wrong
71
-
72
- -- converting between version ranges and version intervals
73
- , property prop_to_intervals
74
- -- , property prop_to_intervals_canonical --FIXME: runs out of test cases
75
- -- , property prop_to_intervals_canonical' --FIXME: runs out of test cases
76
- , property prop_from_intervals
77
- , property prop_to_from_intervals
78
- , property prop_from_to_intervals
79
- , property prop_from_to_intervals'
80
-
81
- -- union and intersection of version intervals
82
- , property prop_unionVersionIntervals
83
- , property prop_unionVersionIntervals_idempotent
84
- , property prop_unionVersionIntervals_commutative
85
- , property prop_unionVersionIntervals_associative
86
- , property prop_intersectVersionIntervals
87
- , property prop_intersectVersionIntervals_idempotent
88
- , property prop_intersectVersionIntervals_commutative
89
- , property prop_intersectVersionIntervals_associative
90
- , property prop_union_intersect_distributive
91
- , property prop_intersect_union_distributive
92
-
93
- -- inversion of version intervals
94
- , property prop_invertVersionIntervals
95
- , property prop_invertVersionIntervalsTwice
96
- ]
32
+ [ tp " versionNumbers . mkVersion = id @[NonNegative Int]" prop_VersionId
33
+ , tp " versionNumbers . mkVersion = id @Base.Version" prop_VersionId2
34
+ , tp " (==) = (==) `on` versionNumbers" prop_VersionEq
35
+ , tp " (==) = (==) `on` mkVersion" prop_VersionEq2
36
+ , tp " compare = compare `on` versionNumbers" prop_VersionOrd
37
+ , tp " compare = compare `on` mkVersion" prop_VersionOrd2
38
+
39
+ , tp " readMaybe . show = Just" prop_ShowRead
40
+ , tp " read example" prop_ShowRead_example
41
+ ]
42
+
43
+ ++
44
+ zipWith (\ n p -> testProperty (" Range Property " ++ show n) p) [1 :: Int .. ]
45
+ -- properties to validate the test framework
46
+ [ property prop_nonNull
47
+ , property prop_gen_intervals1
48
+ , property prop_gen_intervals2
49
+ -- , property prop_equivalentVersionRange --FIXME: runs out of test cases
50
+ , property prop_intermediateVersion
51
+
52
+ , property prop_anyVersion
53
+ , property prop_noVersion
54
+ , property prop_thisVersion
55
+ , property prop_notThisVersion
56
+ , property prop_laterVersion
57
+ , property prop_orLaterVersion
58
+ , property prop_earlierVersion
59
+ , property prop_orEarlierVersion
60
+ , property prop_unionVersionRanges
61
+ , property prop_intersectVersionRanges
62
+ , property prop_differenceVersionRanges
63
+ , property prop_invertVersionRange
64
+ , property prop_withinVersion
65
+ , property prop_foldVersionRange
66
+ , property prop_foldVersionRange'
67
+
68
+ -- the semantic query functions
69
+ -- , property prop_isAnyVersion1 --FIXME: runs out of test cases
70
+ -- , property prop_isAnyVersion2 --FIXME: runs out of test cases
71
+ -- , property prop_isNoVersion --FIXME: runs out of test cases
72
+ -- , property prop_isSpecificVersion1 --FIXME: runs out of test cases
73
+ -- , property prop_isSpecificVersion2 --FIXME: runs out of test cases
74
+ , property prop_simplifyVersionRange1
75
+ , property prop_simplifyVersionRange1'
76
+ -- , property prop_simplifyVersionRange2 --FIXME: runs out of test cases
77
+ -- , property prop_simplifyVersionRange2' --FIXME: runs out of test cases
78
+ -- , property prop_simplifyVersionRange2'' --FIXME: actually wrong
79
+
80
+ -- converting between version ranges and version intervals
81
+ , property prop_to_intervals
82
+ -- , property prop_to_intervals_canonical --FIXME: runs out of test cases
83
+ -- , property prop_to_intervals_canonical' --FIXME: runs out of test cases
84
+ , property prop_from_intervals
85
+ , property prop_to_from_intervals
86
+ , property prop_from_to_intervals
87
+ , property prop_from_to_intervals'
88
+
89
+ -- union and intersection of version intervals
90
+ , property prop_unionVersionIntervals
91
+ , property prop_unionVersionIntervals_idempotent
92
+ , property prop_unionVersionIntervals_commutative
93
+ , property prop_unionVersionIntervals_associative
94
+ , property prop_intersectVersionIntervals
95
+ , property prop_intersectVersionIntervals_idempotent
96
+ , property prop_intersectVersionIntervals_commutative
97
+ , property prop_intersectVersionIntervals_associative
98
+ , property prop_union_intersect_distributive
99
+ , property prop_intersect_union_distributive
100
+
101
+ -- inversion of version intervals
102
+ , property prop_invertVersionIntervals
103
+ , property prop_invertVersionIntervalsTwice
104
+ ]
105
+ where
106
+ tp :: Testable p => String -> p -> TestTree
107
+ tp = testProperty
97
108
98
109
-- parseTests :: [TestTree]
99
110
-- parseTests =
@@ -204,6 +215,17 @@ prop_VersionOrd2 :: VersionArb -> VersionArb -> Bool
204
215
prop_VersionOrd2 (VersionArb v1) (VersionArb v2) =
205
216
(==) v1 v2 == ((==) `on` mkVersion) v1 v2
206
217
218
+ prop_ShowRead :: Version -> Property
219
+ #if MIN_VERSION_base(4,6,0)
220
+ prop_ShowRead v = Just v === readMaybe (show v)
221
+ #else
222
+ -- readMaybe is since base-4.6
223
+ prop_ShowRead v = v === read (show v)
224
+ #endif
225
+
226
+ prop_ShowRead_example :: Bool
227
+ prop_ShowRead_example = show (mkVersion [1 ,2 ,3 ]) == " mkVersion [1,2,3]"
228
+
207
229
---------------------------
208
230
-- VersionRange properties
209
231
--
0 commit comments