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
|
||||
_ -> False
|
||||
|
||||
-- | Find the type of a value.
|
||||
|
||||
infer :: Json.Value -> Type
|
||||
infer = \case
|
||||
Value.Null -> Null
|
||||
|
@ -107,6 +109,8 @@ instance HasField "actual" Mismatch Type where
|
|||
getField :: Mismatch -> Type
|
||||
getField = (.inferred)
|
||||
|
||||
-- | Compute all the differences to the expected type. Empty List means that the value is conforming.
|
||||
|
||||
conforms :: Type -> Json.Value -> [Mismatch]
|
||||
conforms = conforms' []
|
||||
|
||||
|
@ -135,6 +139,8 @@ conforms' path layout value = case (value, layout) of
|
|||
else Foldable.concatMap id mismatches
|
||||
_ -> pure $ Mismatch {expected=layout, inferred=infer value, value=value, path=path}
|
||||
|
||||
-- | Choose any arbitrary value conforming to the type.
|
||||
|
||||
sample :: Type -> Gen Value
|
||||
sample = \case
|
||||
All -> arbitrary
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue