Merge pull request #10654 from haskell/wip/T10652
[cabal.git] / Cabal-tests / tests / UnitTests / Distribution / CabalSpecVersion.hs
blob52fb5c7a689e3a60c844f4723288e67ed205f5d3
1 {-# LANGUAGE CPP #-}
2 {-# OPTIONS_GHC -fno-warn-deprecations #-}
3 module UnitTests.Distribution.CabalSpecVersion (tests) where
5 import Distribution.Compat.Prelude.Internal
6 import Prelude ()
8 import Distribution.CabalSpecVersion
9 import Distribution.FieldGrammar.Newtypes (SpecVersion (..))
10 import Distribution.Parsec (eitherParsec)
11 import Distribution.Pretty (prettyShow)
13 import Test.Tasty
14 import Test.Tasty.QuickCheck
16 -- instances
17 import Test.QuickCheck.Instances.Cabal ()
19 tests :: TestTree
20 tests = testGroup "Distribution.CabalSpecVersion"
21 [ testProperty "roundtrip" propRoundtrip
22 , testProperty "fromVersionDigits . toVersionDigits = Just" propViaVersionDigits
24 where
25 -- we test roundtrip here,
26 -- because Described instance is a small simplification.
27 propRoundtrip :: SpecVersion -> Property
28 propRoundtrip x = counterexample (show (res, str)) $ case res of
29 Right y -> x == y
30 Left _ -> False
31 where
32 str = prettyShow x
33 res = eitherParsec str
35 propViaVersionDigits :: CabalSpecVersion -> Property
36 propViaVersionDigits csv =
37 counterexample (show digits) $
38 lhs === rhs
39 where
40 digits = cabalSpecToVersionDigits csv
41 lhs = cabalSpecFromVersionDigits digits
42 rhs = Just csv