1{-# OPTIONS_GHC -fprint-potential-instances #-}
3module SchemaSpec (spec, main) where
6import Data.ByteString.Lazy
7import Data.Functor.Identity
16 '[ '("foo", 'SchemaArray '[ 'AEq 1] ('SchemaNumber '[ 'NGt 10]))
17 , '("bar", 'SchemaOptional ('SchemaText '[ 'TEnum '["foo", "bar"]]))]
20 'Migration "test_revision"
21 '[ 'Diff '[ 'PKey "bar" ] ('Update ('SchemaText '[]))
22 , 'Diff '[ 'PKey "foo" ] ('Update ('SchemaNumber '[])) ]
24type VS = 'Versioned SchemaExample '[ TestMigration ]
26jsonExample :: JsonRepr SchemaExample
27jsonExample = ReprObject $
28 FieldRepr (ReprArray [ReprNumber 12])
29 :& FieldRepr (ReprOptional (Just (ReprText "bar")))
32schemaJson :: ByteString
33schemaJson = "{\"foo\": [13], \"bar\": null}"
35schemaJson2 :: ByteString
36schemaJson2 = "{\"foo\": [3], \"bar\": null}"
41 '[ '("foo", 'SchemaNumber '[])
42 , '("bar", 'SchemaText '[])])
43topObject = ReprObject $
44 FieldRepr (ReprNumber 42)
45 :& FieldRepr (ReprText "test")
50 -- it "show/read JsonRepr properly" $
51 -- read (show example) == example
52 it "decode/encode JsonRepr properly" $
53 decode (encode jsonExample) == Just jsonExample
54 it "validates correct representation" $
55 ((decodeAndValidateJson schemaJson) :: ParseResult (JsonRepr SchemaExample))
56 `shouldSatisfy` isValid
57 it "returns decoding error on structurally incorrect input" $
58 ((decodeAndValidateJson "{}") :: ParseResult (JsonRepr SchemaExample))
59 `shouldSatisfy` isDecodingError
60 it "validates incorrect representation" $
61 ((decodeAndValidateJson schemaJson2) :: ParseResult (JsonRepr SchemaExample))
62 `shouldSatisfy` isValidationError
63 -- it "validates versioned json" $ do
64 -- decodeAndValidateVersionedJson (Proxy @VS) schemaJson
65 -- `shouldSatisfy` isValid
66 it "validates versioned json with a migration list" $ do
67 decodeAndValidateVersionedWithPureMList
70 (Proxy @(SchemaByRevision "test_revision" VS))
71 (const $ Identity topObject) MNil)
73 `shouldSatisfy` isValid
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