Skip to content

Commit

Permalink
Accumulate DList errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmark committed Dec 25, 2017
1 parent 7bcf368 commit 584135e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Data/Aeson/AccParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module Data.Aeson.AccParser
, (<*>+)
) where

import Prelude ()
import Prelude.Compat

import Data.Aeson.Types.Internal (Parser (..), runParser)
import Data.List.NonEmpty (NonEmpty ((:|)))
import qualified Data.List.NonEmpty as NonEmpty
Expand Down
2 changes: 1 addition & 1 deletion Data/Aeson/Types/FromJSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ instance FromJSON Scientific where
instance FromJSON1 DList.DList where
liftParseJSON p _ = withArray "DList a" $
fmap DList.fromList .
Tr.sequence . zipWith (parseIndexedJSON p) [0..] . V.toList
accSequence . zipWith (parseIndexedJSON p) [0..] . V.toList
{-# INLINE liftParseJSON #-}

instance (FromJSON a) => FromJSON (DList.DList a) where
Expand Down
8 changes: 8 additions & 0 deletions tests/UnitTests/AccErrors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Prelude ()
import Prelude.Compat hiding (seq)

import Data.Aeson
import Data.DList (DList)
import Data.Aeson.Parser.Internal
import Data.Aeson.Types ()
import Data.Aeson.Internal
Expand All @@ -24,6 +25,7 @@ tests = testGroup "Error accumulation" [
testCase "Seq" seq
, testCase "Vector" vector
, testCase "NonEmpty" nonEmpty
, testCase "DList" dlist
]

decoder :: FromJSON a
Expand All @@ -48,3 +50,9 @@ nonEmpty = do
let res = decoder "[true, null]" :: Either (NonEmpty (JSONPath, String)) (NL.NonEmpty Int)
let message i s = ([Index i], "expected Int, encountered " <> s)
res @=? Left (NL.fromList [message 0 "Boolean", message 1 "Null"])

dlist :: Assertion
dlist = do
let res = decoder "[true, null]" :: Either (NonEmpty (JSONPath, String)) (DList Int)
let message i s = ([Index i], "expected Int, encountered " <> s)
res @=? Left (NL.fromList [message 0 "Boolean", message 1 "Null"])

0 comments on commit 584135e

Please sign in to comment.