forked from JSONPath-Plus/JSONPath
/
test.html
59 lines (59 loc) · 2.68 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<html>
<head>
<title>JSONPath Tests</title>
<link rel="stylesheet" href="../node_modules/nodeunit/dist/browser/nodeunit.css" type="text/css" />
<script src="../node_modules/nodeunit/dist/browser/nodeunit.js"></script>
<script src="../lib/jsonpath.js"></script>
<script type="text/javascript">
// helper to get all the test cases
var suites = [], _testCase = nodeunit.testCase;
nodeunit.testCase = function(tc) {
suites.push(tc); return _testCase(tc) };
// stubs to load nodejs tests
function require(path) {
if (path === 'nodeunit') return nodeunit;
if (path.match(/^\.\.\/?$/)) return jsonPath;
}
var module = {exports: {}};
</script>
<script type="text/javascript">
// synchronous load function for JS code, uses XMLHttpRequest abstraction from
// http://www.quirksmode.org/js/xmlhttp.html
// Since the tests are written in node.js style we need to wrap their code into
// a function, otherwise they would pollute the global NS and interfere with each
// other
function get(url, callback) {
function sendRequest(url,callback) {
var req = createXMLHTTPObject();
req.open("GET",url,false/*sync*/);
req.onreadystatechange = function () { req.readyState == 4 && callback(req); }
if (req.readyState != 4) req.send();
};
function createXMLHTTPObject() {
var XMLHttpFactories = [
function () {return new XMLHttpRequest()},
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
function () {return new ActiveXObject("Msxml3.XMLHTTP")},
function () {return new ActiveXObject("Microsoft.XMLHTTP")}];
for (var i=0;i<XMLHttpFactories.length;i++)
try { return XMLHttpFactories[i](); } catch (e) { }
return false;
}
sendRequest(url, callback);
}
function loadJS(url) { get(url, function(req) { new Function(req.responseText)(); })}
</script>
</head>
<body>
<h1 id="nodeunit-header">JSONPath Tests</h1>
<script>
loadJS('test.arr.js');
loadJS("test.at_and_dollar.js");
loadJS("test.eval.js");
loadJS("test.examples.js");
loadJS("test.intermixed.arr.js");
loadJS("test.parent-selector.js");
nodeunit.run(suites);
</script>
</body>
</html>