1module SchemaSpec (spec, main) where
4import Data.ByteString.Lazy
11import Test.Hspec.SmallCheck
13import Test.SmallCheck.Series.Instances
18 '[ '("foo", SchemaArray '[AEq 1] (SchemaNumber '[NGt 10]))
19 , '("bar", SchemaOptional (SchemaText '[TRegex "\\w+", TEnum '["foo", "bar"]]))]
21exampleTest :: JsonRepr (SchemaOptional (SchemaText '[TEq 3]))
22exampleTest = ReprOptional (Just (ReprText "lil"))
24exampleNumber :: JsonRepr (SchemaNumber '[NGt 10])
25exampleNumber = ReprNumber 12
27exampleArray :: JsonRepr (SchemaArray '[AEq 1] (SchemaNumber '[NGt 10]))
28exampleArray = ReprArray [exampleNumber]
30jsonExample :: JsonRepr SchemaExample
31jsonExample = ReprObject $
32 FieldRepr (ReprArray [ReprNumber 12])
33 :& FieldRepr (ReprOptional (Just (ReprText "bar")))
36schemaJson :: ByteString
37schemaJson = "{\"foo\": [13], \"bar\": null}"
39schemaJson2 :: ByteString
40schemaJson2 = "{\"foo\": [3], \"bar\": null}"
44 -- it "show/read JsonRepr properly" $
45 -- read (show example) == example
46 it "decode/encode JsonRepr properly" $
47 decode (encode jsonExample) == Just jsonExample
48 it "validates correct representation" $
49 ((decodeAndValidateJson schemaJson) :: ParseResult (JsonRepr SchemaExample))
50 `shouldSatisfy` isValid
51 it "returns decoding error on structurally incorrect input" $
52 ((decodeAndValidateJson "{}") :: ParseResult (JsonRepr SchemaExample))
53 `shouldSatisfy` isDecodingError
54 it "validates incorrect representation" $
55 ((decodeAndValidateJson schemaJson2) :: ParseResult (JsonRepr SchemaExample))
56 `shouldSatisfy` isValidationError
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list