]> git.donarmstrong.com Git - dactyl.git/blob - common/tests/functional/utils.jsm
Initial import of 1.0~b6
[dactyl.git] / common / tests / functional / utils.jsm
1
2 var EXPORTED_SYMBOLS = ["NS", "assert", "assertEqual", "module", "test", "toJSON"];
3
4 const Ci = Components.interfaces;
5
6 function module(uri) {
7     if (!/^[a-z-]+:/.exec(uri))
8         uri = /([^ ]+\/)[^\/]+$/.exec(Components.stack.caller.filename)[1] + uri + ".jsm";
9
10     let obj = {};
11     Components.utils.import(uri, obj);
12     return obj;
13 }
14
15 var elementslib = module("resource://mozmill/modules/elementslib.js");
16 var frame = module("resource://mozmill/modules/frame.js");
17 var jumlib = module("resource://mozmill/modules/jum.js");
18
19 function toJSON(val) {
20     if (typeof val == "function")
21         return val.toSource();
22     if (val instanceof Ci.nsIDOMNode || val instanceof Ci.nsIDOMWindow)
23         return { DOMNode: String(val) };
24     return val;
25 }
26
27 function test(val, params) {
28     frame.events[val ? "pass" : "fail"](params);
29     return val;
30 }
31
32 var NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator");
33
34 function assert(funcName, value, comment)
35     test(value, {
36         function: funcName,
37         value: toJSON(value),
38         comment: toJSON(comment)
39     });
40
41 function assertEqual(funcName, want, got, comment)
42     test(want == got, {
43         function: funcName,
44         want: toJSON(want), got: toJSON(got),
45         comment: toJSON(comment)
46     });
47
48 // vim: sw=4 ts=8 et ft=javascript: