Index: trunk/parsers/wikidom/tests/index.html |
— | — | @@ -1,23 +0,0 @@ |
2 | | -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
3 | | - "http://www.w3.org/TR/html4/loose.dtd"> |
4 | | -<html> |
5 | | - <head> |
6 | | - <title>Wikidom Tests</title> |
7 | | - <link rel="stylesheet" href="../lib/qunit.css" type="text/css" /> |
8 | | - </head> |
9 | | - <body> |
10 | | - <h1 id="qunit-header">Wikidom Tests</h1> |
11 | | - <h2 id="qunit-banner"></h2> |
12 | | - <h2 id="qunit-userAgent"></h2> |
13 | | - <ol id="qunit-tests"></ol> |
14 | | - <script src="../lib/jquery.js" type="text/javascript"></script> |
15 | | - <script src="../lib/qunit.js" type="text/javascript"></script> |
16 | | - <script src="../lib/wiki.js" type="text/javascript"></script> |
17 | | - <script src="../lib/wiki.util.js" type="text/javascript"></script> |
18 | | - <script src="../lib/wiki.Context.js" type="text/javascript"></script> |
19 | | - <script src="../lib/wiki.AnnotationRenderer.js" type="text/javascript"></script> |
20 | | - <script src="../lib/wiki.HtmlRenderer.js" type="text/javascript"></script> |
21 | | - <script src="../lib/wiki.WikitextRenderer.js" type="text/javascript"></script> |
22 | | - <script src="wiki.test.js" type="text/javascript"></script> |
23 | | - </body> |
24 | | -</html> |
Index: trunk/parsers/wikidom/tests/wiki.test.js |
— | — | @@ -1,339 +0,0 @@ |
2 | | -module( 'Wiki DOM Serialization' ); |
3 | | - |
4 | | -var context = new wiki.Context(); |
5 | | - |
6 | | -function assertSerializations( tests ) { |
7 | | - var htmlRenderer = new wiki.HtmlRenderer( context ); |
8 | | - var wikitextRenderer = new wiki.WikitextRenderer( context ); |
9 | | - for ( var i = 0; i < tests.length; i++ ) { |
10 | | - equals( |
11 | | - htmlRenderer.render( tests[i].dom ), |
12 | | - tests[i].html, |
13 | | - 'Serialize ' + tests[i].subject + ' to HTML' |
14 | | - ); |
15 | | - } |
16 | | - for ( var i = 0; i < tests.length; i++ ) { |
17 | | - equals( |
18 | | - wikitextRenderer.render( tests[i].dom ), |
19 | | - tests[i].wikitext, |
20 | | - 'Serialize ' + tests[i].subject + ' to Wikitext' |
21 | | - ); |
22 | | - } |
23 | | -} |
24 | | - |
25 | | -test( 'Comments', function() { |
26 | | - assertSerializations( [ |
27 | | - { |
28 | | - 'subject': 'comment', |
29 | | - 'dom': { 'blocks': [ { |
30 | | - 'type': 'comment', |
31 | | - 'text': 'Hello world!' |
32 | | - } ] }, |
33 | | - 'html': '<!--Hello world!-->', |
34 | | - 'wikitext': '<!--Hello world!-->' |
35 | | - } |
36 | | - ] ); |
37 | | -} ); |
38 | | - |
39 | | -test( 'Horizontal rules', function() { |
40 | | - assertSerializations( [ |
41 | | - { |
42 | | - 'subject': 'horizontal rule', |
43 | | - 'dom': { 'blocks': [ { |
44 | | - 'type': 'horizontal-rule', |
45 | | - } ] }, |
46 | | - 'html': '<hr />', |
47 | | - 'wikitext': '----' |
48 | | - } |
49 | | - ] ); |
50 | | -} ); |
51 | | - |
52 | | -test( 'Headings', function() { |
53 | | - assertSerializations( [ |
54 | | - { |
55 | | - 'subject': 'level 1 heading', |
56 | | - 'dom': { 'blocks': [ { |
57 | | - 'type': 'heading', |
58 | | - 'level': 1, |
59 | | - 'line': { 'text': 'Heading 1' } |
60 | | - } ] }, |
61 | | - 'html': '<h1>Heading 1</h1>', |
62 | | - 'wikitext': '=Heading 1=' |
63 | | - }, |
64 | | - { |
65 | | - 'subject': 'level 2 heading', |
66 | | - 'dom': { 'blocks': [ { |
67 | | - 'type': 'heading', |
68 | | - 'level': 2, |
69 | | - 'line': { 'text': 'Heading 2' } |
70 | | - } ] }, |
71 | | - 'html': '<h2>Heading 2</h2>', |
72 | | - 'wikitext': '==Heading 2==' |
73 | | - }, |
74 | | - { |
75 | | - 'subject': 'level 3 heading', |
76 | | - 'dom': { 'blocks': [ { |
77 | | - 'type': 'heading', |
78 | | - 'level': 3, |
79 | | - 'line': { 'text': 'Heading 3' } |
80 | | - } ] }, |
81 | | - 'html': '<h3>Heading 3</h3>', |
82 | | - 'wikitext': '===Heading 3===' |
83 | | - }, |
84 | | - { |
85 | | - 'subject': 'level 4 heading', |
86 | | - 'dom': { 'blocks': [ { |
87 | | - 'type': 'heading', |
88 | | - 'level': 4, |
89 | | - 'line': { 'text': 'Heading 4' } |
90 | | - } ] }, |
91 | | - 'html': '<h4>Heading 4</h4>', |
92 | | - 'wikitext': '====Heading 4====' |
93 | | - }, |
94 | | - { |
95 | | - 'subject': 'level 5 heading', |
96 | | - 'dom': { 'blocks': [ { |
97 | | - 'type': 'heading', |
98 | | - 'level': 5, |
99 | | - 'line': { 'text': 'Heading 5' } |
100 | | - } ] }, |
101 | | - 'html': '<h5>Heading 5</h5>', |
102 | | - 'wikitext': '=====Heading 5=====' |
103 | | - }, |
104 | | - { |
105 | | - 'subject': 'level 6 heading', |
106 | | - 'dom': { 'blocks': [ { |
107 | | - 'type': 'heading', |
108 | | - 'level': 6, |
109 | | - 'line': { 'text': 'Heading 6' } |
110 | | - } ] }, |
111 | | - 'html': '<h6>Heading 6</h6>', |
112 | | - 'wikitext': '======Heading 6======' |
113 | | - }, |
114 | | - { |
115 | | - 'subject': 'level 1 heading with annotated text', |
116 | | - 'dom': { 'blocks': [ { |
117 | | - 'type': 'heading', |
118 | | - 'level': 1, |
119 | | - 'line': { |
120 | | - 'text': 'Heading with a link', |
121 | | - 'annotations': [ |
122 | | - { |
123 | | - 'type': 'ilink', |
124 | | - 'range': { 'offset': 15, 'length': 4 }, |
125 | | - 'data': { 'namespace': 'Main', 'title': 'Main_Page' } |
126 | | - } |
127 | | - ] |
128 | | - } |
129 | | - } ] }, |
130 | | - 'html': '<h1>Heading with a <a href="https://www.mediawiki.org/wiki/Main_Page">link</a></h1>', |
131 | | - 'wikitext': '=Heading with a [[Main_Page|link]]=' |
132 | | - }, |
133 | | - ] ); |
134 | | -} ); |
135 | | - |
136 | | -test( 'Paragraphs', function() { |
137 | | - assertSerializations( [ |
138 | | - { |
139 | | - 'subject': 'paragraph with a single line of plain text', |
140 | | - 'dom': { 'blocks': [ { |
141 | | - 'type': 'paragraph', |
142 | | - 'lines': [ { 'text': 'Line with plain text' } ] |
143 | | - } ] }, |
144 | | - 'html': '<p>Line with plain text</p>', |
145 | | - 'wikitext': 'Line with plain text' |
146 | | - }, |
147 | | - { |
148 | | - 'subject': 'paragraph with multiple lines of plain text', |
149 | | - 'dom': { 'blocks': [ { |
150 | | - 'type': 'paragraph', |
151 | | - 'lines': [ |
152 | | - { 'text': 'Line with plain text' }, |
153 | | - { 'text': 'Line with more plain text' } |
154 | | - ] |
155 | | - } ] }, |
156 | | - 'html': '<p>Line with plain text\nLine with more plain text</p>', |
157 | | - 'wikitext': 'Line with plain text\nLine with more plain text' |
158 | | - }, |
159 | | - { |
160 | | - 'subject': 'paragraph with a single line of annotated text', |
161 | | - 'dom': { 'blocks': [ { |
162 | | - 'type': 'paragraph', |
163 | | - 'lines': [ |
164 | | - { |
165 | | - 'text': 'Line with bold and italic text', |
166 | | - 'annotations': [ |
167 | | - { 'type': 'bold', 'range': { 'offset': 10, 'length': 4 } }, |
168 | | - { 'type': 'italic', 'range': { 'offset': 19, 'length': 6 } } |
169 | | - ] |
170 | | - } |
171 | | - ] |
172 | | - } ] }, |
173 | | - 'html': '<p>Line with <strong>bold</strong> and <em>italic</em> text</p>', |
174 | | - 'wikitext': 'Line with \'\'\'bold\'\'\' and \'\'italic\'\' text' |
175 | | - } |
176 | | - ] ); |
177 | | -} ); |
178 | | - |
179 | | -// Lists |
180 | | -test( 'Lists', function() { |
181 | | - assertSerializations( [ |
182 | | - { |
183 | | - 'subject': 'numbered list', |
184 | | - 'dom': { 'blocks': [ { |
185 | | - 'type': 'list', |
186 | | - 'style': 'number', |
187 | | - 'items': [ |
188 | | - { 'line': { 'text': '1' } }, |
189 | | - { 'line': { 'text': '2' } }, |
190 | | - { 'line': { 'text': '3' } } |
191 | | - ] |
192 | | - } ] }, |
193 | | - 'html': '<ol>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ol>', |
194 | | - 'wikitext': '# 1\n# 2\n# 3' |
195 | | - }, |
196 | | - { |
197 | | - 'subject': 'bulleted list', |
198 | | - 'dom': { 'blocks': [ { |
199 | | - 'type': 'list', |
200 | | - 'style': 'bullet', |
201 | | - 'items': [ |
202 | | - { 'line': { 'text': '1' } }, |
203 | | - { 'line': { 'text': '2' } }, |
204 | | - { 'line': { 'text': '3' } } |
205 | | - ] |
206 | | - } ] }, |
207 | | - 'html': '<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>', |
208 | | - 'wikitext': '* 1\n* 2\n* 3' |
209 | | - }, |
210 | | - { |
211 | | - 'subject': 'mixed-style nested lists', |
212 | | - 'dom': { 'blocks': [ { |
213 | | - 'type': 'list', |
214 | | - 'style': 'bullet', |
215 | | - 'items': [ |
216 | | - { |
217 | | - 'line': { 'text': '1' }, |
218 | | - 'lists': [ |
219 | | - { |
220 | | - 'style': 'number', |
221 | | - 'items': [ |
222 | | - { 'line': { 'text': '1.1' } }, |
223 | | - { 'line': { 'text': '1.2' } }, |
224 | | - { 'line': { 'text': '1.3' } } |
225 | | - ] |
226 | | - } |
227 | | - ] |
228 | | - }, |
229 | | - { 'line': { 'text': '2' } } |
230 | | - ] |
231 | | - } ] }, |
232 | | - 'html': '<ul>\n<li>1\n<ol>\n<li>1.1</li>\n<li>1.2</li>\n<li>1.3</li>\n</ol>' |
233 | | - + '\n</li>\n<li>2</li>\n</ul>', |
234 | | - 'wikitext': '* 1\n*# 1.1\n*# 1.2\n*# 1.3\n* 2' |
235 | | - } |
236 | | - ] ); |
237 | | -} ); |
238 | | - |
239 | | -// Tables |
240 | | -test( 'Tables', function() { |
241 | | - assertSerializations( [ |
242 | | - { |
243 | | - 'subject': 'table with headings and data', |
244 | | - 'dom': { 'blocks': [{ |
245 | | - 'type': 'table', |
246 | | - 'rows': [ |
247 | | - [ |
248 | | - { |
249 | | - 'type': 'heading', |
250 | | - 'document': { 'blocks': [{ |
251 | | - 'type': 'paragraph', |
252 | | - 'lines': [{ 'text': 'A' }] |
253 | | - }] } |
254 | | - }, |
255 | | - { |
256 | | - 'type': 'heading', |
257 | | - 'document': { 'blocks': [{ |
258 | | - 'type': 'paragraph', |
259 | | - 'lines': [{ 'text': 'B' }] |
260 | | - }] } |
261 | | - } |
262 | | - ], |
263 | | - [ |
264 | | - { |
265 | | - 'type': 'data', |
266 | | - 'document': { 'blocks': [{ |
267 | | - 'type': 'paragraph', |
268 | | - 'lines': [{ 'text': '1' }] |
269 | | - }] } |
270 | | - }, |
271 | | - { |
272 | | - 'type': 'data', |
273 | | - 'document': { 'blocks': [{ |
274 | | - 'type': 'paragraph', |
275 | | - 'lines': [{ 'text': '2' }] |
276 | | - }] } |
277 | | - } |
278 | | - ] |
279 | | - ] |
280 | | - }] }, |
281 | | - 'html': '<table>\n<tr>\n<th>A</th>\n<th>B</th>\n</tr>\n<tr>\n' |
282 | | - + '<td>1</td>\n<td>2</td>\n</tr>\n</table>', |
283 | | - 'wikitext': '{|\n!A\n!B\n|-\n|1\n|2\n|}' |
284 | | - }, |
285 | | - { |
286 | | - 'subject': 'table with attributes', |
287 | | - 'dom': { 'blocks': [{ |
288 | | - 'type': 'table', |
289 | | - 'attributes': { |
290 | | - 'class': 'wikitable' |
291 | | - }, |
292 | | - 'rows': [ |
293 | | - [ |
294 | | - { |
295 | | - 'type': 'data', |
296 | | - 'attributes': { |
297 | | - 'class': 'abc' |
298 | | - }, |
299 | | - 'document': { 'blocks': [{ |
300 | | - 'type': 'paragraph', |
301 | | - 'lines': [{ 'text': 'abc' }] |
302 | | - }] } |
303 | | - } |
304 | | - ] |
305 | | - ] |
306 | | - }] }, |
307 | | - 'html': '<table class="wikitable">\n<tr>\n<td class="abc">abc</td>\n</tr>\n</table>', |
308 | | - 'wikitext': '{|class="wikitable"\n|class="abc"|abc\n|}' |
309 | | - } |
310 | | - ] ); |
311 | | -} ); |
312 | | - |
313 | | -test( 'Transclusion', function() { |
314 | | - assertSerializations( [ |
315 | | - { |
316 | | - 'subject': 'transclusion', |
317 | | - 'dom': { 'blocks': [ { |
318 | | - 'type': 'transclusion', |
319 | | - 'namespace': 'Template', |
320 | | - 'title': 'Test' |
321 | | - } ] }, |
322 | | - 'html': '<a href="https://www.mediawiki.org/wiki/Template:Test">Template:Test</a>', |
323 | | - 'wikitext': '{{Test}}' |
324 | | - } |
325 | | - ] ); |
326 | | -} ); |
327 | | - |
328 | | -test( 'Parameter', function() { |
329 | | - assertSerializations( [ |
330 | | - { |
331 | | - 'subject': 'transclusion', |
332 | | - 'dom': { 'blocks': [ { |
333 | | - 'type': 'parameter', |
334 | | - 'name': '1' |
335 | | - } ] }, |
336 | | - 'html': '{{{1}}}', |
337 | | - 'wikitext': '{{{1}}}' |
338 | | - } |
339 | | - ] ); |
340 | | -} ); |
Index: trunk/parsers/wikidom/tests/wikidom/index.html |
— | — | @@ -0,0 +1,23 @@ |
| 2 | +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 3 | + "http://www.w3.org/TR/html4/loose.dtd"> |
| 4 | +<html> |
| 5 | + <head> |
| 6 | + <title>Wikidom Tests</title> |
| 7 | + <link rel="stylesheet" href="../../lib/qunit.css" type="text/css" /> |
| 8 | + </head> |
| 9 | + <body> |
| 10 | + <h1 id="qunit-header">Wikidom Tests</h1> |
| 11 | + <h2 id="qunit-banner"></h2> |
| 12 | + <h2 id="qunit-userAgent"></h2> |
| 13 | + <ol id="qunit-tests"></ol> |
| 14 | + <script src="../../lib/jquery.js" type="text/javascript"></script> |
| 15 | + <script src="../../lib/qunit.js" type="text/javascript"></script> |
| 16 | + <script src="../../lib/wiki.js" type="text/javascript"></script> |
| 17 | + <script src="../../lib/wiki.util.js" type="text/javascript"></script> |
| 18 | + <script src="../../lib/wiki.Context.js" type="text/javascript"></script> |
| 19 | + <script src="../../lib/wiki.AnnotationRenderer.js" type="text/javascript"></script> |
| 20 | + <script src="../../lib/wiki.HtmlRenderer.js" type="text/javascript"></script> |
| 21 | + <script src="../../lib/wiki.WikitextRenderer.js" type="text/javascript"></script> |
| 22 | + <script src="wiki.test.js" type="text/javascript"></script> |
| 23 | + </body> |
| 24 | +</html> |
Property changes on: trunk/parsers/wikidom/tests/wikidom/index.html |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 25 | + text/plain |
Index: trunk/parsers/wikidom/tests/wikidom/wiki.test.js |
— | — | @@ -0,0 +1,339 @@ |
| 2 | +module( 'Wiki DOM Serialization' ); |
| 3 | + |
| 4 | +var context = new wiki.Context(); |
| 5 | + |
| 6 | +function assertSerializations( tests ) { |
| 7 | + var htmlRenderer = new wiki.HtmlRenderer( context ); |
| 8 | + var wikitextRenderer = new wiki.WikitextRenderer( context ); |
| 9 | + for ( var i = 0; i < tests.length; i++ ) { |
| 10 | + equals( |
| 11 | + htmlRenderer.render( tests[i].dom ), |
| 12 | + tests[i].html, |
| 13 | + 'Serialize ' + tests[i].subject + ' to HTML' |
| 14 | + ); |
| 15 | + } |
| 16 | + for ( var i = 0; i < tests.length; i++ ) { |
| 17 | + equals( |
| 18 | + wikitextRenderer.render( tests[i].dom ), |
| 19 | + tests[i].wikitext, |
| 20 | + 'Serialize ' + tests[i].subject + ' to Wikitext' |
| 21 | + ); |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +test( 'Comments', function() { |
| 26 | + assertSerializations( [ |
| 27 | + { |
| 28 | + 'subject': 'comment', |
| 29 | + 'dom': { 'blocks': [ { |
| 30 | + 'type': 'comment', |
| 31 | + 'text': 'Hello world!' |
| 32 | + } ] }, |
| 33 | + 'html': '<!--Hello world!-->', |
| 34 | + 'wikitext': '<!--Hello world!-->' |
| 35 | + } |
| 36 | + ] ); |
| 37 | +} ); |
| 38 | + |
| 39 | +test( 'Horizontal rules', function() { |
| 40 | + assertSerializations( [ |
| 41 | + { |
| 42 | + 'subject': 'horizontal rule', |
| 43 | + 'dom': { 'blocks': [ { |
| 44 | + 'type': 'horizontal-rule', |
| 45 | + } ] }, |
| 46 | + 'html': '<hr />', |
| 47 | + 'wikitext': '----' |
| 48 | + } |
| 49 | + ] ); |
| 50 | +} ); |
| 51 | + |
| 52 | +test( 'Headings', function() { |
| 53 | + assertSerializations( [ |
| 54 | + { |
| 55 | + 'subject': 'level 1 heading', |
| 56 | + 'dom': { 'blocks': [ { |
| 57 | + 'type': 'heading', |
| 58 | + 'level': 1, |
| 59 | + 'line': { 'text': 'Heading 1' } |
| 60 | + } ] }, |
| 61 | + 'html': '<h1>Heading 1</h1>', |
| 62 | + 'wikitext': '=Heading 1=' |
| 63 | + }, |
| 64 | + { |
| 65 | + 'subject': 'level 2 heading', |
| 66 | + 'dom': { 'blocks': [ { |
| 67 | + 'type': 'heading', |
| 68 | + 'level': 2, |
| 69 | + 'line': { 'text': 'Heading 2' } |
| 70 | + } ] }, |
| 71 | + 'html': '<h2>Heading 2</h2>', |
| 72 | + 'wikitext': '==Heading 2==' |
| 73 | + }, |
| 74 | + { |
| 75 | + 'subject': 'level 3 heading', |
| 76 | + 'dom': { 'blocks': [ { |
| 77 | + 'type': 'heading', |
| 78 | + 'level': 3, |
| 79 | + 'line': { 'text': 'Heading 3' } |
| 80 | + } ] }, |
| 81 | + 'html': '<h3>Heading 3</h3>', |
| 82 | + 'wikitext': '===Heading 3===' |
| 83 | + }, |
| 84 | + { |
| 85 | + 'subject': 'level 4 heading', |
| 86 | + 'dom': { 'blocks': [ { |
| 87 | + 'type': 'heading', |
| 88 | + 'level': 4, |
| 89 | + 'line': { 'text': 'Heading 4' } |
| 90 | + } ] }, |
| 91 | + 'html': '<h4>Heading 4</h4>', |
| 92 | + 'wikitext': '====Heading 4====' |
| 93 | + }, |
| 94 | + { |
| 95 | + 'subject': 'level 5 heading', |
| 96 | + 'dom': { 'blocks': [ { |
| 97 | + 'type': 'heading', |
| 98 | + 'level': 5, |
| 99 | + 'line': { 'text': 'Heading 5' } |
| 100 | + } ] }, |
| 101 | + 'html': '<h5>Heading 5</h5>', |
| 102 | + 'wikitext': '=====Heading 5=====' |
| 103 | + }, |
| 104 | + { |
| 105 | + 'subject': 'level 6 heading', |
| 106 | + 'dom': { 'blocks': [ { |
| 107 | + 'type': 'heading', |
| 108 | + 'level': 6, |
| 109 | + 'line': { 'text': 'Heading 6' } |
| 110 | + } ] }, |
| 111 | + 'html': '<h6>Heading 6</h6>', |
| 112 | + 'wikitext': '======Heading 6======' |
| 113 | + }, |
| 114 | + { |
| 115 | + 'subject': 'level 1 heading with annotated text', |
| 116 | + 'dom': { 'blocks': [ { |
| 117 | + 'type': 'heading', |
| 118 | + 'level': 1, |
| 119 | + 'line': { |
| 120 | + 'text': 'Heading with a link', |
| 121 | + 'annotations': [ |
| 122 | + { |
| 123 | + 'type': 'ilink', |
| 124 | + 'range': { 'offset': 15, 'length': 4 }, |
| 125 | + 'data': { 'namespace': 'Main', 'title': 'Main_Page' } |
| 126 | + } |
| 127 | + ] |
| 128 | + } |
| 129 | + } ] }, |
| 130 | + 'html': '<h1>Heading with a <a href="https://www.mediawiki.org/wiki/Main_Page">link</a></h1>', |
| 131 | + 'wikitext': '=Heading with a [[Main_Page|link]]=' |
| 132 | + }, |
| 133 | + ] ); |
| 134 | +} ); |
| 135 | + |
| 136 | +test( 'Paragraphs', function() { |
| 137 | + assertSerializations( [ |
| 138 | + { |
| 139 | + 'subject': 'paragraph with a single line of plain text', |
| 140 | + 'dom': { 'blocks': [ { |
| 141 | + 'type': 'paragraph', |
| 142 | + 'lines': [ { 'text': 'Line with plain text' } ] |
| 143 | + } ] }, |
| 144 | + 'html': '<p>Line with plain text</p>', |
| 145 | + 'wikitext': 'Line with plain text' |
| 146 | + }, |
| 147 | + { |
| 148 | + 'subject': 'paragraph with multiple lines of plain text', |
| 149 | + 'dom': { 'blocks': [ { |
| 150 | + 'type': 'paragraph', |
| 151 | + 'lines': [ |
| 152 | + { 'text': 'Line with plain text' }, |
| 153 | + { 'text': 'Line with more plain text' } |
| 154 | + ] |
| 155 | + } ] }, |
| 156 | + 'html': '<p>Line with plain text\nLine with more plain text</p>', |
| 157 | + 'wikitext': 'Line with plain text\nLine with more plain text' |
| 158 | + }, |
| 159 | + { |
| 160 | + 'subject': 'paragraph with a single line of annotated text', |
| 161 | + 'dom': { 'blocks': [ { |
| 162 | + 'type': 'paragraph', |
| 163 | + 'lines': [ |
| 164 | + { |
| 165 | + 'text': 'Line with bold and italic text', |
| 166 | + 'annotations': [ |
| 167 | + { 'type': 'bold', 'range': { 'offset': 10, 'length': 4 } }, |
| 168 | + { 'type': 'italic', 'range': { 'offset': 19, 'length': 6 } } |
| 169 | + ] |
| 170 | + } |
| 171 | + ] |
| 172 | + } ] }, |
| 173 | + 'html': '<p>Line with <strong>bold</strong> and <em>italic</em> text</p>', |
| 174 | + 'wikitext': 'Line with \'\'\'bold\'\'\' and \'\'italic\'\' text' |
| 175 | + } |
| 176 | + ] ); |
| 177 | +} ); |
| 178 | + |
| 179 | +// Lists |
| 180 | +test( 'Lists', function() { |
| 181 | + assertSerializations( [ |
| 182 | + { |
| 183 | + 'subject': 'numbered list', |
| 184 | + 'dom': { 'blocks': [ { |
| 185 | + 'type': 'list', |
| 186 | + 'style': 'number', |
| 187 | + 'items': [ |
| 188 | + { 'line': { 'text': '1' } }, |
| 189 | + { 'line': { 'text': '2' } }, |
| 190 | + { 'line': { 'text': '3' } } |
| 191 | + ] |
| 192 | + } ] }, |
| 193 | + 'html': '<ol>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ol>', |
| 194 | + 'wikitext': '# 1\n# 2\n# 3' |
| 195 | + }, |
| 196 | + { |
| 197 | + 'subject': 'bulleted list', |
| 198 | + 'dom': { 'blocks': [ { |
| 199 | + 'type': 'list', |
| 200 | + 'style': 'bullet', |
| 201 | + 'items': [ |
| 202 | + { 'line': { 'text': '1' } }, |
| 203 | + { 'line': { 'text': '2' } }, |
| 204 | + { 'line': { 'text': '3' } } |
| 205 | + ] |
| 206 | + } ] }, |
| 207 | + 'html': '<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>', |
| 208 | + 'wikitext': '* 1\n* 2\n* 3' |
| 209 | + }, |
| 210 | + { |
| 211 | + 'subject': 'mixed-style nested lists', |
| 212 | + 'dom': { 'blocks': [ { |
| 213 | + 'type': 'list', |
| 214 | + 'style': 'bullet', |
| 215 | + 'items': [ |
| 216 | + { |
| 217 | + 'line': { 'text': '1' }, |
| 218 | + 'lists': [ |
| 219 | + { |
| 220 | + 'style': 'number', |
| 221 | + 'items': [ |
| 222 | + { 'line': { 'text': '1.1' } }, |
| 223 | + { 'line': { 'text': '1.2' } }, |
| 224 | + { 'line': { 'text': '1.3' } } |
| 225 | + ] |
| 226 | + } |
| 227 | + ] |
| 228 | + }, |
| 229 | + { 'line': { 'text': '2' } } |
| 230 | + ] |
| 231 | + } ] }, |
| 232 | + 'html': '<ul>\n<li>1\n<ol>\n<li>1.1</li>\n<li>1.2</li>\n<li>1.3</li>\n</ol>' |
| 233 | + + '\n</li>\n<li>2</li>\n</ul>', |
| 234 | + 'wikitext': '* 1\n*# 1.1\n*# 1.2\n*# 1.3\n* 2' |
| 235 | + } |
| 236 | + ] ); |
| 237 | +} ); |
| 238 | + |
| 239 | +// Tables |
| 240 | +test( 'Tables', function() { |
| 241 | + assertSerializations( [ |
| 242 | + { |
| 243 | + 'subject': 'table with headings and data', |
| 244 | + 'dom': { 'blocks': [{ |
| 245 | + 'type': 'table', |
| 246 | + 'rows': [ |
| 247 | + [ |
| 248 | + { |
| 249 | + 'type': 'heading', |
| 250 | + 'document': { 'blocks': [{ |
| 251 | + 'type': 'paragraph', |
| 252 | + 'lines': [{ 'text': 'A' }] |
| 253 | + }] } |
| 254 | + }, |
| 255 | + { |
| 256 | + 'type': 'heading', |
| 257 | + 'document': { 'blocks': [{ |
| 258 | + 'type': 'paragraph', |
| 259 | + 'lines': [{ 'text': 'B' }] |
| 260 | + }] } |
| 261 | + } |
| 262 | + ], |
| 263 | + [ |
| 264 | + { |
| 265 | + 'type': 'data', |
| 266 | + 'document': { 'blocks': [{ |
| 267 | + 'type': 'paragraph', |
| 268 | + 'lines': [{ 'text': '1' }] |
| 269 | + }] } |
| 270 | + }, |
| 271 | + { |
| 272 | + 'type': 'data', |
| 273 | + 'document': { 'blocks': [{ |
| 274 | + 'type': 'paragraph', |
| 275 | + 'lines': [{ 'text': '2' }] |
| 276 | + }] } |
| 277 | + } |
| 278 | + ] |
| 279 | + ] |
| 280 | + }] }, |
| 281 | + 'html': '<table>\n<tr>\n<th>A</th>\n<th>B</th>\n</tr>\n<tr>\n' |
| 282 | + + '<td>1</td>\n<td>2</td>\n</tr>\n</table>', |
| 283 | + 'wikitext': '{|\n!A\n!B\n|-\n|1\n|2\n|}' |
| 284 | + }, |
| 285 | + { |
| 286 | + 'subject': 'table with attributes', |
| 287 | + 'dom': { 'blocks': [{ |
| 288 | + 'type': 'table', |
| 289 | + 'attributes': { |
| 290 | + 'class': 'wikitable' |
| 291 | + }, |
| 292 | + 'rows': [ |
| 293 | + [ |
| 294 | + { |
| 295 | + 'type': 'data', |
| 296 | + 'attributes': { |
| 297 | + 'class': 'abc' |
| 298 | + }, |
| 299 | + 'document': { 'blocks': [{ |
| 300 | + 'type': 'paragraph', |
| 301 | + 'lines': [{ 'text': 'abc' }] |
| 302 | + }] } |
| 303 | + } |
| 304 | + ] |
| 305 | + ] |
| 306 | + }] }, |
| 307 | + 'html': '<table class="wikitable">\n<tr>\n<td class="abc">abc</td>\n</tr>\n</table>', |
| 308 | + 'wikitext': '{|class="wikitable"\n|class="abc"|abc\n|}' |
| 309 | + } |
| 310 | + ] ); |
| 311 | +} ); |
| 312 | + |
| 313 | +test( 'Transclusion', function() { |
| 314 | + assertSerializations( [ |
| 315 | + { |
| 316 | + 'subject': 'transclusion', |
| 317 | + 'dom': { 'blocks': [ { |
| 318 | + 'type': 'transclusion', |
| 319 | + 'namespace': 'Template', |
| 320 | + 'title': 'Test' |
| 321 | + } ] }, |
| 322 | + 'html': '<a href="https://www.mediawiki.org/wiki/Template:Test">Template:Test</a>', |
| 323 | + 'wikitext': '{{Test}}' |
| 324 | + } |
| 325 | + ] ); |
| 326 | +} ); |
| 327 | + |
| 328 | +test( 'Parameter', function() { |
| 329 | + assertSerializations( [ |
| 330 | + { |
| 331 | + 'subject': 'transclusion', |
| 332 | + 'dom': { 'blocks': [ { |
| 333 | + 'type': 'parameter', |
| 334 | + 'name': '1' |
| 335 | + } ] }, |
| 336 | + 'html': '{{{1}}}', |
| 337 | + 'wikitext': '{{{1}}}' |
| 338 | + } |
| 339 | + ] ); |
| 340 | +} ); |
Property changes on: trunk/parsers/wikidom/tests/wikidom/wiki.test.js |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 341 | + text/plain |
Added: svn:eol-style |
2 | 342 | + native |
Index: trunk/parsers/wikidom/tests/annotations/index.html |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 3 | + "http://www.w3.org/TR/html4/loose.dtd"> |
| 4 | +<html> |
| 5 | + <head> |
| 6 | + <title>Wikidom Annotation Tests</title> |
| 7 | + <link rel="stylesheet" href="../../lib/qunit.css" type="text/css" /> |
| 8 | + </head> |
| 9 | + <body> |
| 10 | + <h1 id="qunit-header">Wikidom Tests</h1> |
| 11 | + <h2 id="qunit-banner"></h2> |
| 12 | + <h2 id="qunit-userAgent"></h2> |
| 13 | + <ol id="qunit-tests"></ol> |
| 14 | + <script src="../../lib/jquery.js" type="text/javascript"></script> |
| 15 | + <script src="../../lib/qunit.js" type="text/javascript"></script> |
| 16 | + <script src="test.js" type="text/javascript"></script> |
| 17 | + </body> |
| 18 | +</html> |
Property changes on: trunk/parsers/wikidom/tests/annotations/index.html |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 19 | + text/plain |
Index: trunk/parsers/wikidom/tests/annotations/test.js |
— | — | @@ -0,0 +1,95 @@ |
| 2 | +module( 'Wiki DOM Annotations' ); |
| 3 | + |
| 4 | +/* Functions */ |
| 5 | + |
| 6 | +function diff( a, b ) { |
| 7 | + var result = []; |
| 8 | + for ( var i = 0; i < b.length; i++ ) { |
| 9 | + if ( a.indexOf( b[i] ) === -1 ) { |
| 10 | + result.push( b[i] ); |
| 11 | + } |
| 12 | + } |
| 13 | + return result; |
| 14 | +} |
| 15 | + |
| 16 | +function openAnnotations( annotations ) { |
| 17 | + // TODO: Something... |
| 18 | + return ''; |
| 19 | +} |
| 20 | + |
| 21 | +function closeAnnotations( annotations ) { |
| 22 | + // TODO: Something... |
| 23 | + return ''; |
| 24 | +} |
| 25 | + |
| 26 | +function renderText( text, renderedAnnotations ) { |
| 27 | + var out = ''; |
| 28 | + var left = []; |
| 29 | + for (i in text) { |
| 30 | + var right = renderedAnnotations[i] || []; |
| 31 | + out += openAnnotations( diff( left, right ) ); |
| 32 | + out += text[i]; |
| 33 | + out += closeAnnotations( diff( right, left ) ); |
| 34 | + right = left; |
| 35 | + } |
| 36 | + return out; |
| 37 | +} |
| 38 | + |
| 39 | +/* Test Data */ |
| 40 | + |
| 41 | +var lines = [ |
| 42 | + { |
| 43 | + "text": "This is a test paragraph!", |
| 44 | + "annotations": [ |
| 45 | + { |
| 46 | + "type": "italic", |
| 47 | + "range": { |
| 48 | + "offset": 0, |
| 49 | + "length": 4 |
| 50 | + } |
| 51 | + }, |
| 52 | + { |
| 53 | + "type": "xlink", |
| 54 | + "range": { |
| 55 | + "offset": 8, |
| 56 | + "length": 6 |
| 57 | + }, |
| 58 | + "data": { |
| 59 | + "url": "http://www.a.com" |
| 60 | + } |
| 61 | + }, |
| 62 | + { |
| 63 | + "type": "bold", |
| 64 | + "range": { |
| 65 | + "offset": 10, |
| 66 | + "length": 4 |
| 67 | + } |
| 68 | + } |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "text": "Paragraphs can have more than one line.", |
| 73 | + "annotations": [ |
| 74 | + { |
| 75 | + "type": "italic", |
| 76 | + "range": { |
| 77 | + "offset": 11, |
| 78 | + "length": 3 |
| 79 | + } |
| 80 | + }, |
| 81 | + { |
| 82 | + "type": "bold", |
| 83 | + "range": { |
| 84 | + "offset": 20, |
| 85 | + "length": 4 |
| 86 | + } |
| 87 | + } |
| 88 | + ] |
| 89 | + } |
| 90 | +]; |
| 91 | + |
| 92 | +/* Tests */ |
| 93 | + |
| 94 | +test( 'Dummy test', function() { |
| 95 | + equals( 1, 1 ); |
| 96 | +} ); |
Property changes on: trunk/parsers/wikidom/tests/annotations/test.js |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 97 | + text/plain |
Added: svn:eol-style |
2 | 98 | + native |