siren-json 0.1.2.0 → 0.1.3.0
raw patch · 11 files changed
+11/−364 lines, 11 filesdep +network-arbitraryPVP ok
version bump matches the API change (PVP)
Dependencies added: network-arbitrary
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- siren-json.cabal +2/−7
- test/Data/SirenJSON/Arbitrary.hs +3/−3
- test/External/Network/HTTP/Media/MediaType/Arbitrary.hs +0/−58
- test/External/Network/HTTP/Media/MediaType/ArbitrarySpec.hs +0/−28
- test/External/Network/HTTP/Media/MediaType/JSONSpec.hs +1/−1
- test/External/Network/HTTP/Types/Method/Arbitrary.hs +0/−26
- test/External/Network/HTTP/Types/Method/ArbitrarySpec.hs +0/−24
- test/External/Network/HTTP/Types/Method/JSONSpec.hs +1/−1
- test/External/Network/URI/Arbitrary.hs +0/−191
- test/External/Network/URI/ArbitrarySpec.hs +0/−25
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for siren-json +## 0.1.3.0 -- 2018-01-06++* Externalize network-arbitrary dependency+ ## 0.1.2.0 -- 2017-12-24 * Bump dependence on http-media
siren-json.cabal view
@@ -1,5 +1,5 @@ name: siren-json-version: 0.1.2.0+version: 0.1.3.0 synopsis: Siren Tools for Haskell description: @@ -76,16 +76,10 @@ , Data.SirenJSON.Arbitrary , Data.SirenJSON.Norm , Data.SirenJSONSpec- , External.Network.HTTP.Media.MediaType.Arbitrary- , External.Network.HTTP.Media.MediaType.ArbitrarySpec , External.Network.HTTP.Media.MediaType.JSON , External.Network.HTTP.Media.MediaType.JSONSpec- , External.Network.HTTP.Types.Method.Arbitrary- , External.Network.HTTP.Types.Method.ArbitrarySpec , External.Network.HTTP.Types.Method.JSON , External.Network.HTTP.Types.Method.JSONSpec- , External.Network.URI.Arbitrary- , External.Network.URI.ArbitrarySpec build-tool-depends: hspec-discover:hspec-discover == 2.4.*@@ -99,6 +93,7 @@ , hspec == 2.4.* , http-media >= 0.6 && < 0.8 , http-types == 0.9.*+ , network-arbitrary == 0.2.* , network-uri == 2.6.* , network-uri-json == 0.1.* , QuickCheck >= 2.9 && < 2.11
test/Data/SirenJSON/Arbitrary.hs view
@@ -14,13 +14,13 @@ import Control.Applicative ((<$>), (<*>)) import Data.Maybe (mapMaybe)+import Network.HTTP.Media.MediaType.Arbitrary ()+import Network.HTTP.Types.Method.Arbitrary ()+import Network.URI.Arbitrary () import Test.QuickCheck (Arbitrary (arbitrary, shrink), elements, oneof, scale) import Test.QuickCheck.Instances () import Data.SirenJSON-import External.Network.HTTP.Media.MediaType.Arbitrary ()-import External.Network.HTTP.Types.Method.Arbitrary ()-import External.Network.URI.Arbitrary () instance Arbitrary Entity where arbitrary = Entity <$> arbitrary
− test/External/Network/HTTP/Media/MediaType/Arbitrary.hs
@@ -1,58 +0,0 @@-{-# OPTIONS_GHC -fno-warn-orphans #-}--{-|-Module : External.Network.HTTP.Media.MediaType.Arbitrary-Description : Arbitrary Instances for Network.HTTP.Media.MediaType-Copyright : (c) Alex Brandt, 2017-License : MIT--Arbitrary instances for "Network.HTTP.Media.MediaType".--}-module External.Network.HTTP.Media.MediaType.Arbitrary () where--import Prelude hiding (concat)--import Control.Applicative ((<*>))-import Control.Monad (replicateM)-import Data.ByteString (append, concat, ByteString)-import Data.ByteString.Char8 (singleton)-import Data.Functor ((<$>))-import Network.HTTP.Media.MediaType ((/:), (//), MediaType)-import Test.QuickCheck (Arbitrary (arbitrary), choose, elements, Gen, listOf, oneof, sized)---------- Note: parameter---paramter values are supposed to be unrestricted but due to--- the way that quickcheck validates values it's best if these are--- printable. Until we can use the new instances in quickcheck-2.10.*, we--- shall simply use restrictedName for the values as well.-instance Arbitrary MediaType where- arbitrary =- do n <- (//) <$> restrictedName <*> restrictedName- ps <- listOf $ (,) <$> restrictedName <*> restrictedName -- see parameter note above- return $ foldl (/:) n ps---- * RFC 6838 Generators--restrictedName :: Gen ByteString-restrictedName = sized $ \ s ->- do n <- choose (0, min 126 s)- rs <- concat <$> replicateM n restrictedNameChar- (`append` rs) <$> restrictedNameFirst--restrictedNameFirst :: Gen ByteString-restrictedNameFirst = singleton <$> oneof [alpha, digit]--restrictedNameChar :: Gen ByteString-restrictedNameChar = singleton <$> oneof [ alpha- , digit- , elements ['!', '#', '$', '&', '-', '^', '_', '.', '+']- ]---- * RFC 2234 Generators--alpha :: Gen Char-alpha = elements $ ['a'..'z'] ++ ['A'..'Z']--digit :: Gen Char-digit = elements ['0'..'9']
− test/External/Network/HTTP/Media/MediaType/ArbitrarySpec.hs
@@ -1,28 +0,0 @@-{-|-Module : External.Network.HTTP.Media.MediaType.ArbitrarySpec-Description : Tests for External.Network.HTTP.Media.MediaType.Arbitrary-Copyright : (c) Alex Brandt, 2017-License : MIT--Tests for "External.Network.HTTP.Media.MediaType.Arbitrary".--}-module External.Network.HTTP.Media.MediaType.ArbitrarySpec (main, spec) where--import Prelude hiding (null)--import Data.ByteString (null)-import Data.CaseInsensitive (original)-import Network.HTTP.Media.MediaType (mainType, subType)-import Test.Hspec (describe, hspec, Spec)-import Test.Hspec.QuickCheck (prop)--import External.Network.HTTP.Media.MediaType.Arbitrary ()--main :: IO ()-main = hspec spec--spec :: Spec-spec =- describe "properties" $- do prop "not . null . mainType" $ not . null . original . mainType- prop "not . null . subType" $ not . null . original . subType
test/External/Network/HTTP/Media/MediaType/JSONSpec.hs view
@@ -10,12 +10,12 @@ import Data.Aeson (decode, encode) import Data.Maybe (fromJust)+import Network.HTTP.Media.MediaType.Arbitrary () import Network.HTTP.Media.MediaType (MediaType) import Test.Hspec (describe, hspec, Spec) import Test.Hspec.QuickCheck (prop) import Test.Invariant ((<=>)) -import External.Network.HTTP.Media.MediaType.Arbitrary () import External.Network.HTTP.Media.MediaType.JSON () main :: IO ()
− test/External/Network/HTTP/Types/Method/Arbitrary.hs
@@ -1,26 +0,0 @@-{-# OPTIONS_GHC -fno-warn-orphans #-}--{-|-Module : External.Network.HTTP.Types.Method.Arbitrary-Description : Arbitrary Instances for Network.HTTP.Types.Method-Copyright : (c) Alex Brandt, 2017-License : MIT--Arbitrary instances for "Network.HTTP.Types.Method".--}-module External.Network.HTTP.Types.Method.Arbitrary () where--import Network.HTTP.Types.Method (StdMethod (..))-import Test.QuickCheck (Arbitrary (arbitrary), elements)--instance Arbitrary StdMethod where- arbitrary = elements [ GET- , POST- , HEAD- , PUT- , DELETE- , TRACE- , CONNECT- , OPTIONS- , PATCH- ]
− test/External/Network/HTTP/Types/Method/ArbitrarySpec.hs
@@ -1,24 +0,0 @@-{-|-Module : External.Network.HTTP.Types.Method.ArbitrarySpec-Description : Tests for External.Network.HTTP.Types.Method.Arbitrary-Copyright : (c) Alex Brandt, 2017-License : MIT--Tests for "External.Network.HTTP.Types.Method.Arbitrary".--}-module External.Network.HTTP.Types.Method.ArbitrarySpec (main, spec) where--import Network.HTTP.Types.Method (parseMethod, renderStdMethod)-import Test.Hspec (describe, hspec, Spec)-import Test.Hspec.QuickCheck (prop)-import Test.Invariant ((<=>))--import External.Network.HTTP.Types.Method.Arbitrary ()--main :: IO ()-main = hspec spec--spec :: Spec-spec =- describe "properties" $- prop "parseMethod . renderStdMethod <=> Right" $ parseMethod . renderStdMethod <=> Right
test/External/Network/HTTP/Types/Method/JSONSpec.hs view
@@ -10,12 +10,12 @@ import Data.Aeson (decode, encode) import Data.Maybe (fromJust)+import Network.HTTP.Types.Method.Arbitrary () import Network.HTTP.Types.Method (StdMethod) import Test.Hspec (describe, hspec, Spec) import Test.Hspec.QuickCheck (prop) import Test.Invariant ((<=>)) -import External.Network.HTTP.Types.Method.Arbitrary () import External.Network.HTTP.Types.Method.JSON () main :: IO ()
− test/External/Network/URI/Arbitrary.hs
@@ -1,191 +0,0 @@-{-# LANGUAGE RecordWildCards #-}--{-# OPTIONS_GHC -fno-warn-orphans #-}--{-|-Module : External.Network.URI.Arbitrary-Description : Arbitrary Instances for Network.URI-Copyright : (c) Alex Brandt, 2017-License : MIT--Arbitrary instances for "Network.URI".--}-module External.Network.URI.Arbitrary () where--import Control.Applicative ((<$>), (<*>))-import Control.Monad (replicateM)-import Data.List (intercalate)-import Network.URI (URI (..), URIAuth (..))-import Test.QuickCheck (Arbitrary (arbitrary, shrink), choose, elements, Gen, listOf, listOf1, oneof, suchThat)--instance Arbitrary URI where- arbitrary =- do uriScheme <- scheme- uriAuthority <- arbitrary :: Gen (Maybe URIAuth)- uriPath <- path (null uriScheme) $ maybe True emptyAuthority uriAuthority- uriQuery <- oneof [query, return ""]- uriFragment <- oneof [fragment, return ""]-- return URI {..}- where emptyAuthority URIAuth{..} = all null [uriUserInfo, uriRegName, uriPort]-- shrink URI{..} = [ URI uriScheme' uriAuthority' uriPath' uriQuery' uriFragment' | (uriScheme', uriAuthority', uriPath', uriQuery', uriFragment') <- shrink (uriScheme, uriAuthority, uriPath, uriQuery, uriFragment) ]--instance Arbitrary URIAuth where- arbitrary = URIAuth <$> userinfo- <*> host `suchThat` (not . null)- <*> port-- shrink URIAuth{..} = [ URIAuth uriUserInfo' uriRegName' uriPort' | (uriUserInfo', uriRegName', uriPort') <- shrink (uriUserInfo, uriRegName, uriPort) ]---- * RFC 3986 Generators------ Some generators are handled by the 'Arbitrary' instances above, and others--- are folded into symbols that are preceeded or followed by identifying--- tokens.--scheme :: Gen String-scheme =- do a <- alpha- r <- listOf $ oneof [alpha, digit, elements ['+', '-', '.']]- return $ a : (r ++ ":")--userinfo :: Gen String-userinfo =- do u <- concat <$> userinfo'- if null u- then return ""- else return $ u ++ "@"- where userinfo' = listOf $ oneof [ replicateM 1 $ oneof [unreserved, subDelims, return ':']- , percentEncoded- ]--host :: Gen String-host = oneof [ ipLiteral- , ipv4Address- , regName- ]--port :: Gen String-port =- do p <- listOf digit- if null p- then return ""- else return $ ':':p--ipLiteral :: Gen String-ipLiteral =- do x <- oneof [ ipv6Address- --, ipvFuture- ]- return $ "[" ++ x ++ "]"--{- TODO Check that "Network.URI" implements this correctly.-ipvFuture :: Gen String-ipvFuture =- do h <- hexdig- o <- oneof [ unreserved, subDelims, return ':' ]- return ['v', h, '.', o]--}--ipv6Address :: Gen String-ipv6Address = concat <$> oneof [ sequence [b 6, ls32]- , sequence [return "::", b 5, ls32]- , sequence [h16, return "::", b 4, ls32]- , sequence [b 1, h16, return "::", b 3, ls32]- , sequence [b 2, h16, return "::", b 2, ls32]- , sequence [b 3, h16, return "::", b 1, ls32]- , sequence [b 4, h16, return "::", ls32]- , sequence [b 5, h16, return "::", h16]- , sequence [b 6, h16, return "::"]- ]- where b n = fmap concat $ replicateM n $ fmap (++ ":") h16 :: Gen String--h16 :: Gen String-h16 = replicateM 4 hexdig--ls32 :: Gen String-ls32 = oneof [ intercalate ":" <$> replicateM 2 h16- , ipv4Address- ]--ipv4Address :: Gen String-ipv4Address = intercalate "." <$> replicateM 4 decOctet--decOctet :: Gen String-decOctet = (show :: Int -> String) <$> choose (0, 255)--regName :: Gen String-regName = fmap concat $ listOf $ oneof [ replicateM 1 unreserved- , percentEncoded- , replicateM 1 subDelims- ]--path :: Bool -> Bool -> Gen String-path emptyScheme emptyURIAuth = if emptyURIAuth- then oneof [ pathAbsolute- , if emptyScheme then pathNoScheme else pathRootless- , return ""- ]- else pathAbEmpty--pathAbEmpty :: Gen String-pathAbEmpty = concat <$> listOf ((('/':) . concat) <$> listOf pchar)--pathAbsolute :: Gen String-pathAbsolute = ('/':) <$> oneof [return "", pathRootless]--pathNoScheme :: Gen String-pathNoScheme = concat <$> sequence [segment1nc, pathAbEmpty]--pathRootless :: Gen String-pathRootless = concat <$> sequence [ concat <$> listOf1 pchar- , pathAbEmpty- ]--segment1nc :: Gen String-segment1nc = oneof [ replicateM 1 unreserved- , percentEncoded- , replicateM 1 subDelims- , replicateM 1 $ return '@'- ] --pchar :: Gen String-pchar = oneof [ replicateM 1 unreserved- , percentEncoded- , replicateM 1 subDelims- , replicateM 1 $ return ':'- , replicateM 1 $ return '@'- ]--query :: Gen String-query = fmap (('?':) . concat) $ listOf $ oneof [ pchar- , return "/"- , return "?"- ]--fragment :: Gen String-fragment = fmap (('#':) . concat) $ listOf $ oneof [ pchar- , return "/"- , return "?"- ]--percentEncoded :: Gen String-percentEncoded = ('%':) <$> replicateM 2 hexdig--unreserved :: Gen Char-unreserved = oneof [ alpha, digit, elements ['-', '.', '_', '~']]--subDelims :: Gen Char-subDelims = elements ['!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=']---- * RFC 2234 Generators--alpha :: Gen Char-alpha = elements $ ['a'..'z'] ++ ['A'..'Z']--digit :: Gen Char-digit = elements ['0'..'9']--hexdig :: Gen Char-hexdig = oneof [digit, elements ['A'..'F']]
− test/External/Network/URI/ArbitrarySpec.hs
@@ -1,25 +0,0 @@-{-|-Module : External.Network.URI.ArbitrarySpec-Description : Tests for External.Network.URI.Arbitrary-Copyright : (c) Alex Brandt, 2017-License : MIT--Tests for "External.Network.URI.Arbitrary".--}-module External.Network.URI.ArbitrarySpec (main, spec) where--import Network.URI (isURIReference, parseURIReference, uriToString)-import Test.Hspec (describe, hspec, Spec)-import Test.Hspec.QuickCheck (prop)--import External.Network.URI.Arbitrary ()--main :: IO ()-main = hspec spec--spec :: Spec-spec =- describe "properties" $- do prop "isURIReference (uriToString id u \"\")" $ \ u -> isURIReference (uriToString id u "")-- prop "Just u == parseURIReference (uriToString id u \"\")" $ \ u -> Just u == parseURIReference (uriToString id u "")