@@ -1,33 +1,28 @@
1+{-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
12{-# OPTIONS_GHC -fprint-potential-instances #-}
23
3−{-# LANGUAGE DataKinds #-}
4−{-# LANGUAGE FlexibleContexts #-}
5−{-# LANGUAGE GADTs #-}
6−{-# LANGUAGE OverloadedLists #-}
7−{-# LANGUAGE OverloadedStrings #-}
8−{-# LANGUAGE RankNTypes #-}
4+{-# LANGUAGE DataKinds #-}
5+{-# LANGUAGE FlexibleContexts #-}
6+{-# LANGUAGE GADTs #-}
7+{-# LANGUAGE OverloadedLists #-}
8+{-# LANGUAGE OverloadedStrings #-}
9+{-# LANGUAGE RankNTypes #-}
910{-# LANGUAGE ScopedTypeVariables #-}
10−{-# LANGUAGE TypeApplications #-}
11+{-# LANGUAGE TypeApplications #-}
1112
1213module SchemaSpec (spec, main) where
1314
1415import Control.Lens
1516import Data.Aeson
1617import Data.ByteString.Lazy
17−import Data.Functor.Identity
1818import Data.Proxy
1919import Data.Schematic
20−import Data.Schematic.Generator
21−import Data.Singletons
22−import Data.Tagged
2320import Data.Vinyl
2421import Test.Hspec
2522import Test.Hspec.SmallCheck
2623import Test.SmallCheck as SC
27−import Test.SmallCheck.Drivers as SC
2824import Test.SmallCheck.Series as SC
2925
30−import Debug.Trace
3126
3227type SchemaExample = 'SchemaObject
3328 '[ '("foo", 'SchemaArray '[ 'AEq 1] ('SchemaNumber '[ 'NGt 10]))
@@ -37,6 +32,13 @@ type SchemaExample2 = 'SchemaObject
3732 '[ '("foo", 'SchemaArray '[ 'AEq 2] ('SchemaText '[ 'TGt 10]))
3833 , '("bar", 'SchemaOptional ('SchemaText '[ 'TRegex "[0-9]+"]))]
3934
35+type SchemaExample3 = 'SchemaUnion '[SchemaExample]
36+
37+type SchemaExample4 = 'SchemaObject
38+ '[ '("baz3", SchemaExample3)
39+ , '("baz1", SchemaExample)]
40+
41+
4042jsonExample :: JsonRepr SchemaExample
4143jsonExample = withRepr @SchemaExample
4244 $ field @"bar" (Just "bar")
@@ -45,7 +47,7 @@ jsonExample = withRepr @SchemaExample
4547
4648type AddQuuz =
4749 'Migration "add_field_quuz"
48− '[ 'Diff '[] ('AddKey "quuz" (SchemaNumber '[])) ]
50+ '[ 'Diff '[] ('AddKey "quuz" ('SchemaNumber '[])) ]
4951
5052type DeleteQuuz =
5153 'Migration "remove_field_quuz"
@@ -80,6 +82,12 @@ schemaJson = "{\"foo\": [13], \"bar\": null}"
8082schemaJson2 :: ByteString
8183schemaJson2 = "{\"foo\": [3], \"bar\": null}"
8284
85+schemaJson3 :: ByteString
86+schemaJson3 = schemaJson
87+
88+schemaJson4 :: ByteString
89+schemaJson4 = "{\"baz1\": "<>schemaJson<>", \"baz3\": "<>schemaJson3<>"}"
90+
8391schemaJsonSeries :: Monad m => SC.Series m (JsonRepr SchemaExample)
8492schemaJsonSeries = series
8593
@@ -93,7 +101,7 @@ spec = do
93101 it "decode/encode JsonRepr properly" $
94102 decode (encode jsonExample) == Just jsonExample
95103 it "validates correct representation" $
96− ((decodeAndValidateJson schemaJson) :: ParseResult (JsonRepr SchemaExample))
104+ ((decodeAndValidateJson schemaJson4) :: ParseResult (JsonRepr SchemaExample4))
97105 `shouldSatisfy` isValid
98106 it "returns decoding error on structurally incorrect input" $
99107 ((decodeAndValidateJson "{}") :: ParseResult (JsonRepr SchemaExample))