rockyzh / jsonpath

Automatically exported from code.google.com/p/jsonpath
0 stars 0 forks source link

Test page showing inputs and expectations - for regression testing #26

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Having the test page tests/jsonpath-test-js.html show a variety of example 
objects, expressions and results is really useful. 

To make sense of it you need to review the output of the page (in a browser) - 
which only shows the results - side-by-side with the HTML source. 

The attached is an attempt to put all the useful information in the viewable 
page - namely what the source data object was and the input expression. Further 
to this I've included the expectations to potentially allow for regression 
testing - e.g. comparison of behaviour for different jsonpath.js versions by 
seeing what "fails" the expected vs actual test. 

So in summary, starting with the jsonpath-test-js.html, the changes in the 
attached include:
- reference to jsonpath.js is relative from /tests (../src/js/jsonpath.js)
- removed reference to json.js and using JSON.stringify(..) instead
- display (in tabular layout) the source data, expression and results
- structure of the test data changed to be (excuse the made up JSON schema):
     var suite =  [ <test-objects> ];
     <test-object>:  { 
        "comment": <optional test comment>,
        "data": <source object>,
        "tests": [ <expression-test-objects> ]
    }
    <expression-test-objects>: { 
         "expr": <jsonpath expression>, 
         "comment": <optional expression comment>,
         "paths": [ <expected PATH result as 0-to-many paths> ], 
         "values": [ <expected VALUE result as 0-to-many paths> ]
    }
- each expression test runs the path and value tests separately and compares 
the results with the expectations. This is different to jsonpath-test-js.html 
which only obtained the "PATH" result then obtained the values via 'evaluate'. 
Presently, there's one test failing the "VALUE" result (Test #2, Expression 
#1). 
- if a comparison between expected & actual fails, the actual result is 
stringified onto the page (perhaps to help update expectations)
- no-result 'false' is turned into empty array [] 
- added in the 'bookstore' data and example expressions and expectations from 
the Wiki 

I'm hoping someone else finds this useful ... 

Consider for inclusion in the project? Potentially, new issues could be 
captured as new "<test-object>" definitions - showing the expectation, and the 
page will show if it fails. 

Original issue reported on code.google.com by kevin.ja...@exari.com on 16 Jul 2013 at 2:46

Attachments: