test: move failed json parsing to doctest
This commit is contained in:
committed by
Steve Chavez
parent
315b01ebf7
commit
3103060f4b
@@ -325,6 +325,11 @@ pTreePath = do
|
|||||||
-- Left (line 1, column 16):
|
-- Left (line 1, column 16):
|
||||||
-- unexpected '['
|
-- unexpected '['
|
||||||
-- expecting letter, digit, "-", "!", "(", "->>", "->", "::", ")", "," or end of input
|
-- expecting letter, digit, "-", "!", "(", "->>", "->", "::", ")", "," or end of input
|
||||||
|
--
|
||||||
|
-- >>> P.parse pFieldForest "" "data->>-78xy"
|
||||||
|
-- Left (line 1, column 11):
|
||||||
|
-- unexpected 'x'
|
||||||
|
-- expecting digit, "->", "::", ".", "," or end of input
|
||||||
pFieldForest :: Parser [Tree SelectItem]
|
pFieldForest :: Parser [Tree SelectItem]
|
||||||
pFieldForest = pFieldTree `sepBy1` lexeme (char ',')
|
pFieldForest = pFieldTree `sepBy1` lexeme (char ',')
|
||||||
where
|
where
|
||||||
@@ -401,6 +406,23 @@ pFieldName =
|
|||||||
--
|
--
|
||||||
-- >>> P.parse pJsonPath "" "->0.desc"
|
-- >>> P.parse pJsonPath "" "->0.desc"
|
||||||
-- Right [JArrow {jOp = JIdx {jVal = "+0"}}]
|
-- Right [JArrow {jOp = JIdx {jVal = "+0"}}]
|
||||||
|
--
|
||||||
|
-- Fails on badly formed negatives
|
||||||
|
--
|
||||||
|
-- >>> P.parse pJsonPath "" "->>-78xy"
|
||||||
|
-- Left (line 1, column 7):
|
||||||
|
-- unexpected 'x'
|
||||||
|
-- expecting digit, "->", "::", ".", "," or end of input
|
||||||
|
--
|
||||||
|
-- >>> P.parse pJsonPath "" "->>--34"
|
||||||
|
-- Left (line 1, column 5):
|
||||||
|
-- unexpected "-"
|
||||||
|
-- expecting digit
|
||||||
|
--
|
||||||
|
-- >>> P.parse pJsonPath "" "->>-xy-4"
|
||||||
|
-- Left (line 1, column 5):
|
||||||
|
-- unexpected "x"
|
||||||
|
-- expecting digit
|
||||||
pJsonPath :: Parser JsonPath
|
pJsonPath :: Parser JsonPath
|
||||||
pJsonPath = many pJsonOperation
|
pJsonPath = many pJsonOperation
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -292,25 +292,11 @@ spec actualPgVersion = describe "json and jsonb operators" $ do
|
|||||||
[json| [{"data":[{"a": [1,2,3]}, {"b": [4,5]}]}] |]
|
[json| [{"data":[{"a": [1,2,3]}, {"b": [4,5]}]}] |]
|
||||||
{ matchHeaders = [matchContentTypeJson] }
|
{ matchHeaders = [matchContentTypeJson] }
|
||||||
|
|
||||||
it "should fail on badly formed negatives" $ do
|
it "gives a meaningful error on bad syntax" $
|
||||||
get "/json_arr?select=data->>-78xy" `shouldRespondWith`
|
get "/json_arr?select=data->>--34" `shouldRespondWith`
|
||||||
[json|
|
[json|
|
||||||
{"details": "unexpected 'x' expecting digit, \"->\", \"::\", \".\", \",\" or end of input",
|
{"details": "unexpected \"-\" expecting digit",
|
||||||
"message": "\"failed to parse select parameter (data->>-78xy)\" (line 1, column 11)",
|
"message": "\"failed to parse select parameter (data->>--34)\" (line 1, column 9)",
|
||||||
"code": "PGRST100",
|
"code": "PGRST100",
|
||||||
"hint": null} |]
|
"hint": null} |]
|
||||||
{ matchStatus = 400, matchHeaders = [matchContentTypeJson] }
|
{ matchStatus = 400, matchHeaders = [matchContentTypeJson] }
|
||||||
get "/json_arr?select=data->>--34" `shouldRespondWith`
|
|
||||||
[json|
|
|
||||||
{"details": "unexpected \"-\" expecting digit",
|
|
||||||
"message": "\"failed to parse select parameter (data->>--34)\" (line 1, column 9)",
|
|
||||||
"code": "PGRST100",
|
|
||||||
"hint": null} |]
|
|
||||||
{ matchStatus = 400, matchHeaders = [matchContentTypeJson] }
|
|
||||||
get "/json_arr?select=data->>-xy-4" `shouldRespondWith`
|
|
||||||
[json|
|
|
||||||
{"details":"unexpected \"x\" expecting digit",
|
|
||||||
"message":"\"failed to parse select parameter (data->>-xy-4)\" (line 1, column 9)",
|
|
||||||
"code": "PGRST100",
|
|
||||||
"hint": null} |]
|
|
||||||
{ matchStatus = 400, matchHeaders = [matchContentTypeJson] }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user