11{-# OPTIONS_GHC -fprint-potential-instances #-}
22{-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
33
4+ {-# LANGUAGE CPP #-}
45{-# LANGUAGE DataKinds #-}
56{-# LANGUAGE FlexibleContexts #-}
67{-# LANGUAGE GADTs #-}
@@ -27,6 +28,9 @@ import Test.Hspec.SmallCheck
2728import Test.SmallCheck as SC
2829-- import Test.SmallCheck.Drivers as SC
2930import Test.SmallCheck.Series as SC
31+ #if !MIN_VERSION_base(4,11,0)
32+ import Data.Monoid ((<>) )
33+ #endif
3034
3135
3236type SchemaExample = 'SchemaObject
@@ -37,6 +41,12 @@ type SchemaExample2 = 'SchemaObject
3741 '[ '(" foo" , 'SchemaArray '[ 'AEq 2 ] ('SchemaText '[ 'TGt 10 ]))
3842 , '(" bar" , 'SchemaOptional ('SchemaText '[ 'TRegex " [0-9]+" ]))]
3943
44+ type SchemaExample3 = 'SchemaUnion '[SchemaExample ]
45+
46+ type SchemaExample4 = 'SchemaObject
47+ '[ '(" baz3" , SchemaExample3 )
48+ , '(" baz1" , SchemaExample )]
49+
4050jsonExample :: JsonRepr SchemaExample
4151jsonExample = withRepr @ SchemaExample
4252 $ field @ " bar" (Just " bar" )
@@ -80,6 +90,12 @@ schemaJson = "{\"foo\": [13], \"bar\": null}"
8090schemaJson2 :: ByteString
8191schemaJson2 = " {\" foo\" : [3], \" bar\" : null}"
8292
93+ schemaJson3 :: ByteString
94+ schemaJson3 = schemaJson
95+
96+ schemaJson4 :: ByteString
97+ schemaJson4 = " {\" baz1\" : " <> schemaJson<> " , \" baz3\" : " <> schemaJson3<> " }"
98+
8399schemaJsonSeries :: Monad m => SC. Series m (JsonRepr SchemaExample )
84100schemaJsonSeries = series
85101
@@ -93,7 +109,7 @@ spec = do
93109 it " decode/encode JsonRepr properly" $
94110 decode (encode jsonExample) == Just jsonExample
95111 it " validates correct representation" $
96- ((decodeAndValidateJson schemaJson ) :: ParseResult (JsonRepr SchemaExample ))
112+ ((decodeAndValidateJson schemaJson4 ) :: ParseResult (JsonRepr SchemaExample4 ))
97113 `shouldSatisfy` isValid
98114 it " returns decoding error on structurally incorrect input" $
99115 ((decodeAndValidateJson " {}" ) :: ParseResult (JsonRepr SchemaExample ))
0 commit comments