packages feed

versions 3.3.0 → 3.3.1

raw patch · 3 files changed

+45/−7 lines, 3 files

Files

Data/Versions.hs view
@@ -41,7 +41,7 @@     , SemVer(..)     , Version(..)     , Mess(..)-    , VUnit, digits, str+    , VUnit(..), digits, str     , VChunk     , VSep(..)       -- * Parsers@@ -314,6 +314,14 @@ -- by periods in the source. data VUnit = Digits Word | Str T.Text deriving (Eq,Show,Read,Ord,Generic,NFData,Hashable) +instance Monoid VUnit where+  mempty = Str ""++  Digits n `mappend` Digits m = Digits $ n + m+  Str t    `mappend` Str s    = Str $ t <> s+  Digits n `mappend` _        = Digits n+  _        `mappend` Digits n = Digits n+ -- | Smart constructor for a `VUnit` made of digits. digits :: Word -> VUnit digits = Digits@@ -346,6 +354,11 @@ data Version = Version { _vEpoch  :: Maybe Word                        , _vChunks :: [VChunk]                        , _vRel    :: [VChunk] } deriving (Eq,Show,Generic,NFData,Hashable)++instance Monoid Version where+  mempty = Version Nothing [] []++  Version e c r `mappend` Version e' c' r' = Version ((+) <$> e <*> e') (c ++ c') (r ++ r')  -- | Set a `Version`'s epoch to `Nothing`. wipe :: Version -> Version
test/Test.hs view
@@ -4,7 +4,8 @@  import Data.Char import Data.Either (isRight, isLeft)-import Data.Maybe (fromJust)+import Data.Foldable (fold)+import Data.List (groupBy) import Data.Monoid ((<>)) import Data.Text (Text, unpack, pack) import Data.Versions@@ -19,21 +20,40 @@ ---  instance Arbitrary SemVer where-  arbitrary = SemVer <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary+  arbitrary = SemVer <$> arbitrary <*> arbitrary <*> arbitrary <*> chunks <*> chunks +-- | Sane generation of VChunks.+chunks :: Gen [[VUnit]]+chunks = resize 10 . listOf1 . fmap simplify . resize 10 $ listOf1 arbitrary++simplify :: [VUnit] -> [VUnit]+simplify = map fold . groupBy f+  where f (Digits _) (Digits _) = True+        f (Str _) (Str _) = True+        f _ _ = False+ instance EqProp SemVer where   a =-= b = eq a b  instance Arbitrary VUnit where-  arbitrary = frequency [ (1, digits <$> arbitrary) , (1, s) ]-    where s = fromJust . str . pack . map unletter <$> arbitrary+  arbitrary = frequency [ (1, Digits . (+ 1) <$> arbitrary) , (1, s) ]+    where s = Str . pack . map unletter <$> resize 10 (listOf1 arbitrary) +instance EqProp VUnit where+  a =-= b = eq a b+ -- | An ASCII letter. newtype Letter = Letter { unletter :: Char }  instance Arbitrary Letter where   arbitrary = Letter . chr <$> choose (97, 122) +instance Arbitrary Version where+  arbitrary = Version <$> arbitrary <*> chunks <*> chunks++instance EqProp Version where+  a =-= b = eq a b+ -- | These don't need to parse as a SemVer. goodVers :: [Text] goodVers = [ "1", "1.2", "1.0rc0", "1.0rc1", "1.1rc1", "1.58.0-3",  "44.0.2403.157-1"@@ -82,6 +102,11 @@     [ testGroup "SemVer - Monoid" $       map (\(name, test) -> testProperty name test) . unbatch $ monoid (SemVer 1 2 3 [] [])     , testProperty "SemVer - Arbitrary" $ \a -> isRight . fmap (== a) $ semver (prettySemVer a)+    , testProperty "Version - Arbitrary" $ \a -> isRight . fmap (== a) $ version (prettyVer a)+    -- , testGroup "Version - Monoid" $+    --   map (\(name, test) -> testProperty name test) . unbatch $ monoid (Version (Just 1) [[digits 2], [digits 3]])+    , testGroup "VUnit - Monoid" $+      map (\(name, test) -> testProperty name test) . unbatch $ monoid (Digits 0)     ]   , testGroup "Unit Tests"     [ testGroup "(Ideal) Semantic Versioning"
versions.cabal view
@@ -1,9 +1,9 @@--- This file has been generated from package.yaml by hpack version 0.17.0.+-- This file has been generated from package.yaml by hpack version 0.17.1. -- -- see: https://github.com/sol/hpack  name:           versions-version:        3.3.0+version:        3.3.1 synopsis:       Types and parsers for software version numbers. description:    A library for parsing and comparing software version numbers.                 We like to give version numbers to our software in a myriad of