git.iko.soy/typeable/swagger2
on v1.1.1 help sign in
typeable/swagger2/test/SpecCommon.hs
25 lines 724 B history raw
1module SpecCommon where
3import Data.Aeson
4import qualified Data.Foldable as F
5import qualified Data.HashMap.Strict as HashMap
6import qualified Data.Vector as Vector
8import Test.Hspec
10isSubJSON :: Value -> Value -> Bool
11isSubJSON Null _ = True
12isSubJSON (Object x) (Object y) = HashMap.keys x == HashMap.keys i && F.and i
13 where
14 i = HashMap.intersectionWith isSubJSON x y
15isSubJSON (Array xs) (Array ys) = Vector.length xs == Vector.length ys && F.and (Vector.zipWith isSubJSON xs ys)
16isSubJSON x y = x == y
18(<=>) :: (Eq a, Show a, ToJSON a, FromJSON a) => a -> Value -> Spec
19x <=> js = do
20 it "encodes correctly" $ do
21 toJSON x `shouldBe` js
22 it "decodes correctly" $ do
23 fromJSON js `shouldBe` Success x