4import Data.ByteString.Builder (toLazyByteString)
5import qualified Data.Foldable as F
6import qualified Data.HashMap.Strict as HashMap
9import qualified Data.Vector as Vector
12import Test.QuickCheck (Arbitrary, property)
14isSubJSON :: Value -> Value -> Bool
15isSubJSON Null _ = True
16isSubJSON (Object x) (Object y) = HashMap.keys x == HashMap.keys i && F.and i
18 i = HashMap.intersectionWith isSubJSON x y
19isSubJSON (Array xs) (Array ys) = Vector.length xs == Vector.length ys && F.and (Vector.zipWith isSubJSON xs ys)
22(<=>) :: (Eq a, Show a, ToJSON a, FromJSON a, HasCallStack) => a -> Value -> Spec
24 it "encodes correctly" $ do
25 toJSON x `shouldBe` js
26 it "decodes correctly" $ do
27 fromJSON js `shouldBe` Success x
28 it "roundtrips: eitherDecode . encode" $ do
29 eitherDecode (encode x) `shouldBe` Right x
30 it "roundtrips with toJSON" $ do
31 eitherDecode (encode $ toJSON x) `shouldBe` Right x
32 it "roundtrips with toEncoding" $ do
33 eitherDecode (toLazyByteString $ fromEncoding $ toEncoding x) `shouldBe` Right x
35testJsonIdempotency :: (Eq a, Show a, Arbitrary a, FromJSON a, ToJSON a, Typeable a, HasCallStack) =>
37testJsonIdempotency px = describe (show ty) $ do
38 it "roundtrips: decode . encode" $ property $ \x ->
39 decode (encode x) == Just (x `asProxyTypeOf` px)
41 ty = typeOf $ undefined `asProxyTypeOf` px
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list