git.iko.soy/typeable/openapi3
on master help sign in
typeable/openapi3/test/SpecCommon.hs
22 lines 764 B history raw
1module SpecCommon where
3import Data.Aeson
4import Data.ByteString.Builder (toLazyByteString)
5import qualified Data.Foldable as F
6import qualified Data.HashMap.Strict as HashMap
7import qualified Data.Vector as Vector
9import Test.Hspec
11(<=>) :: (Eq a, Show a, ToJSON a, FromJSON a, HasCallStack) => a -> Value -> Spec
12x <=> js = do
13 it "encodes correctly" $ do
14 toJSON x `shouldBe` js
15 it "decodes correctly" $ do
16 fromJSON js `shouldBe` Success x
17 it "roundtrips: eitherDecode . encode" $ do
18 eitherDecode (encode x) `shouldBe` Right x
19 it "roundtrips with toJSON" $ do
20 eitherDecode (encode $ toJSON x) `shouldBe` Right x
21 it "roundtrips with toEncoding" $ do
22 eitherDecode (toLazyByteString $ fromEncoding $ toEncoding x) `shouldBe` Right x