Skip to content

Commit 0df89f7

Browse files
committed
basic harness for running conformance tests
1 parent a9058a7 commit 0df89f7

4 files changed

Lines changed: 88 additions & 0 deletions

File tree

src/test/conformance_tests.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head></head>
4+
<body>
5+
These are the the official JSONQuery conformance tests.
6+
<div id="tests">
7+
</div>
8+
</body>
9+
<script src="js/jquery-1.6.1.min.js"></script>
10+
<script src="js/conf_tests.js"></script>
11+
</html>

src/test/js/conf_tests.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
$(document).ready(function() {
2+
var tests = {};
3+
4+
function fetchFile(p, c) {
5+
$.get(p, function (data) {
6+
$("." + c).text(data);
7+
});
8+
}
9+
10+
function renderTests() {
11+
var c = $("<div/>");
12+
for (var k in tests) {
13+
c.append($("<h1/>").text("document: " + k));
14+
var cl = k + "_document";
15+
c.append($("<pre/>").addClass(cl).text("loading document..."));
16+
fetchFile("tests/" + k + ".json", cl);
17+
for (var i = 0; i < tests[k].length; i++) {
18+
var n = tests[k][i];
19+
c.append($("<h2/>").text(n));
20+
var cl = k + "_" + n + "_selector";
21+
c.append($("<pre/>").addClass(cl).text("loading selector..."));
22+
fetchFile("tests/" + k + "_" + n + ".selector", cl);
23+
cl = k + "_" + n + "_output";
24+
c.append($("<pre/>").addClass(cl).text("loading output..."));
25+
fetchFile("tests/" + k + "_" + n + ".output", cl);
26+
}
27+
}
28+
c.appendTo($("#tests"));
29+
}
30+
31+
$.get("tests/alltests.txt", function (data) {
32+
var lines = data.split("\n");
33+
for (var i = 0; i < lines.length; i++) {
34+
var f = $.trim(lines[i]);
35+
if (f.length == 0) continue;
36+
var m = /^([A-Za-z]+)_(.+)\.selector$/.exec(f);
37+
console.log(f, ": ", m);
38+
if (m) {
39+
if (!tests.hasOwnProperty(m[1])) tests[m[1]] = [];
40+
tests[m[1]].push(m[2]);
41+
}
42+
}
43+
renderTests();
44+
});
45+
});

src/test/tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../tests/

tests/alltests.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
alltests.txt
2+
basic_first-child.output
3+
basic_first-child.selector
4+
basic_grouping.output
5+
basic_grouping.selector
6+
basic_id_multiple.output
7+
basic_id_multiple.selector
8+
basic_id.output
9+
basic_id_quotes.output
10+
basic_id_quotes.selector
11+
basic_id.selector
12+
basic_id_with_type.output
13+
basic_id_with_type.selector
14+
basic.json
15+
basic_last-child.output
16+
basic_last-child.selector
17+
basic_nth-child.output
18+
basic_nth-child.selector
19+
basic_nth-last-child.output
20+
basic_nth-last-child.selector
21+
basic_root_psuedo.output
22+
basic_root_psuedo.selector
23+
basic_type2.output
24+
basic_type2.selector
25+
basic_type3.output
26+
basic_type3.selector
27+
basic_type.output
28+
basic_type.selector
29+
basic_universal.output
30+
basic_universal.selector
31+
basic.xml

0 commit comments

Comments
 (0)