hspec-expectations-json-1.0.0.0: Hspec expectations for JSON Values

Safe HaskellNone
LanguageHaskell2010

Test.Hspec.Expectations.Json

Contents

Description

Expectations on JSON Values

Semantics:

Assertion that fails on: extra Object keys wrong Array order
shouldBeJson Yes Yes
shouldBeUnorderedJson Yes No
shouldMatchJson No No
shouldMatchOrderedJson No Yes
Synopsis

Documentation

shouldBeJson :: HasCallStack => Value -> Value -> IO () infix 1 Source #

Compare two JSON values, with a useful diff

>>> :{
catchFailure $
  [aesonQQ| { "a": true, "b": false } |] `shouldBeJson`
  [aesonQQ| { "a": true, "b": false } |]
:}
<passed>
>>> :{
catchFailure $
  [aesonQQ| { "a": true, "b": false } |] `shouldBeJson`
  [aesonQQ| { "a": true, "b": true  } |]
:}
   {
       "a": true,
---    "b": true
+++    "b": false
   }

shouldBeUnorderedJson :: HasCallStack => Value -> Value -> IO () infix 1 Source #

shouldBeJson, ignoring Array ordering

>>> :{
catchFailure $
  [aesonQQ| { "a": [true, false], "b": false } |] `shouldBeUnorderedJson`
  [aesonQQ| { "a": [false, true], "b": false } |]
:}
<passed>
>>> :{
catchFailure $
  [aesonQQ| { "a": [true, false], "b": false, "c": true } |] `shouldBeUnorderedJson`
  [aesonQQ| { "a": [false, true], "b": true             } |]
:}
   {
       "a": [
           false,
           true
       ],
---    "b": true
+++    "b": false,
+++    "c": true
   }

shouldMatchJson :: HasCallStack => Value -> Value -> IO () infix 1 Source #

shouldBeJson, ignoring extra Object keys or Array ordering

>>> :{
catchFailure $
  [aesonQQ| { "a": [true, false], "b": false, "c": true } |] `shouldMatchJson`
  [aesonQQ| { "a": [false, true], "b": false            } |]
:}
<passed>
>>> :{
catchFailure $
  [aesonQQ| { "a": [true, false], "b": false, "c": true } |] `shouldMatchJson`
  [aesonQQ| { "a": [false, true], "b": true             } |]
:}
   {
       "a": [
           false,
           true
       ],
---    "b": true
+++    "b": false
   }

shouldMatchOrderedJson :: HasCallStack => Value -> Value -> IO () infix 1 Source #

shouldBeJson, ignoring extra Object keys

>>> :{
catchFailure $
  [aesonQQ| { "a": [true, false], "b": false, "c": true } |] `shouldMatchOrderedJson`
  [aesonQQ| { "a": [true, false], "b": false            } |]
:}
<passed>
>>> :{
catchFailure $
  [aesonQQ| { "a": [true, false], "b": false, "c": true } |] `shouldMatchOrderedJson`
  [aesonQQ| { "a": [false, true], "b": true             } |]
:}
   {
       "a": [
---        false,
---        true
+++        true,
+++        false
       ],
---    "b": true
+++    "b": false
   }

As predicates

These are only created when a specific need arises

matchesJson :: Value -> Value -> Bool Source #

Compare JSON values with the same semantics as shouldMatchJson