on 0453cc3 help sign in
servant/test/Servant/API/ContentTypesSpec.hs
52 lines 1.8 kB history raw
1{-# LANGUAGE DeriveGeneric #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
3module Servant.API.ContentTypesSpec where
5import Control.Applicative
6import Data.Aeson
7import Data.Proxy
8import qualified Data.Text as TextS
9import qualified Data.Text.Lazy as TextL
10import GHC.Generics
11import Test.Hspec
12import Test.QuickCheck
14import Servant.API.ContentTypes
16spec :: Spec
17spec = describe "Servant.API.ContentTypes" $ do
19 describe "The JSON Content-Type type" $ do
21 it "has fromByteString reverse toByteString for valid top-level json ([Int]) " $ do
22 let p = Proxy :: Proxy JSON
23 property $ \x -> fromByteString p (toByteString p x) == Right (x::[Int])
25 it "has fromByteString reverse toByteString for valid top-level json " $ do
26 let p = Proxy :: Proxy JSON
27 property $ \x -> fromByteString p (toByteString p x) == Right (x::SomeData)
29 describe "The PlainText Content-Type type" $ do
31 it "has fromByteString reverse toByteString (lazy Text)" $ do
32 let p = Proxy :: Proxy PlainText
33 property $ \x -> fromByteString p (toByteString p x) == Right (x::TextL.Text)
35 it "has fromByteString reverse toByteString (strict Text)" $ do
36 let p = Proxy :: Proxy PlainText
37 property $ \x -> fromByteString p (toByteString p x) == Right (x::TextS.Text)
40data SomeData = SomeData { record1 :: String, record2 :: Int }
41 deriving (Generic, Eq, Show)
43instance FromJSON SomeData
44instance ToJSON SomeData
45instance Arbitrary SomeData where
46 arbitrary = SomeData <$> arbitrary <*> arbitrary
48instance Arbitrary TextL.Text where
49 arbitrary = TextL.pack <$> arbitrary
51instance Arbitrary TextS.Text where
52 arbitrary = TextS.pack <$> arbitrary