Skip to content

Commit 6110e14

Browse files
committed
Expand parserCatchErrorProp test
1 parent 53e1b78 commit 6110e14

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

tests/Properties.hs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Control.Applicative (Const)
1313
import Data.Aeson (eitherDecode, encode)
1414
import Data.Aeson.Encoding (encodingToLazyByteString)
1515
import Data.Aeson.Internal (IResult(..), formatError, ifromJSON, iparse)
16+
import qualified Data.Aeson.Internal as I
1617
import Data.Aeson.Parser (value)
1718
import Data.Aeson.Types
1819
import Data.DList (DList)
@@ -121,14 +122,20 @@ parserThrowErrorProp msg =
121122
result :: Result ()
122123
result = parse parser ()
123124

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)
127129
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
132139

133140
-- | Perform a structural comparison of the results of two encoding
134141
-- methods. Compares decoded values to account for HashMap-driven

0 commit comments

Comments
 (0)