From 4bb2a70e08143bf9047a8c4bb4e3cc918e541be9 Mon Sep 17 00:00:00 2001
From: Keegan McAllister
Date: Mon, 14 Oct 2013 16:38:42 -0700
Subject: [PATCH] harness: Support more assertion types
---
src/test/html/content/harness.js | 28 +++++++++++++------
src/test/html/content/test_childnodes.html | 4 +--
.../html/content/test_create_element.html | 6 ++--
.../content/test_document_getElementById.html | 6 ++--
.../html/content/test_empty_clientrect.html | 4 +--
src/test/html/content/test_navigator.html | 2 +-
src/test/html/content/test_prototypes.html | 14 +++++-----
7 files changed, 38 insertions(+), 26 deletions(-)
diff --git a/src/test/html/content/harness.js b/src/test/html/content/harness.js
index 725380838c2..0697376df4f 100644
--- a/src/test/html/content/harness.js
+++ b/src/test/html/content/harness.js
@@ -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;
diff --git a/src/test/html/content/test_childnodes.html b/src/test/html/content/test_childnodes.html
index f8a4d9797c6..205a6124959 100644
--- a/src/test/html/content/test_childnodes.html
+++ b/src/test/html/content/test_childnodes.html
@@ -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();
diff --git a/src/test/html/content/test_create_element.html b/src/test/html/content/test_create_element.html
index eaa3e11377a..f62c599504d 100644
--- a/src/test/html/content/test_create_element.html
+++ b/src/test/html/content/test_create_element.html
@@ -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();