mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
harness: Support more assertion types
This commit is contained in:
parent
e701ba4d43
commit
4bb2a70e08
7 changed files with 38 additions and 26 deletions
|
@ -12,16 +12,28 @@ function _pass(s, m) {
|
|||
window.alert(_oneline("TEST-PASS | " + s + ": " + m));
|
||||
}
|
||||
|
||||
function is(a, b, c) {
|
||||
let f = a != b ? _fail : _pass;
|
||||
let m = !c ? "" : c;
|
||||
f(a + " == " + b, m);
|
||||
function _printer(opstr, op) {
|
||||
return function (a, b, msg) {
|
||||
let f = op(a,b) ? _pass : _fail;
|
||||
if (!msg) msg = "";
|
||||
f(a + " " + opstr + " " + b, msg);
|
||||
};
|
||||
}
|
||||
|
||||
function isnot(a, b, c) {
|
||||
let f = (a != b) ? _pass : _fail;
|
||||
let m = !c ? "" : c;
|
||||
f(a + " != " + b, m);
|
||||
var is = _printer("==", function (a,b) { return a == b; });
|
||||
var is_a = _printer("is a", function (a,b) { return a instanceof b; });
|
||||
var is_in = _printer("is in", function (a,b) { return a in b; });
|
||||
var is_not_in = _printer("is not in", function (a,b) { return !(a in b); });
|
||||
var as_str_is = _printer("as string is", function (a,b) { return String(a) == b; });
|
||||
var isnot = _printer("!=", function (a,b) { return a != b; });
|
||||
var lt = _printer("<", function (a,b) { return a < b; });
|
||||
var gt = _printer(">", function (a,b) { return a > b; });
|
||||
var leq = _printer("<=", function (a,b) { return a <= b; });
|
||||
var geq = _printer(">=", function (a,b) { return a >= b; });
|
||||
var starts_with = _printer("starts with", function (a,b) { return a.indexOf(b) == 0; });
|
||||
|
||||
function is_function(val, name) {
|
||||
starts_with(String(val), "function " + name + "(");
|
||||
}
|
||||
|
||||
var _test_complete = false;
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
var child2 = document.createElement("p");
|
||||
elem.appendChild(child2);
|
||||
|
||||
is(1 in children, true);
|
||||
is_in(1, children);
|
||||
is(children.length, 2);
|
||||
is(children.item(1), child2);
|
||||
|
||||
is(!(2 in children), true);
|
||||
is_not_in(2, children);
|
||||
is(children.item(2), null);
|
||||
|
||||
finish();
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
var elem = document.createElement("foo");
|
||||
is(elem.tagName, "FOO");
|
||||
var elem = document.createElement("p");
|
||||
is(elem instanceof HTMLParagraphElement, true);
|
||||
is_a(elem, HTMLParagraphElement);
|
||||
var elem = document.createElement("sPAn");
|
||||
is(elem instanceof HTMLSpanElement, true);
|
||||
is_a(elem, HTMLSpanElement);
|
||||
var text = document.createTextNode("hello");
|
||||
is(text instanceof Text, true);
|
||||
is_a(text, Text);
|
||||
finish();
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
let foo = document.getElementById("foo");
|
||||
isnot(foo, null, "test-1-0, on static page");
|
||||
is(foo && foo.tagName, "HEAD", "test1-1, on static page");
|
||||
is(foo instanceof HTMLHeadElement, true, "test1-2, on static page");
|
||||
is_a(foo, HTMLHeadElement, "test1-2, on static page");
|
||||
|
||||
let bar = document.getElementById("bar");
|
||||
isnot(bar, null, "test1-3, on static page");
|
||||
is(bar && bar.tagName, "DIV", "test1-4, on static page");
|
||||
is(bar instanceof HTMLDivElement, true, "test1-5, on static page");
|
||||
is_a(bar, HTMLDivElement, "test1-5, on static page");
|
||||
}
|
||||
|
||||
// test2: scripted element
|
||||
|
@ -32,7 +32,7 @@
|
|||
let appended = document.getElementById(TEST_ID);
|
||||
isnot(appended, null, "test2-0, appended element");
|
||||
is(appended && appended.tagName, "DIV", "test2-1, appended element");
|
||||
is(appended instanceof HTMLDivElement, true, "test2-2, appended element");
|
||||
is_a(appended, HTMLDivElement, "test2-2, appended element");
|
||||
|
||||
// test: removed element
|
||||
gBody.removeChild(test);
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
<script>
|
||||
var rect = window.document.head.getBoundingClientRect();
|
||||
var rects = window.document.head.getClientRects();
|
||||
is(rect instanceof ClientRect, true);
|
||||
is_a(rect, ClientRect);
|
||||
is(rect.top, 0);
|
||||
is(rect.bottom, 0);
|
||||
is(rect.left, 0);
|
||||
is(rect.right, 0);
|
||||
is(rect.width, 0);
|
||||
is(rect.height, 0);
|
||||
is(rects instanceof ClientRectList, true);
|
||||
is_a(rects, ClientRectList);
|
||||
is(rects.length, 0);
|
||||
finish();
|
||||
</script>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<body>
|
||||
<script>
|
||||
is(window.navigator, window.navigator);
|
||||
is(String(window.navigator), '[object Navigator]');
|
||||
is_a(window.navigator, Navigator);
|
||||
|
||||
var nav = window.navigator;
|
||||
is(nav.doNotTrack, "unspecified");
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
<body>
|
||||
<foo-á>foo</foo-á>
|
||||
<script>
|
||||
is(window.document.documentElement instanceof Node, true);
|
||||
is(window.document.documentElement instanceof Element, true);
|
||||
is(window.document.documentElement instanceof HTMLElement, true);
|
||||
is(window.document.documentElement instanceof HTMLHtmlElement, true);
|
||||
is(window.document instanceof Document, true);
|
||||
is(window.document instanceof HTMLDocument, true);
|
||||
is_a(window.document.documentElement, Node);
|
||||
is_a(window.document.documentElement, Element);
|
||||
is_a(window.document.documentElement, HTMLElement);
|
||||
is_a(window.document.documentElement, HTMLHtmlElement);
|
||||
is_a(window.document, Document);
|
||||
is_a(window.document, HTMLDocument);
|
||||
is(window.document.documentElement.tagName, "HTML");
|
||||
is(window.document.getElementsByTagName('foo-á')[0] instanceof HTMLUnknownElement, true);
|
||||
is_a(window.document.getElementsByTagName('foo-á')[0], HTMLUnknownElement);
|
||||
is(window.document.getElementsByTagName('foo-á')[0].tagName, "FOO-á");
|
||||
finish();
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue