Skip to content

Multiple errors for records? #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/Test/Record.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import Prelude

import Control.Monad.Gen as Gen
import Control.Monad.Gen.Common as GenC
import Data.Codec.JSON.Common (DecodeError(..))
import Data.Codec.JSON.Common as CJ
import Data.Codec.JSON.Record as CJR
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype, unwrap, wrap)
import Data.Profunctor (dimap)
Expand All @@ -14,6 +16,7 @@ import Effect (Effect)
import Effect.Console (log)
import JSON as J
import JSON.Object as JO
import JSON.Path as JP
import Test.QuickCheck (assertEquals, quickCheck, quickCheckGen)
import Test.QuickCheck.Gen (Gen)
import Test.Util (genInt, propCodec)
Expand Down Expand Up @@ -94,4 +97,16 @@ main = do
let obj = J.toJObject $ CJ.encode innerCodec (v { o = Just b })
pure $ assertEquals (Just [ "m", "n", "o" ]) (JO.keys <$> obj)

log "Check record with two errors has both reported"
quickCheckGen do
n ← Gen.chooseBool
m ← genInt
o ← Gen.chooseBool
let
codec = CJR.object { n: CJ.boolean, m: CJ.int, o: CJ.boolean }
encoded = CJ.encode codec { n, m, o }
decoded = CJ.decode innerCodec encoded
error = DecodeError { causes: [], message: "Expected value of type Int", path: JP.AtKey "n" JP.Tip }
pure $ assertEquals (Left error) decoded

pure unit