doc[type]
This commit is contained in:
parent
bda145f8f4
commit
b081a2fa09
1 changed files with 6 additions and 0 deletions
|
@ -85,6 +85,8 @@ isObject = \case
|
||||||
Object _ -> True
|
Object _ -> True
|
||||||
_ -> False
|
_ -> False
|
||||||
|
|
||||||
|
-- | Find the type of a value.
|
||||||
|
|
||||||
infer :: Json.Value -> Type
|
infer :: Json.Value -> Type
|
||||||
infer = \case
|
infer = \case
|
||||||
Value.Null -> Null
|
Value.Null -> Null
|
||||||
|
@ -107,6 +109,8 @@ instance HasField "actual" Mismatch Type where
|
||||||
getField :: Mismatch -> Type
|
getField :: Mismatch -> Type
|
||||||
getField = (.inferred)
|
getField = (.inferred)
|
||||||
|
|
||||||
|
-- | Compute all the differences to the expected type. Empty List means that the value is conforming.
|
||||||
|
|
||||||
conforms :: Type -> Json.Value -> [Mismatch]
|
conforms :: Type -> Json.Value -> [Mismatch]
|
||||||
conforms = conforms' []
|
conforms = conforms' []
|
||||||
|
|
||||||
|
@ -135,6 +139,8 @@ conforms' path layout value = case (value, layout) of
|
||||||
else Foldable.concatMap id mismatches
|
else Foldable.concatMap id mismatches
|
||||||
_ -> pure $ Mismatch {expected=layout, inferred=infer value, value=value, path=path}
|
_ -> pure $ Mismatch {expected=layout, inferred=infer value, value=value, path=path}
|
||||||
|
|
||||||
|
-- | Choose any arbitrary value conforming to the type.
|
||||||
|
|
||||||
sample :: Type -> Gen Value
|
sample :: Type -> Gen Value
|
||||||
sample = \case
|
sample = \case
|
||||||
All -> arbitrary
|
All -> arbitrary
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue