@@ -12,16 +12,19 @@ import Data.Argonaut.Gen as AGen
1212import Data.Either (Either (..))
1313import Data.Either.Nested (type (\/))
1414import Data.Foldable (notElem )
15+ import Data.Map as Map
16+ import Data.Maybe (Maybe (..))
1517import Data.String (Pattern (..))
1618import Data.String as String
1719import Data.String.Gen as StringGen
1820import Data.Tuple.Nested ((/\))
1921import Foreign.Object as Object
20- import JsonSchema (JsonSchema )
22+ import JsonSchema (JsonSchema (..), ObjectFormJsonSchemaSpec (..) )
2123import JsonSchema as Schema
2224import JsonSchema.Codec as Codec
2325import Test.QuickCheck (Result (..), (===))
24- import Test.Spec (describe )
26+ import Test.Spec (describe , it )
27+ import Test.Spec.Assertions (fail , shouldEqual )
2528import Test.Types (TestSpec )
2629import Test.Utils (TestLength (..), generativeTestCase )
2730
@@ -99,6 +102,79 @@ spec = describe "Codec" do
99102 , pattern: " type"
100103 }
101104
105+ positiveParseTestCase
106+ { description: " an empty object schema"
107+ , expectedSchema: ObjectFormJsonSchema JsonEmptySchema
108+ , json: A .jsonEmptyObject
109+ }
110+
111+ positiveParseTestCase
112+ { description: " a false boolean schema"
113+ , expectedSchema: BooleanFormJsonSchema false
114+ , json: A .fromBoolean false
115+ }
116+
117+ positiveParseTestCase
118+ { description: " a true boolean schema"
119+ , expectedSchema: BooleanFormJsonSchema true
120+ , json: A .fromBoolean true
121+ }
122+
123+ positiveParseTestCase
124+ { description: " a schema for an array"
125+ , expectedSchema: ObjectFormJsonSchema
126+ $ JsonArraySchema { itemsSchema: Nothing , uniqueItems: false }
127+ , json: A .jsonSingletonObject " type" $ A .fromString " array"
128+ }
129+
130+ positiveParseTestCase
131+ { description: " a schema for a boolean"
132+ , expectedSchema: ObjectFormJsonSchema JsonBooleanSchema
133+ , json: A .jsonSingletonObject " type" $ A .fromString " boolean"
134+ }
135+
136+ positiveParseTestCase
137+ { description: " a schema for integer"
138+ , expectedSchema: ObjectFormJsonSchema $ JsonIntegerSchema {}
139+ , json: A .jsonSingletonObject " type" $ A .fromString " integer"
140+ }
141+
142+ positiveParseTestCase
143+ { description: " a schema for a null"
144+ , expectedSchema: ObjectFormJsonSchema JsonNullSchema
145+ , json: A .jsonSingletonObject " type" $ A .fromString " null"
146+ }
147+
148+ positiveParseTestCase
149+ { description: " a schema for a number"
150+ , expectedSchema: ObjectFormJsonSchema $ JsonNumberSchema {}
151+ , json: A .jsonSingletonObject " type" $ A .fromString " number"
152+ }
153+
154+ positiveParseTestCase
155+ { description: " a schema for an object"
156+ , expectedSchema: ObjectFormJsonSchema
157+ $ JsonObjectSchema { properties: Map .empty }
158+ , json: A .jsonSingletonObject " type" $ A .fromString " object"
159+ }
160+
161+ positiveParseTestCase
162+ { description: " a schema for a string"
163+ , expectedSchema: ObjectFormJsonSchema $ JsonStringSchema {}
164+ , json: A .jsonSingletonObject " type" $ A .fromString " string"
165+ }
166+
167+ positiveParseTestCase
168+ ∷ { description ∷ String , expectedSchema ∷ JsonSchema , json ∷ Json }
169+ → TestSpec
170+ positiveParseTestCase { description, expectedSchema, json } = it
171+ (" Should parse " <> description)
172+ case Codec .parseSchema json of
173+ Left parseErrorMessage →
174+ fail $ " Could not parse JSON schema: " <> parseErrorMessage
175+ Right parsedSchema →
176+ parsedSchema `shouldEqual` expectedSchema
177+
102178errorMessageShouldMention
103179 ∷ { description ∷ String
104180 , parsingResult ∷ String \/ JsonSchema
0 commit comments