@@ -13,6 +13,7 @@ import Control.Applicative (Const)
13import Data.Aeson (eitherDecode, encode)
13import Data.Aeson (eitherDecode, encode)
14import Data.Aeson.Encoding (encodingToLazyByteString)
14import Data.Aeson.Encoding (encodingToLazyByteString)
15import Data.Aeson.Internal (IResult(..), formatError, ifromJSON, iparse)
15import Data.Aeson.Internal (IResult(..), formatError, ifromJSON, iparse)
16+import qualified Data.Aeson.Internal as I
16import Data.Aeson.Parser (value)
17import Data.Aeson.Parser (value)
17import Data.Aeson.Types
18import Data.Aeson.Types
18import Data.DList (DList)
19import Data.DList (DList)
@@ -121,14 +122,20 @@ parserThrowErrorProp msg =
121 result :: Result ()
122 result :: Result ()
122 result = parse parser ()
123 result = parse parser ()
125+-- | Tests (also) that we catch the JSONPath and it has elements in the right order.
124−parserCatchErrorProp :: String -> Property
126+parserCatchErrorProp :: [String] -> String -> Property
125−parserCatchErrorProp msg =
127+parserCatchErrorProp path msg =
126− result === Success msg
128+ result === Success ([I.Key "outer", I.Key "inner"] ++ jsonPath, msg)
128− -- Fail, catch, use error message as a successful parse
129− parser = const $ parserCatchError (fail msg) (\_ err -> pure err)
130+ parser = parserCatchError outer (\p err -> pure (p, err))
132+ outer = inner I.<?> I.Key "outer"
133+ inner = parserThrowError jsonPath msg I.<?> I.Key "inner"
130− result :: Result String
135+ result :: Result (I.JSONPath, String)
131− result = parse parser ()
136+ result = parse (const parser) ()
138+ jsonPath = map (I.Key . T.pack) path
133-- | Perform a structural comparison of the results of two encoding
140-- | Perform a structural comparison of the results of two encoding
134-- methods. Compares decoded values to account for HashMap-driven
141-- methods. Compares decoded values to account for HashMap-driven