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