Merge lp:~jjacobs/methanal/util-tests into lp:methanal
- util-tests
- Merge into trunk
Proposed by
Jonathan Jacobs
Status: | Superseded |
---|---|
Proposed branch: | lp:~jjacobs/methanal/util-tests |
Merge into: | lp:methanal |
Diff against target: |
454 lines 5 files modified
methanal/js/Methanal/Tests/DOMUtil.js (+0/-75) methanal/js/Methanal/Tests/MockBrowser.js (+102/-0) methanal/js/Methanal/Tests/TestUtil.js (+178/-5) methanal/js/Methanal/Tests/TestView.js (+2/-2) methanal/js/Methanal/Util.js (+16/-7) |
To merge this branch: | bzr merge lp:~jjacobs/methanal/util-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Methanal maintainers | Pending | ||
Review via email:
|
This proposal has been superseded by a proposal from 2009-10-12.
Commit message
Description of the change
To post a comment you must log in.
lp:~jjacobs/methanal/util-tests
updated
- 112. By Jonathan Jacobs
-
Initialise all properties.
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed file 'methanal/js/Methanal/Tests/DOMUtil.js' | |||
2 | --- methanal/js/Methanal/Tests/DOMUtil.js 2009-10-10 10:28:01 +0000 | |||
3 | +++ methanal/js/Methanal/Tests/DOMUtil.js 1970-01-01 00:00:00 +0000 | |||
4 | @@ -1,75 +0,0 @@ | |||
5 | 1 | // import Divmod.MockBrowser | ||
6 | 2 | |||
7 | 3 | |||
8 | 4 | |||
9 | 5 | /** | ||
10 | 6 | * HTMLSelectElement mock implementation. | ||
11 | 7 | */ | ||
12 | 8 | Divmod.MockBrowser.Element.subclass( | ||
13 | 9 | Methanal.Tests.DOMUtil, 'MockHTMLSelectElement').methods( | ||
14 | 10 | function __init__(self) { | ||
15 | 11 | Methanal.Tests.DOMUtil.MockHTMLSelectElement.upcall( | ||
16 | 12 | self, '__init__', 'select'); | ||
17 | 13 | self.options = []; | ||
18 | 14 | }, | ||
19 | 15 | |||
20 | 16 | |||
21 | 17 | /** | ||
22 | 18 | * Add a new element to the collection of OPTION elements for this SELECT. | ||
23 | 19 | */ | ||
24 | 20 | function add(self, element, before) { | ||
25 | 21 | var index = Methanal.Util.arrayIndexOf(self.options, before); | ||
26 | 22 | if (index == -1) { | ||
27 | 23 | index = self.options.length; | ||
28 | 24 | self.options.push(element); | ||
29 | 25 | } else { | ||
30 | 26 | self.options.splice(index, 0, element); | ||
31 | 27 | } | ||
32 | 28 | element.index = index; | ||
33 | 29 | }); | ||
34 | 30 | |||
35 | 31 | |||
36 | 32 | |||
37 | 33 | /** | ||
38 | 34 | * HTMLDocument mock implementation. | ||
39 | 35 | */ | ||
40 | 36 | Divmod.MockBrowser.Document.subclass( | ||
41 | 37 | Methanal.Tests.DOMUtil, 'Document').methods( | ||
42 | 38 | function __init__(self) { | ||
43 | 39 | self._elementTags = {}; | ||
44 | 40 | Methanal.Tests.DOMUtil.Document.upcall(self, '__init__'); | ||
45 | 41 | }, | ||
46 | 42 | |||
47 | 43 | |||
48 | 44 | /** | ||
49 | 45 | * Register a new type for a tag name. | ||
50 | 46 | */ | ||
51 | 47 | function registerElementTag(self, tagName, type) { | ||
52 | 48 | var old = self._elementTags[tagName]; | ||
53 | 49 | self._elementTags[tagName] = type; | ||
54 | 50 | return old; | ||
55 | 51 | }, | ||
56 | 52 | |||
57 | 53 | |||
58 | 54 | function createElement(self, tagName) { | ||
59 | 55 | var el; | ||
60 | 56 | if (self._elementTags[tagName]) { | ||
61 | 57 | el = self._elementTags[tagName](); | ||
62 | 58 | } else { | ||
63 | 59 | el = Divmod.MockBrowser.Element(tagName); | ||
64 | 60 | } | ||
65 | 61 | el._setOwnerDocument(self); | ||
66 | 62 | self._allElements.push(el); | ||
67 | 63 | return el; | ||
68 | 64 | }); | ||
69 | 65 | |||
70 | 66 | |||
71 | 67 | |||
72 | 68 | // Only override Divmod's mock document. | ||
73 | 69 | if (document instanceof Divmod.MockBrowser.Document) { | ||
74 | 70 | if (!(document instanceof Methanal.Tests.DOMUtil.Document)) { | ||
75 | 71 | document = Methanal.Tests.DOMUtil.Document(); | ||
76 | 72 | document.registerElementTag( | ||
77 | 73 | 'select', Methanal.Tests.DOMUtil.MockHTMLSelectElement); | ||
78 | 74 | } | ||
79 | 75 | } | ||
80 | 76 | 0 | ||
81 | === added file 'methanal/js/Methanal/Tests/MockBrowser.js' | |||
82 | --- methanal/js/Methanal/Tests/MockBrowser.js 1970-01-01 00:00:00 +0000 | |||
83 | +++ methanal/js/Methanal/Tests/MockBrowser.js 2009-10-12 17:06:10 +0000 | |||
84 | @@ -0,0 +1,102 @@ | |||
85 | 1 | // import Divmod.MockBrowser | ||
86 | 2 | |||
87 | 3 | |||
88 | 4 | |||
89 | 5 | Divmod.MockBrowser.Element.subclass( | ||
90 | 6 | Methanal.Tests.MockBrowser, 'Element').methods( | ||
91 | 7 | function __init__(self, tagName) { | ||
92 | 8 | Methanal.Tests.MockBrowser.Element.upcall(self, '__init__', tagName); | ||
93 | 9 | self._updateChildProperties(); | ||
94 | 10 | }, | ||
95 | 11 | |||
96 | 12 | |||
97 | 13 | function _updateChildProperties(self) { | ||
98 | 14 | self.firstChild = self.childNodes[0] || null; | ||
99 | 15 | self.lastChild = self.childNodes[self.childNodes.length - 1] || null; | ||
100 | 16 | }, | ||
101 | 17 | |||
102 | 18 | |||
103 | 19 | function appendChild(self, child) { | ||
104 | 20 | Methanal.Tests.MockBrowser.Element.upcall(self, 'appendChild', child); | ||
105 | 21 | self._updateChildProperties(); | ||
106 | 22 | }, | ||
107 | 23 | |||
108 | 24 | |||
109 | 25 | function removeChild(self, child) { | ||
110 | 26 | Methanal.Tests.MockBrowser.Element.upcall(self, 'removeChild', child); | ||
111 | 27 | self._updateChildProperties(); | ||
112 | 28 | }); | ||
113 | 29 | |||
114 | 30 | |||
115 | 31 | |||
116 | 32 | /** | ||
117 | 33 | * HTMLSelectElement mock implementation. | ||
118 | 34 | */ | ||
119 | 35 | Methanal.Tests.MockBrowser.Element.subclass( | ||
120 | 36 | Methanal.Tests.MockBrowser, 'MockHTMLSelectElement').methods( | ||
121 | 37 | function __init__(self) { | ||
122 | 38 | Methanal.Tests.MockBrowser.MockHTMLSelectElement.upcall( | ||
123 | 39 | self, '__init__', 'select'); | ||
124 | 40 | self.options = []; | ||
125 | 41 | }, | ||
126 | 42 | |||
127 | 43 | |||
128 | 44 | /** | ||
129 | 45 | * Add a new element to the collection of OPTION elements for this SELECT. | ||
130 | 46 | */ | ||
131 | 47 | function add(self, element, before) { | ||
132 | 48 | var index = Methanal.Util.arrayIndexOf(self.options, before); | ||
133 | 49 | if (index == -1) { | ||
134 | 50 | index = self.options.length; | ||
135 | 51 | self.options.push(element); | ||
136 | 52 | } else { | ||
137 | 53 | self.options.splice(index, 0, element); | ||
138 | 54 | } | ||
139 | 55 | element.index = index; | ||
140 | 56 | }); | ||
141 | 57 | |||
142 | 58 | |||
143 | 59 | |||
144 | 60 | /** | ||
145 | 61 | * HTMLDocument mock implementation. | ||
146 | 62 | */ | ||
147 | 63 | Divmod.MockBrowser.Document.subclass( | ||
148 | 64 | Methanal.Tests.MockBrowser, 'Document').methods( | ||
149 | 65 | function __init__(self) { | ||
150 | 66 | self._elementTags = {}; | ||
151 | 67 | Methanal.Tests.MockBrowser.Document.upcall(self, '__init__'); | ||
152 | 68 | }, | ||
153 | 69 | |||
154 | 70 | |||
155 | 71 | /** | ||
156 | 72 | * Register a new type for a tag name. | ||
157 | 73 | */ | ||
158 | 74 | function registerElementTag(self, tagName, type) { | ||
159 | 75 | var old = self._elementTags[tagName]; | ||
160 | 76 | self._elementTags[tagName] = type; | ||
161 | 77 | return old; | ||
162 | 78 | }, | ||
163 | 79 | |||
164 | 80 | |||
165 | 81 | function createElement(self, tagName) { | ||
166 | 82 | var el; | ||
167 | 83 | if (self._elementTags[tagName]) { | ||
168 | 84 | el = self._elementTags[tagName](); | ||
169 | 85 | } else { | ||
170 | 86 | el = Methanal.Tests.MockBrowser.Element(tagName); | ||
171 | 87 | } | ||
172 | 88 | el._setOwnerDocument(self); | ||
173 | 89 | self._allElements.push(el); | ||
174 | 90 | return el; | ||
175 | 91 | }); | ||
176 | 92 | |||
177 | 93 | |||
178 | 94 | |||
179 | 95 | // Only override Divmod's mock document. | ||
180 | 96 | if (document instanceof Divmod.MockBrowser.Document) { | ||
181 | 97 | if (!(document instanceof Methanal.Tests.MockBrowser.Document)) { | ||
182 | 98 | document = Methanal.Tests.MockBrowser.Document(); | ||
183 | 99 | document.registerElementTag( | ||
184 | 100 | 'select', Methanal.Tests.MockBrowser.MockHTMLSelectElement); | ||
185 | 101 | } | ||
186 | 102 | } | ||
187 | 0 | 103 | ||
188 | === modified file 'methanal/js/Methanal/Tests/TestUtil.js' | |||
189 | --- methanal/js/Methanal/Tests/TestUtil.js 2009-10-10 10:28:01 +0000 | |||
190 | +++ methanal/js/Methanal/Tests/TestUtil.js 2009-10-12 17:06:10 +0000 | |||
191 | @@ -1,11 +1,184 @@ | |||
192 | 1 | // import Divmod.UnitTest | 1 | // import Divmod.UnitTest |
193 | 2 | // import Divmod.MockBrowser | ||
194 | 3 | // import Methanal.Util | 2 | // import Methanal.Util |
195 | 4 | // import Methanal.Tests.Util | 3 | // import Methanal.Tests.Util |
200 | 5 | 4 | // import Methanal.Tests.MockBrowser | |
201 | 6 | 5 | ||
202 | 7 | 6 | ||
203 | 8 | Divmod.UnitTest.TestCase.subclass(Methanal.Tests.TestUtil, 'TestUtil').methods( | 7 | |
204 | 8 | Methanal.Tests.Util.TestCase.subclass( | ||
205 | 9 | Methanal.Tests.TestUtil, 'TestUtil').methods( | ||
206 | 10 | /** | ||
207 | 11 | * L{Methanal.Util.addElementClass} and L{Methanal.Util.removeElementClass} | ||
208 | 12 | * add and remove values to an element's C{className} attribute. | ||
209 | 13 | */ | ||
210 | 14 | function test_addRemoveElementClass(self) { | ||
211 | 15 | var node = document.createElement('div'); | ||
212 | 16 | var addElementClass = Methanal.Util.addElementClass; | ||
213 | 17 | var removeElementClass = Methanal.Util.removeElementClass; | ||
214 | 18 | |||
215 | 19 | addElementClass(node, 'foo'); | ||
216 | 20 | self.assertIdentical(node.className, 'foo'); | ||
217 | 21 | addElementClass(node, 'foo'); | ||
218 | 22 | self.assertIdentical(node.className, 'foo'); | ||
219 | 23 | |||
220 | 24 | addElementClass(node, 'bar'); | ||
221 | 25 | self.assertIdentical(node.className, 'foo bar'); | ||
222 | 26 | |||
223 | 27 | removeElementClass(node, 'foo'); | ||
224 | 28 | self.assertIdentical(node.className, 'bar'); | ||
225 | 29 | |||
226 | 30 | removeElementClass(node, 'bar'); | ||
227 | 31 | self.assertIdentical(node.className, ''); | ||
228 | 32 | |||
229 | 33 | removeElementClass(node, 'bar'); | ||
230 | 34 | self.assertIdentical(node.className, ''); | ||
231 | 35 | }, | ||
232 | 36 | |||
233 | 37 | |||
234 | 38 | /** | ||
235 | 39 | * Create a DOM node with some children. | ||
236 | 40 | */ | ||
237 | 41 | function _makeNodeWithChildren(self) { | ||
238 | 42 | var T = Methanal.Util.DOMBuilder(document); | ||
239 | 43 | var node = T('div', {}, [ | ||
240 | 44 | T('span', {}, ['hello ', | ||
241 | 45 | T('strong', {}, 'world')]), | ||
242 | 46 | T('em', {}, ['!'])]); | ||
243 | 47 | self.assertIdentical(node.childNodes.length, 2); | ||
244 | 48 | return node; | ||
245 | 49 | }, | ||
246 | 50 | |||
247 | 51 | |||
248 | 52 | /** | ||
249 | 53 | * L{Methanal.Util.removeNodeContent} removes all of a node's children. | ||
250 | 54 | */ | ||
251 | 55 | function test_removeNodeContent(self) { | ||
252 | 56 | var node = self._makeNodeWithChildren(); | ||
253 | 57 | Methanal.Util.removeNodeContent(node); | ||
254 | 58 | self.assertIdentical(node.childNodes.length, 0); | ||
255 | 59 | }, | ||
256 | 60 | |||
257 | 61 | |||
258 | 62 | /** | ||
259 | 63 | * L{Methanal.Util.replaceNodeContent} replaces a node's children with | ||
260 | 64 | * some other children. | ||
261 | 65 | */ | ||
262 | 66 | function test_replaceNodeContent(self) { | ||
263 | 67 | var T = Methanal.Util.DOMBuilder(document); | ||
264 | 68 | var node = self._makeNodeWithChildren(); | ||
265 | 69 | var children = [T('strong', {}, ['yay'])]; | ||
266 | 70 | Methanal.Util.replaceNodeContent(node, children); | ||
267 | 71 | self.assertArraysEqual(node.childNodes, children); | ||
268 | 72 | }, | ||
269 | 73 | |||
270 | 74 | |||
271 | 75 | /** | ||
272 | 76 | * L{Methanal.Util.replaceNodeText} replaces a node's content with a text | ||
273 | 77 | * node. | ||
274 | 78 | */ | ||
275 | 79 | function test_replaceNodeText(self) { | ||
276 | 80 | var node = self._makeNodeWithChildren(); | ||
277 | 81 | Methanal.Util.replaceNodeText(node, 'hey'); | ||
278 | 82 | self.assertIdentical(node.childNodes.length, 1); | ||
279 | 83 | self.assertIsInstanceOf(node.firstChild, Divmod.MockBrowser.TextNode); | ||
280 | 84 | }, | ||
281 | 85 | |||
282 | 86 | |||
283 | 87 | /** | ||
284 | 88 | * L{Methanal.Util.formatDecimal} pretty-prints a number with thousand | ||
285 | 89 | * separators. | ||
286 | 90 | */ | ||
287 | 91 | function test_formatDecimal(self) { | ||
288 | 92 | var formatDecimal = Methanal.Util.formatDecimal; | ||
289 | 93 | self.assertIdentical(formatDecimal(1), '1'); | ||
290 | 94 | self.assertIdentical(formatDecimal(100), '100'); | ||
291 | 95 | self.assertIdentical(formatDecimal(1000), '1,000'); | ||
292 | 96 | self.assertIdentical(formatDecimal(10000), '10,000'); | ||
293 | 97 | self.assertIdentical(formatDecimal(1000000), '1,000,000'); | ||
294 | 98 | |||
295 | 99 | self.assertIdentical(formatDecimal(1000.25), '1,000.25'); | ||
296 | 100 | self.assertIdentical(formatDecimal(1000000.66), '1,000,000.66'); | ||
297 | 101 | }, | ||
298 | 102 | |||
299 | 103 | |||
300 | 104 | /** | ||
301 | 105 | * L{Methanal.Util.cycle} produces a callable that iterates through | ||
302 | 106 | * the original arguments indefinitely. | ||
303 | 107 | */ | ||
304 | 108 | function test_cycle(self) { | ||
305 | 109 | var cycler = Methanal.Util.cycle(42, 5144, 'a'); | ||
306 | 110 | self.assertIdentical(cycler(), 42); | ||
307 | 111 | self.assertIdentical(cycler(), 5144); | ||
308 | 112 | self.assertIdentical(cycler(), 'a'); | ||
309 | 113 | self.assertIdentical(cycler(), 42); | ||
310 | 114 | }, | ||
311 | 115 | |||
312 | 116 | |||
313 | 117 | /** | ||
314 | 118 | * L{Methanal.Util.arrayIndexOf} finds the first index of an element in an | ||
315 | 119 | * array, or C{-1} if no such element exists. | ||
316 | 120 | */ | ||
317 | 121 | function test_arrayIndexOf(self) { | ||
318 | 122 | var arrayIndexOf = Methanal.Util.arrayIndexOf; | ||
319 | 123 | var a = ['x', 'y', 'z', 'x']; | ||
320 | 124 | self.assertIdentical(arrayIndexOf(a, 'x'), 0); | ||
321 | 125 | self.assertIdentical(arrayIndexOf(a, 'y'), 1); | ||
322 | 126 | self.assertIdentical(arrayIndexOf(a, 'z'), 2); | ||
323 | 127 | self.assertIdentical(arrayIndexOf(a, 'a'), -1); | ||
324 | 128 | }, | ||
325 | 129 | |||
326 | 130 | |||
327 | 131 | /** | ||
328 | 132 | * L{Methanal.Util.nodeInserted} calls a widget's C{nodeInserted} method | ||
329 | 133 | * and the C{nodeInserted} method of each child widget. | ||
330 | 134 | */ | ||
331 | 135 | function test_nodeInserted(self) { | ||
332 | 136 | function makeWidget(childWidgets) { | ||
333 | 137 | return { | ||
334 | 138 | 'childWidgets': childWidgets, | ||
335 | 139 | 'nodeInserted': function () { | ||
336 | 140 | this.nodeInserted = true; | ||
337 | 141 | }}; | ||
338 | 142 | }; | ||
339 | 143 | |||
340 | 144 | var childWidgets = []; | ||
341 | 145 | for (var i = 0; i < 5; ++i) { | ||
342 | 146 | childWidgets.push(makeWidget([])); | ||
343 | 147 | } | ||
344 | 148 | var widget = makeWidget(childWidgets); | ||
345 | 149 | |||
346 | 150 | Methanal.Util.nodeInserted(widget); | ||
347 | 151 | self.assertIdentical(widget.nodeInserted, true); | ||
348 | 152 | for (var i = 0; i < childWidgets.length; ++i) { | ||
349 | 153 | self.assertIdentical(childWidgets[i].nodeInserted, true); | ||
350 | 154 | } | ||
351 | 155 | }, | ||
352 | 156 | |||
353 | 157 | |||
354 | 158 | /** | ||
355 | 159 | * L{Methanal.Util.repr} converts an object to a human-readable string. | ||
356 | 160 | */ | ||
357 | 161 | function test_repr(self) { | ||
358 | 162 | var repr = Methanal.Util.repr; | ||
359 | 163 | self.assertIdentical(repr('a'), '"a"'); | ||
360 | 164 | self.assertIdentical(repr('a"b"c'), '"a\\"b\\"c"'); | ||
361 | 165 | self.assertIdentical(repr(1), '1'); | ||
362 | 166 | self.assertIdentical(repr(null), 'null'); | ||
363 | 167 | self.assertIdentical(repr(undefined), 'undefined'); | ||
364 | 168 | self.assertIdentical(repr(repr), '<function repr>'); | ||
365 | 169 | var a = [1, 2, 3, 'a', ['b', '"c"']]; | ||
366 | 170 | self.assertIdentical(repr(a), '[1, 2, 3, "a", ["b", "\\"c\\""]]'); | ||
367 | 171 | var o = {a: 1}; | ||
368 | 172 | self.assertIdentical(repr(o), '{"a": 1}'); | ||
369 | 173 | var o2 = {a: 1, b: 2}; | ||
370 | 174 | self.assertIdentical(repr(o2), '{"a": 1, "b": 2}'); | ||
371 | 175 | |||
372 | 176 | var type = Divmod.Class.subclass('Foo'); | ||
373 | 177 | var i = type(); | ||
374 | 178 | self.assertIdentical(repr(i), i.toString()); | ||
375 | 179 | }, | ||
376 | 180 | |||
377 | 181 | |||
378 | 9 | /** | 182 | /** |
379 | 10 | * L{Methanal.Util.strToInt} converts a base-10 integer value, represented | 183 | * L{Methanal.Util.strToInt} converts a base-10 integer value, represented |
380 | 11 | * as a C{String}, to an C{Integer}. | 184 | * as a C{String}, to an C{Integer}. |
381 | 12 | 185 | ||
382 | === modified file 'methanal/js/Methanal/Tests/TestView.js' | |||
383 | --- methanal/js/Methanal/Tests/TestView.js 2009-10-10 10:28:01 +0000 | |||
384 | +++ methanal/js/Methanal/Tests/TestView.js 2009-10-12 17:06:10 +0000 | |||
385 | @@ -3,7 +3,7 @@ | |||
386 | 3 | // import Methanal.View | 3 | // import Methanal.View |
387 | 4 | // import Methanal.Util | 4 | // import Methanal.Util |
388 | 5 | // import Methanal.Tests.Util | 5 | // import Methanal.Tests.Util |
390 | 6 | // import Methanal.Tests.DOMUtil | 6 | // import Methanal.Tests.MockBrowser |
391 | 7 | 7 | ||
392 | 8 | 8 | ||
393 | 9 | 9 | ||
394 | @@ -374,7 +374,7 @@ | |||
395 | 374 | /** | 374 | /** |
396 | 375 | * Mimic Internet Explorer's broken C{HTMLSelectElement.add} behaviour. | 375 | * Mimic Internet Explorer's broken C{HTMLSelectElement.add} behaviour. |
397 | 376 | */ | 376 | */ |
399 | 377 | Methanal.Tests.DOMUtil.MockHTMLSelectElement.subclass( | 377 | Methanal.Tests.MockBrowser.MockHTMLSelectElement.subclass( |
400 | 378 | Methanal.Tests.TestView, 'MockIEHTMLSelectElement').methods( | 378 | Methanal.Tests.TestView, 'MockIEHTMLSelectElement').methods( |
401 | 379 | function add(self, element, before) { | 379 | function add(self, element, before) { |
402 | 380 | if (before === null) { | 380 | if (before === null) { |
403 | 381 | 381 | ||
404 | === modified file 'methanal/js/Methanal/Util.js' | |||
405 | --- methanal/js/Methanal/Util.js 2009-10-10 10:28:01 +0000 | |||
406 | +++ methanal/js/Methanal/Util.js 2009-10-12 17:06:10 +0000 | |||
407 | @@ -1,7 +1,3 @@ | |||
408 | 1 | // import Nevow.Athena | ||
409 | 2 | |||
410 | 3 | |||
411 | 4 | |||
412 | 5 | /** | 1 | /** |
413 | 6 | * Add a class to an element's "className" attribute. | 2 | * Add a class to an element's "className" attribute. |
414 | 7 | * | 3 | * |
415 | @@ -95,7 +91,7 @@ | |||
416 | 95 | * | 91 | * |
417 | 96 | * @type node: DOM node | 92 | * @type node: DOM node |
418 | 97 | * | 93 | * |
420 | 98 | * @type children: C{Array} | 94 | * @type children: C{Array} of C{DOM nodes} |
421 | 99 | */ | 95 | */ |
422 | 100 | Methanal.Util.replaceNodeContent = function replaceNodeContent(node, children) { | 96 | Methanal.Util.replaceNodeContent = function replaceNodeContent(node, children) { |
423 | 101 | Methanal.Util.removeNodeContent(node); | 97 | Methanal.Util.removeNodeContent(node); |
424 | @@ -107,7 +103,7 @@ | |||
425 | 107 | 103 | ||
426 | 108 | 104 | ||
427 | 109 | /** | 105 | /** |
429 | 110 | * Replace a node's text node with new text. | 106 | * Replace all of a node's content with text. |
430 | 111 | * | 107 | * |
431 | 112 | * @type node: DOM node | 108 | * @type node: DOM node |
432 | 113 | * | 109 | * |
433 | @@ -308,7 +304,20 @@ | |||
434 | 308 | return '<function ' + o.name + '>'; | 304 | return '<function ' + o.name + '>'; |
435 | 309 | } | 305 | } |
436 | 310 | } else if (o instanceof Array) { | 306 | } else if (o instanceof Array) { |
438 | 311 | return o.toSource(); | 307 | var names = Methanal.Util.map(Methanal.Util.repr, o); |
439 | 308 | return '[' + names.join(', ') + ']'; | ||
440 | 309 | } else { | ||
441 | 310 | if (o.constructor !== undefined && o.constructor.name !== undefined) { | ||
442 | 311 | var typeName = o.constructor.name; | ||
443 | 312 | if (typeName == 'Object') { | ||
444 | 313 | var names = []; | ||
445 | 314 | var repr = Methanal.Util.repr; | ||
446 | 315 | for (var key in o) { | ||
447 | 316 | names.push(repr(key) + ': ' + repr(o[key])); | ||
448 | 317 | } | ||
449 | 318 | return '{' + names.join(', ') + '}'; | ||
450 | 319 | } | ||
451 | 320 | } | ||
452 | 312 | } | 321 | } |
453 | 313 | return o.toString(); | 322 | return o.toString(); |
454 | 314 | }; | 323 | }; |