@@ -1,33 +1,28 @@
1+{-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
1{-# OPTIONS_GHC -fprint-potential-instances #-}
2{-# OPTIONS_GHC -fprint-potential-instances #-}
3−{-# LANGUAGE DataKinds #-}
4+{-# LANGUAGE DataKinds #-}
4−{-# LANGUAGE FlexibleContexts #-}
5+{-# LANGUAGE FlexibleContexts #-}
5−{-# LANGUAGE GADTs #-}
6+{-# LANGUAGE GADTs #-}
6−{-# LANGUAGE OverloadedLists #-}
7+{-# LANGUAGE OverloadedLists #-}
7−{-# LANGUAGE OverloadedStrings #-}
8+{-# LANGUAGE OverloadedStrings #-}
8−{-# LANGUAGE RankNTypes #-}
9+{-# LANGUAGE RankNTypes #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
10−{-# LANGUAGE TypeApplications #-}
11+{-# LANGUAGE TypeApplications #-}
12module SchemaSpec (spec, main) where
13module SchemaSpec (spec, main) where
14import Control.Lens
15import Control.Lens
15import Data.Aeson
16import Data.Aeson
16import Data.ByteString.Lazy
17import Data.ByteString.Lazy
17−import Data.Functor.Identity
18import Data.Proxy
18import Data.Proxy
19import Data.Schematic
19import Data.Schematic
20−import Data.Schematic.Generator
21−import Data.Singletons
23import Data.Vinyl
20import Data.Vinyl
24import Test.Hspec
21import Test.Hspec
25import Test.Hspec.SmallCheck
22import Test.Hspec.SmallCheck
26import Test.SmallCheck as SC
23import Test.SmallCheck as SC
27−import Test.SmallCheck.Drivers as SC
28import Test.SmallCheck.Series as SC
24import Test.SmallCheck.Series as SC
32type SchemaExample = 'SchemaObject
27type SchemaExample = 'SchemaObject
33 '[ '("foo", 'SchemaArray '[ 'AEq 1] ('SchemaNumber '[ 'NGt 10]))
28 '[ '("foo", 'SchemaArray '[ 'AEq 1] ('SchemaNumber '[ 'NGt 10]))
@@ -37,6 +32,13 @@ type SchemaExample2 = 'SchemaObject
37 '[ '("foo", 'SchemaArray '[ 'AEq 2] ('SchemaText '[ 'TGt 10]))
32 '[ '("foo", 'SchemaArray '[ 'AEq 2] ('SchemaText '[ 'TGt 10]))
38 , '("bar", 'SchemaOptional ('SchemaText '[ 'TRegex "[0-9]+"]))]
33 , '("bar", 'SchemaOptional ('SchemaText '[ 'TRegex "[0-9]+"]))]
35+type SchemaExample3 = 'SchemaUnion '[SchemaExample]
37+type SchemaExample4 = 'SchemaObject
38+ '[ '("baz3", SchemaExample3)
39+ , '("baz1", SchemaExample)]
40jsonExample :: JsonRepr SchemaExample
42jsonExample :: JsonRepr SchemaExample
41jsonExample = withRepr @SchemaExample
43jsonExample = withRepr @SchemaExample
42 $ field @"bar" (Just "bar")
44 $ field @"bar" (Just "bar")
@@ -45,7 +47,7 @@ jsonExample = withRepr @SchemaExample
46type AddQuuz =
48type AddQuuz =
47 'Migration "add_field_quuz"
49 'Migration "add_field_quuz"
48− '[ 'Diff '[] ('AddKey "quuz" (SchemaNumber '[])) ]
50+ '[ 'Diff '[] ('AddKey "quuz" ('SchemaNumber '[])) ]
50type DeleteQuuz =
52type DeleteQuuz =
51 'Migration "remove_field_quuz"
53 'Migration "remove_field_quuz"
@@ -80,6 +82,12 @@ schemaJson = "{\"foo\": [13], \"bar\": null}"
80schemaJson2 :: ByteString
82schemaJson2 :: ByteString
81schemaJson2 = "{\"foo\": [3], \"bar\": null}"
83schemaJson2 = "{\"foo\": [3], \"bar\": null}"
85+schemaJson3 :: ByteString
86+schemaJson3 = schemaJson
88+schemaJson4 :: ByteString
89+schemaJson4 = "{\"baz1\": "<>schemaJson<>", \"baz3\": "<>schemaJson3<>"}"
83schemaJsonSeries :: Monad m => SC.Series m (JsonRepr SchemaExample)
91schemaJsonSeries :: Monad m => SC.Series m (JsonRepr SchemaExample)
84schemaJsonSeries = series
92schemaJsonSeries = series
@@ -93,7 +101,7 @@ spec = do
93 it "decode/encode JsonRepr properly" $
101 it "decode/encode JsonRepr properly" $
94 decode (encode jsonExample) == Just jsonExample
102 decode (encode jsonExample) == Just jsonExample
95 it "validates correct representation" $
103 it "validates correct representation" $
96− ((decodeAndValidateJson schemaJson) :: ParseResult (JsonRepr SchemaExample))
104+ ((decodeAndValidateJson schemaJson4) :: ParseResult (JsonRepr SchemaExample4))
97 `shouldSatisfy` isValid
105 `shouldSatisfy` isValid
98 it "returns decoding error on structurally incorrect input" $
106 it "returns decoding error on structurally incorrect input" $
99 ((decodeAndValidateJson "{}") :: ParseResult (JsonRepr SchemaExample))
107 ((decodeAndValidateJson "{}") :: ParseResult (JsonRepr SchemaExample))