Skip to content

Commit 7b4ac91

Browse files
committed
some tests
1 parent 92ff42c commit 7b4ac91

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/Data/Schematic/Schema.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ knownFieldName
7474
. KnownSymbol fieldName
7575
=> proxy '(fieldName, schema)
7676
-> Text
77-
knownFieldName _ = T.pack $ symbolVal (Proxy @fieldName)
77+
knownFieldName _ = demote' @fieldName
7878

7979
knownFieldSchema
8080
:: forall proxy fieldName schema

stack.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
resolver: lts-13.7
1+
# resolver: lts-13.7
22
# resolver: lts-12.0
3-
# resolver: lts-10.0
3+
resolver: lts-10.0
44
extra-deps:
55
- hjsonpointer-1.4.0@rev:0
66
- hjsonschema-1.9.0@rev:0

test/SchemaSpec.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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
2728
import Test.SmallCheck as SC
2829
-- import Test.SmallCheck.Drivers as SC
2930
import Test.SmallCheck.Series as SC
31+
#if !MIN_VERSION_base(4,11,0)
32+
import Data.Monoid ((<>))
33+
#endif
3034

3135

3236
type 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+
4050
jsonExample :: JsonRepr SchemaExample
4151
jsonExample = withRepr @SchemaExample
4252
$ field @"bar" (Just "bar")
@@ -80,6 +90,12 @@ schemaJson = "{\"foo\": [13], \"bar\": null}"
8090
schemaJson2 :: ByteString
8191
schemaJson2 = "{\"foo\": [3], \"bar\": null}"
8292

93+
schemaJson3 :: ByteString
94+
schemaJson3 = schemaJson
95+
96+
schemaJson4 :: ByteString
97+
schemaJson4 = "{\"baz1\": "<>schemaJson<>", \"baz3\": "<>schemaJson3<>"}"
98+
8399
schemaJsonSeries :: Monad m => SC.Series m (JsonRepr SchemaExample)
84100
schemaJsonSeries = 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

Comments
 (0)