on master help sign in
Basic TH testing
commit30834b524c0424d1563143e61bec8a395e98cbee authorBryan O'Sullivan <bos@serpentine.com> dateThu 2 Jul 2015, 15:10 (11 years ago) parent0fb9de0
2 files changed+13
tests/Encoders.hs+3 tests/Properties.hs+10
tests/Encoders.hs+3
@@ -14,6 +14,9 @@ import Types
1414thNullaryToJSONString :: Nullary -> Value
1515thNullaryToJSONString = $(mkToJSON defaultOptions ''Nullary)
1616
17+thNullaryToEncodingString :: Nullary -> Encoding
18+thNullaryToEncodingString = $(mkToEncoding defaultOptions ''Nullary)
19+
1720thNullaryParseJSONString :: Value -> Parser Nullary
1821thNullaryParseJSONString = $(mkParseJSON defaultOptions ''Nullary)
1922
tests/Properties.hs+10
@@ -5,6 +5,7 @@ import Data.Aeson (eitherDecode)
55import Data.Aeson.Encode
66import Data.Aeson.Parser (value)
77import Data.Aeson.Types
8+import Data.ByteString.Builder (toLazyByteString)
89import Data.Char (toUpper)
910import Test.Framework (Test, defaultMain, testGroup)
1011import Test.Framework.Providers.QuickCheck2 (testProperty)
@@ -76,6 +77,11 @@ modifyFailureProp orig added =
7677 result :: Result ()
7778 result = parse parser ()
7879
80+sameAs :: (a -> Value) -> (a -> Encoding) -> a -> Property
81+sameAs toVal toEnc v =
82+ toLazyByteString (encodeToBuilder (toVal v)) ===
83+ toLazyByteString (fromEncoding (toEnc v))
84+
7985main :: IO ()
8086main = do
8187 comparisonTest <- encoderComparisonTests
@@ -185,6 +191,10 @@ tests = [
185191 ]
186192 ]
187193 ]
194+ , testGroup "toEncoding" [
195+ testProperty "NullaryString" $
196+ thNullaryToJSONString `sameAs` thNullaryToEncodingString
197+ ]
188198 ]
189199 ]
190200