Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /***
3 MochiKit.Test 1.4.2
5 See <http://mochikit.com/> for documentation, downloads, license, etc.
7 (c) 2005 Bob Ippolito. All rights Reserved.
9 ***/
11 MochiKit.Base._deps('Test', ['Base']);
13 MochiKit.Test.NAME = "MochiKit.Test";
14 MochiKit.Test.VERSION = "1.4.2";
15 MochiKit.Test.__repr__ = function () {
16 return "[" + this.NAME + " " + this.VERSION + "]";
17 };
19 MochiKit.Test.toString = function () {
20 return this.__repr__();
21 };
24 MochiKit.Test.EXPORT = ["runTests"];
25 MochiKit.Test.EXPORT_OK = [];
27 MochiKit.Test.runTests = function (obj) {
28 if (typeof(obj) == "string") {
29 obj = JSAN.use(obj);
30 }
31 var suite = new MochiKit.Test.Suite();
32 suite.run(obj);
33 };
35 MochiKit.Test.Suite = function () {
36 this.testIndex = 0;
37 MochiKit.Base.bindMethods(this);
38 };
40 MochiKit.Test.Suite.prototype = {
41 run: function (obj) {
42 try {
43 obj(this);
44 } catch (e) {
45 this.traceback(e);
46 }
47 },
48 traceback: function (e) {
49 var items = MochiKit.Iter.sorted(MochiKit.Base.items(e));
50 print("not ok " + this.testIndex + " - Error thrown");
51 for (var i = 0; i < items.length; i++) {
52 var kv = items[i];
53 if (kv[0] == "stack") {
54 kv[1] = kv[1].split(/\n/)[0];
55 }
56 this.print("# " + kv.join(": "));
57 }
58 },
59 print: function (s) {
60 print(s);
61 },
62 is: function (got, expected, /* optional */message) {
63 var res = 1;
64 var msg = null;
65 try {
66 res = MochiKit.Base.compare(got, expected);
67 } catch (e) {
68 msg = "Can not compare " + typeof(got) + ":" + typeof(expected);
69 }
70 if (res) {
71 msg = "Expected value did not compare equal";
72 }
73 if (!res) {
74 return this.testResult(true, message);
75 }
76 return this.testResult(false, message,
77 [[msg], ["got:", got], ["expected:", expected]]);
78 },
80 testResult: function (pass, msg, failures) {
81 this.testIndex += 1;
82 if (pass) {
83 this.print("ok " + this.testIndex + " - " + msg);
84 return;
85 }
86 this.print("not ok " + this.testIndex + " - " + msg);
87 if (failures) {
88 for (var i = 0; i < failures.length; i++) {
89 this.print("# " + failures[i].join(" "));
90 }
91 }
92 },
94 isDeeply: function (got, expected, /* optional */message) {
95 var m = MochiKit.Base;
96 var res = 1;
97 try {
98 res = m.compare(got, expected);
99 } catch (e) {
100 // pass
101 }
102 if (res === 0) {
103 return this.ok(true, message);
104 }
105 var gk = m.keys(got);
106 var ek = m.keys(expected);
107 gk.sort();
108 ek.sort();
109 if (m.compare(gk, ek)) {
110 // differing keys
111 var cmp = {};
112 var i;
113 for (i = 0; i < gk.length; i++) {
114 cmp[gk[i]] = "got";
115 }
116 for (i = 0; i < ek.length; i++) {
117 if (ek[i] in cmp) {
118 delete cmp[ek[i]];
119 } else {
120 cmp[ek[i]] = "expected";
121 }
122 }
123 var diffkeys = m.keys(cmp);
124 diffkeys.sort();
125 var gotkeys = [];
126 var expkeys = [];
127 while (diffkeys.length) {
128 var k = diffkeys.shift();
129 if (k in Object.prototype) {
130 continue;
131 }
132 (cmp[k] == "got" ? gotkeys : expkeys).push(k);
133 }
136 }
138 return this.testResult((!res), msg,
139 (msg ? [["got:", got], ["expected:", expected]] : undefined)
140 );
141 },
143 ok: function (res, message) {
144 return this.testResult(res, message);
145 }
146 };
148 MochiKit.Test.__new__ = function () {
149 var m = MochiKit.Base;
151 this.EXPORT_TAGS = {
152 ":common": this.EXPORT,
153 ":all": m.concat(this.EXPORT, this.EXPORT_OK)
154 };
156 m.nameFunctions(this);
158 };
160 MochiKit.Test.__new__();
162 MochiKit.Base._exportSymbols(this, MochiKit.Test);