1 function checkSnapshot(comment, actual, expected) {
2 if (actual.snapshotLength != expected.length) {
3 testFailed(comment + " incorrect length (expected " + expected.length + ", actual " + actual.snapshotLength + ")");
7 for (i = 0; i < actual.snapshotLength; ++i) {
8 if (actual.snapshotItem(i) != expected[i]) {
9 testFailed(comment + " item " + i + " incorrect (expected " + expected[i].nodeName + ", actual " + actual.snapshotItem(i).nodeName + ")");
17 function test(doc, context, expr, expected, nsResolver)
20 if (typeof(context) == "string")
21 context = doc.evaluate(context, doc.documentElement, nsResolver, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
22 if (typeof(expected) == "object") {
23 var result = doc.evaluate(expr, context, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
24 checkSnapshot(expr, result, expected);
26 var result = doc.evaluate(expr, context, nsResolver, XPathResult.ANY_TYPE, null);
27 if (typeof(expected) == "number") {
28 if (result.numberValue == expected)
31 testFailed(expr + ": expected " + expected + ", actual " + result.numberValue);
32 } else if (typeof(expected) == "string") {
33 if (result.stringValue == expected)
36 testFailed(expr + ": expected '" + expected + "', actual '" + result.stringValue + "'");
37 } else if (typeof(expected) == "boolean") {
38 if (result.booleanValue == expected)
41 testFailed(expr + ": expected '" + expected + "', actual '" + result.booleanValue + "'");
45 testFailed(expr + ": raised " + ex);