on master help sign in
Accumulate DList errors
commit584135e8e65df292c36530b79fa53f07f15cb3b4 authorAdam Bergmark <adam@bergmark.nl> dateMon 25 Dec 2017, 18:55 (9 years ago) parent7bcf368
3 files changed+12−1
Data/Aeson/AccParser.hs+3 Data/Aeson/Types/FromJSON.hs+1−1 tests/UnitTests/AccErrors.hs+8
Data/Aeson/AccParser.hs+3
@@ -8,6 +8,9 @@ module Data.Aeson.AccParser
88 , (<*>+)
99 ) where
1010
11+import Prelude ()
12+import Prelude.Compat
13+
1114import Data.Aeson.Types.Internal (Parser (..), runParser)
1215import Data.List.NonEmpty (NonEmpty ((:|)))
1316import qualified Data.List.NonEmpty as NonEmpty
Data/Aeson/Types/FromJSON.hs+1−1
@@ -1439,7 +1439,7 @@ instance FromJSON Scientific where
14391439instance FromJSON1 DList.DList where
14401440 liftParseJSON p _ = withArray "DList a" $
14411441 fmap DList.fromList .
1442− Tr.sequence . zipWith (parseIndexedJSON p) [0..] . V.toList
1442+ accSequence . zipWith (parseIndexedJSON p) [0..] . V.toList
14431443 {-# INLINE liftParseJSON #-}
14441444
14451445instance (FromJSON a) => FromJSON (DList.DList a) where
tests/UnitTests/AccErrors.hs+8
@@ -6,6 +6,7 @@ import Prelude ()
66import Prelude.Compat hiding (seq)
77
88import Data.Aeson
9+import Data.DList (DList)
910import Data.Aeson.Parser.Internal
1011import Data.Aeson.Types ()
1112import Data.Aeson.Internal
@@ -24,6 +25,7 @@ tests = testGroup "Error accumulation" [
2425 testCase "Seq" seq
2526 , testCase "Vector" vector
2627 , testCase "NonEmpty" nonEmpty
28+ , testCase "DList" dlist
2729 ]
2830
2931decoder :: FromJSON a
@@ -48,3 +50,9 @@ nonEmpty = do
4850 let res = decoder "[true, null]" :: Either (NonEmpty (JSONPath, String)) (NL.NonEmpty Int)
4951 let message i s = ([Index i], "expected Int, encountered " <> s)
5052 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"])