Declarative TOML-driven test case generation for rsonpath
The whole pitch of this framework is that we can declare full query engine test documents and queries by writing a straightforward TOML config file:
[]
= "short json with objects and lists, given as an example on jsonpath com"
= false
[]
= '''
{
"firstName": "John",
"lastName": "doe",
"age": 26,
"address": {
"streetAddress": "naist street",
"city": "Nara",
"postalCode": "630-0192"
},
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4567-8888"
},
{
"type": "home",
"number": "0123-4567-8910"
}
]
}
'''
[[]]
= "select exact path with name and index selectors"
= "$.phoneNumbers[0].type"
[]
= 1
= [239]
= ['"iPhone"']
[[]]
= "descendant search for 'number'"
= "$..number"
[]
= 2
= [271, 359]
= ['"0123-4567-8888"', '"0123-4567-8910"']
[[]]
= "select first number directly"
= "$.phoneNumbers[0]"
[]
= 1
= [217]
= ['''{
"type": "iPhone",
"number": "0123-4567-8888"
}''']
How it works
This library provides a single public entry point, generate_tests, that takes a path to a directory with the source TOML configuration
and a path to an auxillary JSON output directory.
- It reads all the TOML files and parses them into the structures declared in
model. - It creates compressed versions of all documents that are declared as non-compressed (
input.is_compressedis false) using thecompressionmodule. This will create a new TOML file with the same name, located in thecompressedsubdirectory, whose input source was processed to be a minified JSON. - Each TOML document that has an inline
input.sourcehas a JSON file created with the given input. There are two reasons for this: one, testingMmapInputrequires an actual file; two, putting those strings inline into the generated test.rsfile makes it excessively large. - Each document gets test cases generated for each declared query, using both engines, all declared result types,
and all supported input modes. This is driven by
gen.
Large inputs
The input.source property can either contain an inline JSON string as the json_string property,
or a relative path to the file containing the actual JSON in the large_file property. This is used
for the twitter and wikidata files, since they take multiple megabytes and make the TOML file hard to edit.