on master help sign in
Accumulate DList errors
584135eAdam Bergmark
Data/Aeson/AccParser.hs+3
@@ -8,6 +8,9 @@ module Data.Aeson.AccParser
8 , (<*>+)
8 , (<*>+)
9 ) where
9 ) where
10
10
11+import Prelude ()
12+import Prelude.Compat
13+
11import Data.Aeson.Types.Internal (Parser (..), runParser)
14import Data.Aeson.Types.Internal (Parser (..), runParser)
12import Data.List.NonEmpty (NonEmpty ((:|)))
15import Data.List.NonEmpty (NonEmpty ((:|)))
13import qualified Data.List.NonEmpty as NonEmpty
16import qualified Data.List.NonEmpty as NonEmpty
Data/Aeson/Types/FromJSON.hs+1−1
@@ -1439,7 +1439,7 @@ instance FromJSON Scientific where
1439instance FromJSON1 DList.DList where
1439instance FromJSON1 DList.DList where
1440 liftParseJSON p _ = withArray "DList a" $
1440 liftParseJSON p _ = withArray "DList a" $
1441 fmap DList.fromList .
1441 fmap DList.fromList .
1442− Tr.sequence . zipWith (parseIndexedJSON p) [0..] . V.toList
1442+ accSequence . zipWith (parseIndexedJSON p) [0..] . V.toList
1443 {-# INLINE liftParseJSON #-}
1443 {-# INLINE liftParseJSON #-}
1444
1444
1445instance (FromJSON a) => FromJSON (DList.DList a) where
1445instance (FromJSON a) => FromJSON (DList.DList a) where
tests/UnitTests/AccErrors.hs+8
@@ -6,6 +6,7 @@ import Prelude ()
6import Prelude.Compat hiding (seq)
6import Prelude.Compat hiding (seq)
7
7
8import Data.Aeson
8import Data.Aeson
9+import Data.DList (DList)
9import Data.Aeson.Parser.Internal
10import Data.Aeson.Parser.Internal
10import Data.Aeson.Types ()
11import Data.Aeson.Types ()
11import Data.Aeson.Internal
12import Data.Aeson.Internal
@@ -24,6 +25,7 @@ tests = testGroup "Error accumulation" [
24 testCase "Seq" seq
25 testCase "Seq" seq
25 , testCase "Vector" vector
26 , testCase "Vector" vector
26 , testCase "NonEmpty" nonEmpty
27 , testCase "NonEmpty" nonEmpty
28+ , testCase "DList" dlist
27 ]
29 ]
28
30
29decoder :: FromJSON a
31decoder :: FromJSON a
@@ -48,3 +50,9 @@ nonEmpty = do
48 let res = decoder "[true, null]" :: Either (NonEmpty (JSONPath, String)) (NL.NonEmpty Int)
50 let res = decoder "[true, null]" :: Either (NonEmpty (JSONPath, String)) (NL.NonEmpty Int)
49 let message i s = ([Index i], "expected Int, encountered " <> s)
51 let message i s = ([Index i], "expected Int, encountered " <> s)
50 res @=? Left (NL.fromList [message 0 "Boolean", message 1 "Null"])
52 res @=? Left (NL.fromList [message 0 "Boolean", message 1 "Null"])
53+
54+dlist :: Assertion
55+dlist = do
56+ let res = decoder "[true, null]" :: Either (NonEmpty (JSONPath, String)) (DList Int)
57+ let message i s = ([Index i], "expected Int, encountered " <> s)
58+ res @=? Left (NL.fromList [message 0 "Boolean", message 1 "Null"])