Diffstat (limited to 'frontend/gamma/js/MochiKit/Test.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/MochiKit/Test.js | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/frontend/gamma/js/MochiKit/Test.js b/frontend/gamma/js/MochiKit/Test.js index 9520ab2..f29670f 100644 --- a/frontend/gamma/js/MochiKit/Test.js +++ b/frontend/gamma/js/MochiKit/Test.js | |||
@@ -1,144 +1,144 @@ | |||
1 | /*** | 1 | /*** |
2 | 2 | ||
3 | MochiKit.Test 1.5 | 3 | MochiKit.Test 1.5 |
4 | 4 | ||
5 | See <http://mochikit.com/> for documentation, downloads, license, etc. | 5 | See <http://mochikit.com/> for documentation, downloads, license, etc. |
6 | 6 | ||
7 | (c) 2005 Bob Ippolito. All rights Reserved. | 7 | (c) 2005 Bob Ippolito. All rights Reserved. |
8 | 8 | ||
9 | ***/ | 9 | ***/ |
10 | 10 | ||
11 | MochiKit.Base._module('Test', '1.5', ['Base']); | 11 | MochiKit.Base.module(MochiKit, 'Test', '1.5', ['Base']); |
12 | 12 | ||
13 | MochiKit.Test.runTests = function (obj) { | 13 | MochiKit.Test.runTests = function (obj) { |
14 | if (typeof(obj) == "string") { | 14 | if (typeof(obj) == "string") { |
15 | // TODO: Remove this temporary API change advertisement | 15 | // TODO: Remove this temporary API change advertisement |
16 | throw new TypeError("Automatic module import not supported, call runTests() with proper object: " + obj); | 16 | throw new TypeError("Automatic module import not supported, call runTests() with proper object: " + obj); |
17 | } | 17 | } |
18 | var suite = new MochiKit.Test.Suite(); | 18 | var suite = new MochiKit.Test.Suite(); |
19 | suite.run(obj); | 19 | suite.run(obj); |
20 | }; | 20 | }; |
21 | 21 | ||
22 | MochiKit.Test.Suite = function () { | 22 | MochiKit.Test.Suite = function () { |
23 | this.testIndex = 0; | 23 | this.testIndex = 0; |
24 | MochiKit.Base.bindMethods(this); | 24 | MochiKit.Base.bindMethods(this); |
25 | }; | 25 | }; |
26 | 26 | ||
27 | MochiKit.Test.Suite.prototype = { | 27 | MochiKit.Test.Suite.prototype = { |
28 | run: function (obj) { | 28 | run: function (obj) { |
29 | try { | 29 | try { |
30 | obj(this); | 30 | obj(this); |
31 | } catch (e) { | 31 | } catch (e) { |
32 | this.traceback(e); | 32 | this.traceback(e); |
33 | } | 33 | } |
34 | }, | 34 | }, |
35 | traceback: function (e) { | 35 | traceback: function (e) { |
36 | var items = MochiKit.Iter.sorted(MochiKit.Base.items(e)); | 36 | var items = MochiKit.Iter.sorted(MochiKit.Base.items(e)); |
37 | print("not ok " + this.testIndex + " - Error thrown"); | 37 | print("not ok " + this.testIndex + " - Error thrown"); |
38 | for (var i = 0; i < items.length; i++) { | 38 | for (var i = 0; i < items.length; i++) { |
39 | var kv = items[i]; | 39 | var kv = items[i]; |
40 | if (kv[0] == "stack") { | 40 | if (kv[0] == "stack") { |
41 | kv[1] = kv[1].split(/\n/)[0]; | 41 | kv[1] = kv[1].split(/\n/)[0]; |
42 | } | 42 | } |
43 | this.print("# " + kv.join(": ")); | 43 | this.print("# " + kv.join(": ")); |
44 | } | 44 | } |
45 | }, | 45 | }, |
46 | print: function (s) { | 46 | print: function (s) { |
47 | print(s); | 47 | print(s); |
48 | }, | 48 | }, |
49 | is: function (got, expected, /* optional */message) { | 49 | is: function (got, expected, /* optional */message) { |
50 | var res = 1; | 50 | var res = 1; |
51 | var msg = null; | 51 | var msg = null; |
52 | try { | 52 | try { |
53 | res = MochiKit.Base.compare(got, expected); | 53 | res = MochiKit.Base.compare(got, expected); |
54 | } catch (e) { | 54 | } catch (e) { |
55 | msg = "Can not compare " + typeof(got) + ":" + typeof(expected); | 55 | msg = "Can not compare " + typeof(got) + ":" + typeof(expected); |
56 | } | 56 | } |
57 | if (res) { | 57 | if (res) { |
58 | msg = "Expected value did not compare equal"; | 58 | msg = "Expected value did not compare equal"; |
59 | } | 59 | } |
60 | if (!res) { | 60 | if (!res) { |
61 | return this.testResult(true, message); | 61 | return this.testResult(true, message); |
62 | } | 62 | } |
63 | return this.testResult(false, message, | 63 | return this.testResult(false, message, |
64 | [[msg], ["got:", got], ["expected:", expected]]); | 64 | [[msg], ["got:", got], ["expected:", expected]]); |
65 | }, | 65 | }, |
66 | 66 | ||
67 | testResult: function (pass, msg, failures) { | 67 | testResult: function (pass, msg, failures) { |
68 | this.testIndex += 1; | 68 | this.testIndex += 1; |
69 | if (pass) { | 69 | if (pass) { |
70 | this.print("ok " + this.testIndex + " - " + msg); | 70 | this.print("ok " + this.testIndex + " - " + msg); |
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | this.print("not ok " + this.testIndex + " - " + msg); | 73 | this.print("not ok " + this.testIndex + " - " + msg); |
74 | if (failures) { | 74 | if (failures) { |
75 | for (var i = 0; i < failures.length; i++) { | 75 | for (var i = 0; i < failures.length; i++) { |
76 | this.print("# " + failures[i].join(" ")); | 76 | this.print("# " + failures[i].join(" ")); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | }, | 79 | }, |
80 | 80 | ||
81 | isDeeply: function (got, expected, /* optional */message) { | 81 | isDeeply: function (got, expected, /* optional */message) { |
82 | var m = MochiKit.Base; | 82 | var m = MochiKit.Base; |
83 | var res = 1; | 83 | var res = 1; |
84 | try { | 84 | try { |
85 | res = m.compare(got, expected); | 85 | res = m.compare(got, expected); |
86 | } catch (e) { | 86 | } catch (e) { |
87 | // pass | 87 | // pass |
88 | } | 88 | } |
89 | if (res === 0) { | 89 | if (res === 0) { |
90 | return this.ok(true, message); | 90 | return this.ok(true, message); |
91 | } | 91 | } |
92 | var gk = m.keys(got); | 92 | var gk = m.keys(got); |
93 | var ek = m.keys(expected); | 93 | var ek = m.keys(expected); |
94 | gk.sort(); | 94 | gk.sort(); |
95 | ek.sort(); | 95 | ek.sort(); |
96 | if (m.compare(gk, ek)) { | 96 | if (m.compare(gk, ek)) { |
97 | // differing keys | 97 | // differing keys |
98 | var cmp = {}; | 98 | var cmp = {}; |
99 | var i; | 99 | var i; |
100 | for (i = 0; i < gk.length; i++) { | 100 | for (i = 0; i < gk.length; i++) { |
101 | cmp[gk[i]] = "got"; | 101 | cmp[gk[i]] = "got"; |
102 | } | 102 | } |
103 | for (i = 0; i < ek.length; i++) { | 103 | for (i = 0; i < ek.length; i++) { |
104 | if (ek[i] in cmp) { | 104 | if (ek[i] in cmp) { |
105 | delete cmp[ek[i]]; | 105 | delete cmp[ek[i]]; |
106 | } else { | 106 | } else { |
107 | cmp[ek[i]] = "expected"; | 107 | cmp[ek[i]] = "expected"; |
108 | } | 108 | } |
109 | } | 109 | } |
110 | var diffkeys = m.keys(cmp); | 110 | var diffkeys = m.keys(cmp); |
111 | diffkeys.sort(); | 111 | diffkeys.sort(); |
112 | var gotkeys = []; | 112 | var gotkeys = []; |
113 | var expkeys = []; | 113 | var expkeys = []; |
114 | while (diffkeys.length) { | 114 | while (diffkeys.length) { |
115 | var k = diffkeys.shift(); | 115 | var k = diffkeys.shift(); |
116 | if (k in Object.prototype) { | 116 | if (k in Object.prototype) { |
117 | continue; | 117 | continue; |
118 | } | 118 | } |
119 | (cmp[k] == "got" ? gotkeys : expkeys).push(k); | 119 | (cmp[k] == "got" ? gotkeys : expkeys).push(k); |
120 | } | 120 | } |
121 | 121 | ||
122 | 122 | ||
123 | } | 123 | } |
124 | 124 | ||
125 | return this.testResult((!res), msg, | 125 | return this.testResult((!res), msg, |
126 | (msg ? [["got:", got], ["expected:", expected]] : undefined) | 126 | (msg ? [["got:", got], ["expected:", expected]] : undefined) |
127 | ); | 127 | ); |
128 | }, | 128 | }, |
129 | 129 | ||
130 | ok: function (res, message) { | 130 | ok: function (res, message) { |
131 | return this.testResult(res, message); | 131 | return this.testResult(res, message); |
132 | } | 132 | } |
133 | }; | 133 | }; |
134 | 134 | ||
135 | MochiKit.Test.__new__ = function () { | 135 | MochiKit.Test.__new__ = function () { |
136 | var m = MochiKit.Base; | 136 | var m = MochiKit.Base; |
137 | this.Suite.__export__ = false; | 137 | this.Suite.__export__ = false; |
138 | m.nameFunctions(this); | 138 | m.nameFunctions(this); |
139 | 139 | ||
140 | }; | 140 | }; |
141 | 141 | ||
142 | MochiKit.Test.__new__(); | 142 | MochiKit.Test.__new__(); |
143 | 143 | ||
144 | MochiKit.Base._exportSymbols(this, MochiKit.Test); | 144 | MochiKit.Base._exportSymbols(this, MochiKit.Test); |