Closed glyn closed 1 year ago
One option would be to write programmatic parser tests for errors instead of building this feature into the JSON-based tests. An example of such is this:
{-# LANGUAGE OverloadedStrings #-}
module Spec.FilterSpec (spec) where
import Data.JSONPath.Parser(jsonPath)
import Data.Text
import Test.Hspec
import Test.Hspec.Megaparsec
import Text.Megaparsec
filterMissingEndBracketEtoks :: ET Text
filterMissingEndBracketEtoks =
etoks "!="
<> etoks "&&"
<> etoks "<="
<> etoks "=="
<> etoks ">="
<> etoks "||"
<> etoks "!"
<> etoks "."
<> etoks "<"
<> etoks ">"
<> etoks "["
<> etoks "]"
spec :: Spec
spec = do
describe "filter" $ do
it "ummatched filter bracket parse error" $
parse (jsonPath eof) "" "$[?@.foo"
`shouldFailWith` err 8 (ueof <> filterMissingEndBracketEtoks <> elabel "white space")
Yeah, I think there is little point in making these tests JSON. Using megaparsec types to check for expected tokens sounds like a good idea :+1:
Thanks. Closing as we now have an agreed way forward.
While adding function extension support, I'd like to be sure that certain malformed JSONPaths produce reasonable errors. Currently, JSONPathSpec.hs does not provide a way of testing parser errors - it treats all parser errors as bad tests.