Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: test/markdown_test.dart

Issue 1274763005: Clean up: (Closed) Base URL: https://github.com/dart-lang/markdown.git@master
Patch Set: Bump. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pubspec.yaml ('k') | test/util.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Unit tests for markdown. 5 /// Unit tests for markdown.
6 library markdown.test.markdown_test; 6 library markdown.test.markdown_test;
7 7
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import 'package:markdown/markdown.dart'; 10 import 'package:markdown/markdown.dart';
11 11
12 import 'utils.dart'; 12 import 'util.dart';
13 13
14 /// Most of these tests are based on observing how showdown behaves: 14 /// Most of these tests are based on observing how showdown behaves:
15 /// http://softwaremaniacs.org/playground/showdown-highlight/ 15 /// http://softwaremaniacs.org/playground/showdown-highlight/
16 void main() { 16 void main() {
17 group('Paragraphs', () { 17 group('Paragraphs', () {
18 validate('consecutive lines form a single paragraph', ''' 18 validate(
19 'consecutive lines form a single paragraph',
20 '''
19 This is the first line. 21 This is the first line.
20 This is the second line. 22 This is the second line.
21 ''', ''' 23 ''',
24 '''
22 <p>This is the first line. 25 <p>This is the first line.
23 This is the second line.</p> 26 This is the second line.</p>
24 '''); 27 ''');
25 28
26 // TODO(rnystrom): The rules here for what happens to lines following a 29 // TODO(rnystrom): The rules here for what happens to lines following a
27 // paragraph appear to be completely arbitrary in markdown. If it makes the 30 // paragraph appear to be completely arbitrary in markdown. If it makes the
28 // code significantly cleaner, we should consider ourselves free to change 31 // code significantly cleaner, we should consider ourselves free to change
29 // these tests. 32 // these tests.
30 33
31 validate('are terminated by a header', ''' 34 validate(
35 'are terminated by a header',
36 '''
32 para 37 para
33 # header 38 # header
34 ''', ''' 39 ''',
40 '''
35 <p>para</p> 41 <p>para</p>
36 <h1>header</h1> 42 <h1>header</h1>
37 '''); 43 ''');
38 44
39 validate('are terminated by a setext header', ''' 45 validate(
46 'are terminated by a setext header',
47 '''
40 para 48 para
41 header 49 header
42 == 50 ==
43 ''', ''' 51 ''',
52 '''
44 <p>para</p> 53 <p>para</p>
45 <h1>header</h1> 54 <h1>header</h1>
46 '''); 55 ''');
47 56
48 validate('are terminated by a hr', ''' 57 validate(
58 'are terminated by a hr',
59 '''
49 para 60 para
50 ___ 61 ___
51 ''', ''' 62 ''',
63 '''
52 <p>para</p> 64 <p>para</p>
53 <hr /> 65 <hr />
54 '''); 66 ''');
55 67
56 validate('consume an unordered list', ''' 68 validate(
69 'consume an unordered list',
70 '''
57 para 71 para
58 * list 72 * list
59 ''', ''' 73 ''',
74 '''
60 <p>para 75 <p>para
61 * list</p> 76 * list</p>
62 '''); 77 ''');
63 78
64 validate('consume an ordered list', ''' 79 validate(
80 'consume an ordered list',
81 '''
65 para 82 para
66 1. list 83 1. list
67 ''', ''' 84 ''',
85 '''
68 <p>para 86 <p>para
69 1. list</p> 87 1. list</p>
70 '''); 88 ''');
71 89
72 // Windows line endings have a \r\n format 90 // Windows line endings have a \r\n format
73 // instead of the unix \n format. 91 // instead of the unix \n format.
74 validate('take account of windows line endings', ''' 92 validate(
93 'take account of windows line endings',
94 '''
75 line1\r\n\r\n line2\r\n 95 line1\r\n\r\n line2\r\n
76 ''', ''' 96 ''',
97 '''
77 <p>line1</p> 98 <p>line1</p>
78 <p>line2</p> 99 <p>line2</p>
79 '''); 100 ''');
80 }); 101 });
81 102
82 group('Setext headers', () { 103 group('Setext headers', () {
83 validate('h1', ''' 104 validate(
105 'h1',
106 '''
84 text 107 text
85 === 108 ===
86 ''', ''' 109 ''',
110 '''
87 <h1>text</h1> 111 <h1>text</h1>
88 '''); 112 ''');
89 113
90 validate('h2', ''' 114 validate(
115 'h2',
116 '''
91 text 117 text
92 --- 118 ---
93 ''', ''' 119 ''',
120 '''
94 <h2>text</h2> 121 <h2>text</h2>
95 '''); 122 ''');
96 123
97 validate('h1 on first line becomes text', ''' 124 validate(
98 === 125 'h1 on first line becomes text',
99 ''', ''' 126 '''
127 ===
128 ''',
129 '''
100 <p>===</p> 130 <p>===</p>
101 '''); 131 ''');
102 132
103 validate('h2 on first line becomes text', ''' 133 validate(
134 'h2 on first line becomes text',
135 '''
104 - 136 -
105 ''', ''' 137 ''',
138 '''
106 <p>-</p> 139 <p>-</p>
107 '''); 140 ''');
108 141
109 validate('h1 turns preceding list into text', ''' 142 validate(
143 'h1 turns preceding list into text',
144 '''
110 - list 145 - list
111 === 146 ===
112 ''', ''' 147 ''',
148 '''
113 <h1>- list</h1> 149 <h1>- list</h1>
114 '''); 150 ''');
115 151
116 validate('h2 turns preceding list into text', ''' 152 validate(
153 'h2 turns preceding list into text',
154 '''
117 - list 155 - list
118 === 156 ===
119 ''', ''' 157 ''',
158 '''
120 <h1>- list</h1> 159 <h1>- list</h1>
121 '''); 160 ''');
122 161
123 validate('h1 turns preceding blockquote into text', ''' 162 validate(
163 'h1 turns preceding blockquote into text',
164 '''
124 > quote 165 > quote
125 === 166 ===
126 ''', ''' 167 ''',
168 '''
127 <h1>> quote</h1> 169 <h1>> quote</h1>
128 '''); 170 ''');
129 171
130 validate('h2 turns preceding blockquote into text', ''' 172 validate(
173 'h2 turns preceding blockquote into text',
174 '''
131 > quote 175 > quote
132 === 176 ===
133 ''', ''' 177 ''',
178 '''
134 <h1>> quote</h1> 179 <h1>> quote</h1>
135 '''); 180 ''');
136 }); 181 });
137 182
138 group('Headers', () { 183 group('Headers', () {
139 validate('h1', ''' 184 validate(
185 'h1',
186 '''
140 # header 187 # header
141 ''', ''' 188 ''',
142 <h1>header</h1> 189 '''
143 '''); 190 <h1>header</h1>
144 191 ''');
145 validate('h2', ''' 192
193 validate(
194 'h2',
195 '''
146 ## header 196 ## header
147 ''', ''' 197 ''',
198 '''
148 <h2>header</h2> 199 <h2>header</h2>
149 '''); 200 ''');
150 201
151 validate('h3', ''' 202 validate(
203 'h3',
204 '''
152 ### header 205 ### header
153 ''', ''' 206 ''',
207 '''
154 <h3>header</h3> 208 <h3>header</h3>
155 '''); 209 ''');
156 210
157 validate('h4', ''' 211 validate(
212 'h4',
213 '''
158 #### header 214 #### header
159 ''', ''' 215 ''',
216 '''
160 <h4>header</h4> 217 <h4>header</h4>
161 '''); 218 ''');
162 219
163 validate('h5', ''' 220 validate(
221 'h5',
222 '''
164 ##### header 223 ##### header
165 ''', ''' 224 ''',
225 '''
166 <h5>header</h5> 226 <h5>header</h5>
167 '''); 227 ''');
168 228
169 validate('h6', ''' 229 validate(
230 'h6',
231 '''
170 ###### header 232 ###### header
171 ''', ''' 233 ''',
234 '''
172 <h6>header</h6> 235 <h6>header</h6>
173 '''); 236 ''');
174 237
175 validate('trailing "#" are removed', ''' 238 validate(
239 'trailing "#" are removed',
240 '''
176 # header ###### 241 # header ######
177 ''', ''' 242 ''',
243 '''
178 <h1>header</h1> 244 <h1>header</h1>
179 '''); 245 ''');
180 }); 246 });
181 247
182 group('Unordered lists', () { 248 group('Unordered lists', () {
183 validate('asterisk, plus and hyphen', ''' 249 validate(
250 'asterisk, plus and hyphen',
251 '''
184 * star 252 * star
185 - dash 253 - dash
186 + plus 254 + plus
187 ''', ''' 255 ''',
256 '''
188 <ul> 257 <ul>
189 <li>star</li> 258 <li>star</li>
190 <li>dash</li> 259 <li>dash</li>
191 <li>plus</li> 260 <li>plus</li>
192 </ul> 261 </ul>
193 '''); 262 ''');
194 263
195 validate('allow numbered lines after first', ''' 264 validate(
265 'allow numbered lines after first',
266 '''
196 * a 267 * a
197 1. b 268 1. b
198 ''', ''' 269 ''',
270 '''
199 <ul> 271 <ul>
200 <li>a</li> 272 <li>a</li>
201 <li>b</li> 273 <li>b</li>
202 </ul> 274 </ul>
203 '''); 275 ''');
204 276
205 validate('allow a tab after the marker', ''' 277 validate(
278 'allow a tab after the marker',
279 '''
206 *\ta 280 *\ta
207 +\tb 281 +\tb
208 -\tc 282 -\tc
209 1.\td 283 1.\td
210 ''', ''' 284 ''',
285 '''
211 <ul> 286 <ul>
212 <li>a</li> 287 <li>a</li>
213 <li>b</li> 288 <li>b</li>
214 <li>c</li> 289 <li>c</li>
215 <li>d</li> 290 <li>d</li>
216 </ul> 291 </ul>
217 '''); 292 ''');
218 293
219 validate('wrap items in paragraphs if blank lines separate', ''' 294 validate(
295 'wrap items in paragraphs if blank lines separate',
296 '''
220 * one 297 * one
221 298
222 * two 299 * two
223 ''', ''' 300 ''',
301 '''
224 <ul> 302 <ul>
225 <li><p>one</p></li> 303 <li><p>one</p></li>
226 <li><p>two</p></li> 304 <li><p>two</p></li>
227 </ul> 305 </ul>
228 '''); 306 ''');
229 307
230 validate('force paragraph on item before and after blank lines', ''' 308 validate(
309 'force paragraph on item before and after blank lines',
310 '''
231 * one 311 * one
232 * two 312 * two
233 313
234 * three 314 * three
235 ''', ''' 315 ''',
316 '''
236 <ul> 317 <ul>
237 <li>one</li> 318 <li>one</li>
238 <li> 319 <li>
239 <p>two</p> 320 <p>two</p>
240 </li> 321 </li>
241 <li> 322 <li>
242 <p>three</p> 323 <p>three</p>
243 </li> 324 </li>
244 </ul> 325 </ul>
245 '''); 326 ''');
246 327
247 validate('do not force paragraph if item is already block', ''' 328 validate(
329 'do not force paragraph if item is already block',
330 '''
248 * > quote 331 * > quote
249 332
250 * # header 333 * # header
251 ''', ''' 334 ''',
335 '''
252 <ul> 336 <ul>
253 <li><blockquote><p>quote</p></blockquote></li> 337 <li><blockquote><p>quote</p></blockquote></li>
254 <li><h1>header</h1></li> 338 <li><h1>header</h1></li>
255 </ul> 339 </ul>
256 '''); 340 ''');
257 341
258 validate('can contain multiple paragraphs', ''' 342 validate(
343 'can contain multiple paragraphs',
344 '''
259 * one 345 * one
260 346
261 two 347 two
262 348
263 * three 349 * three
264 ''', ''' 350 ''',
351 '''
265 <ul> 352 <ul>
266 <li> 353 <li>
267 <p>one</p> 354 <p>one</p>
268 <p>two</p> 355 <p>two</p>
269 </li> 356 </li>
270 <li> 357 <li>
271 <p>three</p> 358 <p>three</p>
272 </li> 359 </li>
273 </ul> 360 </ul>
274 '''); 361 ''');
275 362
276 validate('can span newlines', ''' 363 validate(
364 'can span newlines',
365 '''
277 * one 366 * one
278 two 367 two
279 * three 368 * three
280 ''', ''' 369 ''',
370 '''
281 <ul> 371 <ul>
282 <li> 372 <li>
283 <p>one 373 <p>one
284 two</p> 374 two</p>
285 </li> 375 </li>
286 <li> 376 <li>
287 three 377 three
288 </li> 378 </li>
289 </ul> 379 </ul>
290 '''); 380 ''');
291 381
292 // TODO(rnystrom): This is how most other markdown parsers handle 382 // TODO(rnystrom): This is how most other markdown parsers handle
293 // this but that seems like a nasty special case. For now, let's not 383 // this but that seems like a nasty special case. For now, let's not
294 // worry about it. 384 // worry about it.
295 /* 385 /*
296 validate('can nest using indentation', ''' 386 validate('can nest using indentation', '''
297 * parent 387 * parent
298 * child 388 * child
299 ''', ''' 389 ''', '''
300 <ul> 390 <ul>
301 <li>parent 391 <li>parent
302 <ul><li>child</li></ul></li> 392 <ul><li>child</li></ul></li>
303 </ul> 393 </ul>
304 '''); 394 ''');
305 */ 395 */
306 }); 396 });
307 397
308 group('Ordered lists', () { 398 group('Ordered lists', () {
309 validate('start with numbers', ''' 399 validate(
400 'start with numbers',
401 '''
310 1. one 402 1. one
311 45. two 403 45. two
312 12345. three 404 12345. three
313 ''', ''' 405 ''',
406 '''
314 <ol> 407 <ol>
315 <li>one</li> 408 <li>one</li>
316 <li>two</li> 409 <li>two</li>
317 <li>three</li> 410 <li>three</li>
318 </ol> 411 </ol>
319 '''); 412 ''');
320 413
321 validate('allow unordered lines after first', ''' 414 validate(
415 'allow unordered lines after first',
416 '''
322 1. a 417 1. a
323 * b 418 * b
324 ''', ''' 419 ''',
420 '''
325 <ol> 421 <ol>
326 <li>a</li> 422 <li>a</li>
327 <li>b</li> 423 <li>b</li>
328 </ol> 424 </ol>
329 '''); 425 ''');
330 }); 426 });
331 427
332 group('Blockquotes', () { 428 group('Blockquotes', () {
333 validate('single line', ''' 429 validate(
430 'single line',
431 '''
334 > blah 432 > blah
335 ''', ''' 433 ''',
434 '''
336 <blockquote> 435 <blockquote>
337 <p>blah</p> 436 <p>blah</p>
338 </blockquote> 437 </blockquote>
339 '''); 438 ''');
340 439
341 validate('with two paragraphs', ''' 440 validate(
441 'with two paragraphs',
442 '''
342 > first 443 > first
343 > 444 >
344 > second 445 > second
345 ''', ''' 446 ''',
447 '''
346 <blockquote> 448 <blockquote>
347 <p>first</p> 449 <p>first</p>
348 <p>second</p> 450 <p>second</p>
349 </blockquote> 451 </blockquote>
350 '''); 452 ''');
351 453
352 validate('nested', ''' 454 validate(
455 'nested',
456 '''
353 > one 457 > one
354 >> two 458 >> two
355 > > > three 459 > > > three
356 ''', ''' 460 ''',
461 '''
357 <blockquote> 462 <blockquote>
358 <p>one</p> 463 <p>one</p>
359 <blockquote> 464 <blockquote>
360 <p>two</p> 465 <p>two</p>
361 <blockquote> 466 <blockquote>
362 <p>three</p> 467 <p>three</p>
363 </blockquote> 468 </blockquote>
364 </blockquote> 469 </blockquote>
365 </blockquote> 470 </blockquote>
366 '''); 471 ''');
367 }); 472 });
368 473
369 group('Code blocks', () { 474 group('Code blocks', () {
370 validate('single line', ''' 475 validate(
476 'single line',
477 '''
371 code 478 code
372 ''', ''' 479 ''',
480 '''
373 <pre><code>code</code></pre> 481 <pre><code>code</code></pre>
374 '''); 482 ''');
375 483
376 validate('include leading whitespace after indentation', ''' 484 validate(
485 'include leading whitespace after indentation',
486 '''
377 zero 487 zero
378 one 488 one
379 two 489 two
380 three 490 three
381 ''', ''' 491 ''',
492 '''
382 <pre><code>zero 493 <pre><code>zero
383 one 494 one
384 two 495 two
385 three</code></pre> 496 three</code></pre>
386 '''); 497 ''');
387 498
388 validate('code blocks separated by newlines form one block', ''' 499 validate(
500 'code blocks separated by newlines form one block',
501 '''
389 zero 502 zero
390 one 503 one
391 504
392 two 505 two
393 506
394 three 507 three
395 ''', ''' 508 ''',
509 '''
396 <pre><code>zero 510 <pre><code>zero
397 one 511 one
398 512
399 two 513 two
400 514
401 three</code></pre> 515 three</code></pre>
402 '''); 516 ''');
403 517
404 validate('code blocks separated by two newlines form multiple blocks', ''' 518 validate(
519 'code blocks separated by two newlines form multiple blocks',
520 '''
405 zero 521 zero
406 one 522 one
407 523
408 524
409 two 525 two
410 526
411 527
412 three 528 three
413 ''', ''' 529 ''',
530 '''
414 <pre><code>zero 531 <pre><code>zero
415 one</code></pre> 532 one</code></pre>
416 <pre><code>two</code></pre> 533 <pre><code>two</code></pre>
417 <pre><code>three</code></pre> 534 <pre><code>three</code></pre>
418 '''); 535 ''');
419 536
420 validate('escape HTML characters', ''' 537 validate(
538 'escape HTML characters',
539 '''
421 <&> 540 <&>
422 ''', ''' 541 ''',
542 '''
423 <pre><code>&lt;&amp;&gt;</code></pre> 543 <pre><code>&lt;&amp;&gt;</code></pre>
424 '''); 544 ''');
425 }); 545 });
426 546
427 group('Fenced code blocks', () { 547 group('Fenced code blocks', () {
428 validate('without an optional language identifier', ''' 548 validate(
549 'without an optional language identifier',
550 '''
429 ``` 551 ```
430 code 552 code
431 ``` 553 ```
432 ''', ''' 554 ''',
555 '''
433 <pre><code>code 556 <pre><code>code
434 </code></pre> 557 </code></pre>
435 '''); 558 ''');
436 559
437 validate('with an optional language identifier', ''' 560 validate(
561 'with an optional language identifier',
562 '''
438 ```dart 563 ```dart
439 code 564 code
440 ``` 565 ```
441 ''', ''' 566 ''',
567 '''
442 <pre class="dart"><code>code 568 <pre class="dart"><code>code
443 </code></pre> 569 </code></pre>
444 '''); 570 ''');
445 571
446 validate('escape HTML characters', ''' 572 validate(
573 'escape HTML characters',
574 '''
447 ``` 575 ```
448 <&> 576 <&>
449 ``` 577 ```
450 ''', ''' 578 ''',
579 '''
451 <pre><code>&lt;&amp;&gt; 580 <pre><code>&lt;&amp;&gt;
452 </code></pre> 581 </code></pre>
453 '''); 582 ''');
454 583
455 validate('Pandoc style without language identifier', ''' 584 validate(
585 'Pandoc style without language identifier',
586 '''
456 ~~~~~ 587 ~~~~~
457 code 588 code
458 ~~~~~ 589 ~~~~~
459 ''', ''' 590 ''',
591 '''
460 <pre><code>code 592 <pre><code>code
461 </code></pre> 593 </code></pre>
462 '''); 594 ''');
463 595
464 validate('Pandoc style with language identifier', ''' 596 validate(
597 'Pandoc style with language identifier',
598 '''
465 ~~~~~dart 599 ~~~~~dart
466 code 600 code
467 ~~~~~ 601 ~~~~~
468 ''', ''' 602 ''',
603 '''
469 <pre class="dart"><code>code 604 <pre class="dart"><code>code
470 </code></pre> 605 </code></pre>
471 '''); 606 ''');
472 607
473 validate('Pandoc style with inner tildes row', ''' 608 validate(
609 'Pandoc style with inner tildes row',
610 '''
474 ~~~~~ 611 ~~~~~
475 ~~~ 612 ~~~
476 code 613 code
477 ~~~ 614 ~~~
478 ~~~~~ 615 ~~~~~
479 ''', ''' 616 ''',
617 '''
480 <pre><code>~~~ 618 <pre><code>~~~
481 code 619 code
482 ~~~ 620 ~~~
483 </code></pre> 621 </code></pre>
484 '''); 622 ''');
485 }); 623 });
486 624
487 group('Horizontal rules', () { 625 group('Horizontal rules', () {
488 validate('from dashes', ''' 626 validate(
627 'from dashes',
628 '''
489 --- 629 ---
490 ''', ''' 630 ''',
631 '''
491 <hr /> 632 <hr />
492 '''); 633 ''');
493 634
494 validate('from asterisks', ''' 635 validate(
636 'from asterisks',
637 '''
495 *** 638 ***
496 ''', ''' 639 ''',
640 '''
497 <hr /> 641 <hr />
498 '''); 642 ''');
499 643
500 validate('from underscores', ''' 644 validate(
645 'from underscores',
646 '''
501 ___ 647 ___
502 ''', ''' 648 ''',
649 '''
503 <hr /> 650 <hr />
504 '''); 651 ''');
505 652
506 validate('can include up to two spaces', ''' 653 validate(
654 'can include up to two spaces',
655 '''
507 _ _ _ 656 _ _ _
508 ''', ''' 657 ''',
658 '''
509 <hr /> 659 <hr />
510 '''); 660 ''');
511 }); 661 });
512 662
513 group('Block-level HTML', () { 663 group('Block-level HTML', () {
514 validate('single line', ''' 664 validate(
665 'single line',
666 '''
515 <table></table> 667 <table></table>
516 ''', ''' 668 ''',
669 '''
517 <table></table> 670 <table></table>
518 '''); 671 ''');
519 672
520 validate('multi-line', ''' 673 validate(
674 'multi-line',
675 '''
521 <table> 676 <table>
522 blah 677 blah
523 </table> 678 </table>
524 ''', ''' 679 ''',
680 '''
525 <table> 681 <table>
526 blah 682 blah
527 </table> 683 </table>
528 '''); 684 ''');
529 685
530 validate('blank line ends block', ''' 686 validate(
687 'blank line ends block',
688 '''
531 <table> 689 <table>
532 blah 690 blah
533 </table> 691 </table>
534 692
535 para 693 para
536 ''', ''' 694 ''',
695 '''
537 <table> 696 <table>
538 blah 697 blah
539 </table> 698 </table>
540 <p>para</p> 699 <p>para</p>
541 '''); 700 ''');
542 701
543 validate('HTML can be bogus', ''' 702 validate(
703 'HTML can be bogus',
704 '''
544 <bogus> 705 <bogus>
545 blah 706 blah
546 </weird> 707 </weird>
547 708
548 para 709 para
549 ''', ''' 710 ''',
711 '''
550 <bogus> 712 <bogus>
551 blah 713 blah
552 </weird> 714 </weird>
553 <p>para</p> 715 <p>para</p>
554 '''); 716 ''');
555 }); 717 });
556 718
557 group('Strong', () { 719 group('Strong', () {
558 validate('using asterisks', ''' 720 validate(
721 'using asterisks',
722 '''
559 before **strong** after 723 before **strong** after
560 ''', ''' 724 ''',
725 '''
561 <p>before <strong>strong</strong> after</p> 726 <p>before <strong>strong</strong> after</p>
562 '''); 727 ''');
563 728
564 validate('using underscores', ''' 729 validate(
730 'using underscores',
731 '''
565 before __strong__ after 732 before __strong__ after
566 ''', ''' 733 ''',
734 '''
567 <p>before <strong>strong</strong> after</p> 735 <p>before <strong>strong</strong> after</p>
568 '''); 736 ''');
569 737
570 validate('unmatched asterisks', ''' 738 validate(
739 'unmatched asterisks',
740 '''
571 before ** after 741 before ** after
572 ''', ''' 742 ''',
743 '''
573 <p>before ** after</p> 744 <p>before ** after</p>
574 '''); 745 ''');
575 746
576 validate('unmatched underscores', ''' 747 validate(
748 'unmatched underscores',
749 '''
577 before __ after 750 before __ after
578 ''', ''' 751 ''',
752 '''
579 <p>before __ after</p> 753 <p>before __ after</p>
580 '''); 754 ''');
581 755
582 validate('multiple spans in one text', ''' 756 validate(
757 'multiple spans in one text',
758 '''
583 a **one** b __two__ c 759 a **one** b __two__ c
584 ''', ''' 760 ''',
761 '''
585 <p>a <strong>one</strong> b <strong>two</strong> c</p> 762 <p>a <strong>one</strong> b <strong>two</strong> c</p>
586 '''); 763 ''');
587 764
588 validate('multi-line', ''' 765 validate(
766 'multi-line',
767 '''
589 before **first 768 before **first
590 second** after 769 second** after
591 ''', ''' 770 ''',
771 '''
592 <p>before <strong>first 772 <p>before <strong>first
593 second</strong> after</p> 773 second</strong> after</p>
594 '''); 774 ''');
595 }); 775 });
596 776
597 group('Emphasis and strong', () { 777 group('Emphasis and strong', () {
598 validate('single asterisks', ''' 778 validate(
779 'single asterisks',
780 '''
599 before *em* after 781 before *em* after
600 ''', ''' 782 ''',
783 '''
601 <p>before <em>em</em> after</p> 784 <p>before <em>em</em> after</p>
602 '''); 785 ''');
603 786
604 validate('single underscores', ''' 787 validate(
788 'single underscores',
789 '''
605 before _em_ after 790 before _em_ after
606 ''', ''' 791 ''',
792 '''
607 <p>before <em>em</em> after</p> 793 <p>before <em>em</em> after</p>
608 '''); 794 ''');
609 795
610 validate('double asterisks', ''' 796 validate(
797 'double asterisks',
798 '''
611 before **strong** after 799 before **strong** after
612 ''', ''' 800 ''',
801 '''
613 <p>before <strong>strong</strong> after</p> 802 <p>before <strong>strong</strong> after</p>
614 '''); 803 ''');
615 804
616 validate('double underscores', ''' 805 validate(
806 'double underscores',
807 '''
617 before __strong__ after 808 before __strong__ after
618 ''', ''' 809 ''',
810 '''
619 <p>before <strong>strong</strong> after</p> 811 <p>before <strong>strong</strong> after</p>
620 '''); 812 ''');
621 813
622 validate('unmatched asterisk', ''' 814 validate(
815 'unmatched asterisk',
816 '''
623 before *after 817 before *after
624 ''', ''' 818 ''',
819 '''
625 <p>before *after</p> 820 <p>before *after</p>
626 '''); 821 ''');
627 822
628 validate('unmatched underscore', ''' 823 validate(
824 'unmatched underscore',
825 '''
629 before _after 826 before _after
630 ''', ''' 827 ''',
828 '''
631 <p>before _after</p> 829 <p>before _after</p>
632 '''); 830 ''');
633 831
634 validate('multiple spans in one text', ''' 832 validate(
833 'multiple spans in one text',
834 '''
635 a *one* b _two_ c 835 a *one* b _two_ c
636 ''', ''' 836 ''',
837 '''
637 <p>a <em>one</em> b <em>two</em> c</p> 838 <p>a <em>one</em> b <em>two</em> c</p>
638 '''); 839 ''');
639 840
640 validate('multi-line', ''' 841 validate(
842 'multi-line',
843 '''
641 before *first 844 before *first
642 second* after 845 second* after
643 ''', ''' 846 ''',
847 '''
644 <p>before <em>first 848 <p>before <em>first
645 second</em> after</p> 849 second</em> after</p>
646 '''); 850 ''');
647 851
648 validate('not processed when surrounded by spaces', ''' 852 validate(
853 'not processed when surrounded by spaces',
854 '''
649 a * b * c _ d _ e 855 a * b * c _ d _ e
650 ''', ''' 856 ''',
857 '''
651 <p>a * b * c _ d _ e</p> 858 <p>a * b * c _ d _ e</p>
652 '''); 859 ''');
653 860
654 validate('strong then emphasis', ''' 861 validate(
862 'strong then emphasis',
863 '''
655 **strong***em* 864 **strong***em*
656 ''', ''' 865 ''',
866 '''
657 <p><strong>strong</strong><em>em</em></p> 867 <p><strong>strong</strong><em>em</em></p>
658 '''); 868 ''');
659 869
660 validate('emphasis then strong', ''' 870 validate(
871 'emphasis then strong',
872 '''
661 *em***strong** 873 *em***strong**
662 ''', ''' 874 ''',
875 '''
663 <p><em>em</em><strong>strong</strong></p> 876 <p><em>em</em><strong>strong</strong></p>
664 '''); 877 ''');
665 878
666 validate('emphasis inside strong', ''' 879 validate(
880 'emphasis inside strong',
881 '''
667 **strong *em*** 882 **strong *em***
668 ''', ''' 883 ''',
884 '''
669 <p><strong>strong <em>em</em></strong></p> 885 <p><strong>strong <em>em</em></strong></p>
670 '''); 886 ''');
671 887
672 validate('mismatched in nested', ''' 888 validate(
889 'mismatched in nested',
890 '''
673 *a _b* c_ 891 *a _b* c_
674 ''', ''' 892 ''',
893 '''
675 <p><em>a _b</em> c_</p> 894 <p><em>a _b</em> c_</p>
676 '''); 895 ''');
677 896
678 validate('cannot nest tags of same type', ''' 897 validate(
898 'cannot nest tags of same type',
899 '''
679 *a _b *c* d_ e* 900 *a _b *c* d_ e*
680 ''', ''' 901 ''',
902 '''
681 <p><em>a _b </em>c<em> d_ e</em></p> 903 <p><em>a _b </em>c<em> d_ e</em></p>
682 '''); 904 ''');
683 }); 905 });
684 906
685 group('Inline code', () { 907 group('Inline code', () {
686 validate('simple case', ''' 908 validate(
909 'simple case',
910 '''
687 before `source` after 911 before `source` after
688 ''', ''' 912 ''',
913 '''
689 <p>before <code>source</code> after</p> 914 <p>before <code>source</code> after</p>
690 '''); 915 ''');
691 916
692 validate('unmatched backtick', ''' 917 validate(
918 'unmatched backtick',
919 '''
693 before ` after 920 before ` after
694 ''', ''' 921 ''',
922 '''
695 <p>before ` after</p> 923 <p>before ` after</p>
696 '''); 924 ''');
697 validate('multiple spans in one text', ''' 925 validate(
926 'multiple spans in one text',
927 '''
698 a `one` b `two` c 928 a `one` b `two` c
699 ''', ''' 929 ''',
930 '''
700 <p>a <code>one</code> b <code>two</code> c</p> 931 <p>a <code>one</code> b <code>two</code> c</p>
701 '''); 932 ''');
702 933
703 validate('multi-line', ''' 934 validate(
935 'multi-line',
936 '''
704 before `first 937 before `first
705 second` after 938 second` after
706 ''', ''' 939 ''',
940 '''
707 <p>before <code>first 941 <p>before <code>first
708 second</code> after</p> 942 second</code> after</p>
709 '''); 943 ''');
710 944
711 validate('simple double backticks', ''' 945 validate(
946 'simple double backticks',
947 '''
712 before ``source`` after 948 before ``source`` after
713 ''', ''' 949 ''',
950 '''
714 <p>before <code>source</code> after</p> 951 <p>before <code>source</code> after</p>
715 '''); 952 ''');
716 953
717 validate('double backticks', ''' 954 validate(
955 'double backticks',
956 '''
718 before ``can `contain` backticks`` after 957 before ``can `contain` backticks`` after
719 ''', ''' 958 ''',
959 '''
720 <p>before <code>can `contain` backticks</code> after</p> 960 <p>before <code>can `contain` backticks</code> after</p>
721 '''); 961 ''');
722 962
723 validate('double backticks with spaces', ''' 963 validate(
964 'double backticks with spaces',
965 '''
724 before `` `tick` `` after 966 before `` `tick` `` after
725 ''', ''' 967 ''',
968 '''
726 <p>before <code>`tick`</code> after</p> 969 <p>before <code>`tick`</code> after</p>
727 '''); 970 ''');
728 971
729 validate('multiline double backticks with spaces', ''' 972 validate(
973 'multiline double backticks with spaces',
974 '''
730 before ``in `tick` 975 before ``in `tick`
731 another`` after 976 another`` after
732 ''', ''' 977 ''',
978 '''
733 <p>before <code>in `tick` 979 <p>before <code>in `tick`
734 another</code> after</p> 980 another</code> after</p>
735 '''); 981 ''');
736 982
737 validate('ignore markup inside code', ''' 983 validate(
984 'ignore markup inside code',
985 '''
738 before `*b* _c_` after 986 before `*b* _c_` after
739 ''', ''' 987 ''',
988 '''
740 <p>before <code>*b* _c_</code> after</p> 989 <p>before <code>*b* _c_</code> after</p>
741 '''); 990 ''');
742 991
743 validate('escape HTML characters', ''' 992 validate(
993 'escape HTML characters',
994 '''
744 `<&>` 995 `<&>`
745 ''', ''' 996 ''',
997 '''
746 <p><code>&lt;&amp;&gt;</code></p> 998 <p><code>&lt;&amp;&gt;</code></p>
747 '''); 999 ''');
748 1000
749 validate('escape HTML tags', ''' 1001 validate(
1002 'escape HTML tags',
1003 '''
750 '*' `<em>` 1004 '*' `<em>`
751 ''', ''' 1005 ''',
1006 '''
752 <p>'*' <code>&lt;em&gt;</code></p> 1007 <p>'*' <code>&lt;em&gt;</code></p>
753 '''); 1008 ''');
754 }); 1009 });
755 1010
756 group('HTML encoding', () { 1011 group('HTML encoding', () {
757 validate('less than and ampersand are escaped', ''' 1012 validate(
1013 'less than and ampersand are escaped',
1014 '''
758 < & 1015 < &
759 ''', ''' 1016 ''',
1017 '''
760 <p>&lt; &amp;</p> 1018 <p>&lt; &amp;</p>
761 '''); 1019 ''');
762 validate('greater than is not escaped', ''' 1020 validate(
1021 'greater than is not escaped',
1022 '''
763 not you > 1023 not you >
764 ''', ''' 1024 ''',
1025 '''
765 <p>not you ></p> 1026 <p>not you ></p>
766 '''); 1027 ''');
767 validate('existing entities are untouched', ''' 1028 validate(
1029 'existing entities are untouched',
1030 '''
768 &amp; 1031 &amp;
769 ''', ''' 1032 ''',
1033 '''
770 <p>&amp;</p> 1034 <p>&amp;</p>
771 '''); 1035 ''');
772 }); 1036 });
773 1037
774 group('Autolinks', () { 1038 group('Autolinks', () {
775 validate('basic link', ''' 1039 validate(
1040 'basic link',
1041 '''
776 before <http://foo.com/> after 1042 before <http://foo.com/> after
777 ''', ''' 1043 ''',
1044 '''
778 <p>before <a href="http://foo.com/">http://foo.com/</a> after</p> 1045 <p>before <a href="http://foo.com/">http://foo.com/</a> after</p>
779 '''); 1046 ''');
780 validate('handles ampersand in url', ''' 1047 validate(
1048 'handles ampersand in url',
1049 '''
781 <http://foo.com/?a=1&b=2> 1050 <http://foo.com/?a=1&b=2>
782 ''', ''' 1051 ''',
1052 '''
783 <p><a href="http://foo.com/?a=1&b=2">http://foo.com/?a=1&amp;b=2</a></p> 1053 <p><a href="http://foo.com/?a=1&b=2">http://foo.com/?a=1&amp;b=2</a></p>
784 '''); 1054 ''');
785 }); 1055 });
786 1056
787 group('Reference links', () { 1057 group('Reference links', () {
788 validate('double quotes for title', ''' 1058 validate(
1059 'double quotes for title',
1060 '''
789 links [are] [a] awesome 1061 links [are] [a] awesome
790 1062
791 [a]: http://foo.com "woo" 1063 [a]: http://foo.com "woo"
792 ''', ''' 1064 ''',
1065 '''
793 <p>links <a href="http://foo.com" title="woo">are</a> awesome</p> 1066 <p>links <a href="http://foo.com" title="woo">are</a> awesome</p>
794 '''); 1067 ''');
795 validate('single quoted title', """ 1068 validate(
1069 'single quoted title',
1070 """
796 links [are] [a] awesome 1071 links [are] [a] awesome
797 1072
798 [a]: http://foo.com 'woo' 1073 [a]: http://foo.com 'woo'
799 """, ''' 1074 """,
1075 '''
800 <p>links <a href="http://foo.com" title="woo">are</a> awesome</p> 1076 <p>links <a href="http://foo.com" title="woo">are</a> awesome</p>
801 '''); 1077 ''');
802 validate('parentheses for title', ''' 1078 validate(
1079 'parentheses for title',
1080 '''
803 links [are] [a] awesome 1081 links [are] [a] awesome
804 1082
805 [a]: http://foo.com (woo) 1083 [a]: http://foo.com (woo)
806 ''', ''' 1084 ''',
1085 '''
807 <p>links <a href="http://foo.com" title="woo">are</a> awesome</p> 1086 <p>links <a href="http://foo.com" title="woo">are</a> awesome</p>
808 '''); 1087 ''');
809 validate('no title', ''' 1088 validate(
1089 'no title',
1090 '''
810 links [are] [a] awesome 1091 links [are] [a] awesome
811 1092
812 [a]: http://foo.com 1093 [a]: http://foo.com
813 ''', ''' 1094 ''',
1095 '''
814 <p>links <a href="http://foo.com">are</a> awesome</p> 1096 <p>links <a href="http://foo.com">are</a> awesome</p>
815 '''); 1097 ''');
816 validate('unknown link becomes plaintext', ''' 1098 validate(
1099 'unknown link becomes plaintext',
1100 '''
817 [not] [known] 1101 [not] [known]
818 ''', ''' 1102 ''',
1103 '''
819 <p>[not] [known]</p> 1104 <p>[not] [known]</p>
820 '''); 1105 ''');
821 validate('can style link contents', ''' 1106 validate(
1107 'can style link contents',
1108 '''
822 links [*are*] [a] awesome 1109 links [*are*] [a] awesome
823 1110
824 [a]: http://foo.com 1111 [a]: http://foo.com
825 ''', ''' 1112 ''',
1113 '''
826 <p>links <a href="http://foo.com"><em>are</em></a> awesome</p> 1114 <p>links <a href="http://foo.com"><em>are</em></a> awesome</p>
827 '''); 1115 ''');
828 validate('inline styles after a bad link are processed', ''' 1116 validate(
1117 'inline styles after a bad link are processed',
1118 '''
829 [bad] `code` 1119 [bad] `code`
830 ''', ''' 1120 ''',
1121 '''
831 <p>[bad] <code>code</code></p> 1122 <p>[bad] <code>code</code></p>
832 '''); 1123 ''');
833 validate('empty reference uses text from link', ''' 1124 validate(
1125 'empty reference uses text from link',
1126 '''
834 links [are][] awesome 1127 links [are][] awesome
835 1128
836 [are]: http://foo.com 1129 [are]: http://foo.com
837 ''', ''' 1130 ''',
1131 '''
838 <p>links <a href="http://foo.com">are</a> awesome</p> 1132 <p>links <a href="http://foo.com">are</a> awesome</p>
839 '''); 1133 ''');
840 validate('references are case-insensitive', ''' 1134 validate(
1135 'references are case-insensitive',
1136 '''
841 links [ARE][] awesome 1137 links [ARE][] awesome
842 1138
843 [are]: http://foo.com 1139 [are]: http://foo.com
844 ''', ''' 1140 ''',
1141 '''
845 <p>links <a href="http://foo.com">ARE</a> awesome</p> 1142 <p>links <a href="http://foo.com">ARE</a> awesome</p>
846 '''); 1143 ''');
847 }); 1144 });
848 1145
849 group('Inline links', () { 1146 group('Inline links', () {
850 validate('double quotes for title', ''' 1147 validate(
1148 'double quotes for title',
1149 '''
851 links [are](http://foo.com "woo") awesome 1150 links [are](http://foo.com "woo") awesome
852 ''', ''' 1151 ''',
1152 '''
853 <p>links <a href="http://foo.com" title="woo">are</a> awesome</p> 1153 <p>links <a href="http://foo.com" title="woo">are</a> awesome</p>
854 '''); 1154 ''');
855 validate('no title', ''' 1155 validate(
1156 'no title',
1157 '''
856 links [are] (http://foo.com) awesome 1158 links [are] (http://foo.com) awesome
857 ''', ''' 1159 ''',
1160 '''
858 <p>links <a href="http://foo.com">are</a> awesome</p> 1161 <p>links <a href="http://foo.com">are</a> awesome</p>
859 '''); 1162 ''');
860 validate('can style link contents', ''' 1163 validate(
1164 'can style link contents',
1165 '''
861 links [*are*](http://foo.com) awesome 1166 links [*are*](http://foo.com) awesome
862 ''', ''' 1167 ''',
1168 '''
863 <p>links <a href="http://foo.com"><em>are</em></a> awesome</p> 1169 <p>links <a href="http://foo.com"><em>are</em></a> awesome</p>
864 '''); 1170 ''');
865 }); 1171 });
866 1172
867 group('Inline Images', () { 1173 group('Inline Images', () {
868 validate('image', ''' 1174 validate(
1175 'image',
1176 '''
869 ![](http://foo.com/foo.png) 1177 ![](http://foo.com/foo.png)
870 ''', ''' 1178 ''',
1179 '''
871 <p> 1180 <p>
872 <a href="http://foo.com/foo.png"> 1181 <a href="http://foo.com/foo.png">
873 <img src="http://foo.com/foo.png"></img> 1182 <img src="http://foo.com/foo.png"></img>
874 </a> 1183 </a>
875 </p> 1184 </p>
876 '''); 1185 ''');
877 1186
878 validate('alternate text', ''' 1187 validate(
1188 'alternate text',
1189 '''
879 ![alternate text](http://foo.com/foo.png) 1190 ![alternate text](http://foo.com/foo.png)
880 ''', ''' 1191 ''',
1192 '''
881 <p> 1193 <p>
882 <a href="http://foo.com/foo.png"> 1194 <a href="http://foo.com/foo.png">
883 <img alt="alternate text" src="http://foo.com/foo.png"></img> 1195 <img alt="alternate text" src="http://foo.com/foo.png"></img>
884 </a> 1196 </a>
885 </p> 1197 </p>
886 '''); 1198 ''');
887 1199
888 validate('title', ''' 1200 validate(
1201 'title',
1202 '''
889 ![](http://foo.com/foo.png "optional title") 1203 ![](http://foo.com/foo.png "optional title")
890 ''', ''' 1204 ''',
1205 '''
891 <p> 1206 <p>
892 <a href="http://foo.com/foo.png" title="optional title"> 1207 <a href="http://foo.com/foo.png" title="optional title">
893 <img src="http://foo.com/foo.png" title="optional title"></img> 1208 <img src="http://foo.com/foo.png" title="optional title"></img>
894 </a> 1209 </a>
895 </p> 1210 </p>
896 '''); 1211 ''');
897 validate('invalid alt text', ''' 1212 validate(
1213 'invalid alt text',
1214 '''
898 ![`alt`](http://foo.com/foo.png) 1215 ![`alt`](http://foo.com/foo.png)
899 ''', ''' 1216 ''',
1217 '''
900 <p> 1218 <p>
901 <a href="http://foo.com/foo.png"> 1219 <a href="http://foo.com/foo.png">
902 <img src="http://foo.com/foo.png"></img> 1220 <img src="http://foo.com/foo.png"></img>
903 </a> 1221 </a>
904 </p> 1222 </p>
905 '''); 1223 ''');
906 }); 1224 });
907 1225
908 group('Reference Images', () { 1226 group('Reference Images', () {
909 validate('image', ''' 1227 validate(
1228 'image',
1229 '''
910 ![][foo] 1230 ![][foo]
911 [foo]: http://foo.com/foo.png 1231 [foo]: http://foo.com/foo.png
912 ''', ''' 1232 ''',
1233 '''
913 <p> 1234 <p>
914 <a href="http://foo.com/foo.png"> 1235 <a href="http://foo.com/foo.png">
915 <img src="http://foo.com/foo.png"></img> 1236 <img src="http://foo.com/foo.png"></img>
916 </a> 1237 </a>
917 </p> 1238 </p>
918 '''); 1239 ''');
919 1240
920 validate('alternate text', ''' 1241 validate(
1242 'alternate text',
1243 '''
921 ![alternate text][foo] 1244 ![alternate text][foo]
922 [foo]: http://foo.com/foo.png 1245 [foo]: http://foo.com/foo.png
923 ''', ''' 1246 ''',
1247 '''
924 <p> 1248 <p>
925 <a href="http://foo.com/foo.png"> 1249 <a href="http://foo.com/foo.png">
926 <img alt="alternate text" src="http://foo.com/foo.png"></img> 1250 <img alt="alternate text" src="http://foo.com/foo.png"></img>
927 </a> 1251 </a>
928 </p> 1252 </p>
929 '''); 1253 ''');
930 1254
931 validate('title', ''' 1255 validate(
1256 'title',
1257 '''
932 ![][foo] 1258 ![][foo]
933 [foo]: http://foo.com/foo.png "optional title" 1259 [foo]: http://foo.com/foo.png "optional title"
934 ''', ''' 1260 ''',
1261 '''
935 <p> 1262 <p>
936 <a href="http://foo.com/foo.png" title="optional title"> 1263 <a href="http://foo.com/foo.png" title="optional title">
937 <img src="http://foo.com/foo.png" title="optional title"></img> 1264 <img src="http://foo.com/foo.png" title="optional title"></img>
938 </a> 1265 </a>
939 </p> 1266 </p>
940 '''); 1267 ''');
941 1268
942 validate('invalid alt text', ''' 1269 validate(
1270 'invalid alt text',
1271 '''
943 ![`alt`][foo] 1272 ![`alt`][foo]
944 [foo]: http://foo.com/foo.png "optional title" 1273 [foo]: http://foo.com/foo.png "optional title"
945 ''', ''' 1274 ''',
1275 '''
946 <p> 1276 <p>
947 <a href="http://foo.com/foo.png" title="optional title"> 1277 <a href="http://foo.com/foo.png" title="optional title">
948 <img src="http://foo.com/foo.png" title="optional title"></img> 1278 <img src="http://foo.com/foo.png" title="optional title"></img>
949 </a> 1279 </a>
950 </p> 1280 </p>
951 '''); 1281 ''');
952 }); 1282 });
953 1283
954 group('Resolver', () { 1284 group('Resolver', () {
955 nyanResolver(text) => new Text('~=[,,_${text}_,,]:3'); 1285 nyanResolver(text) => new Text('~=[,,_${text}_,,]:3');
956 1286
957 validate('simple link resolver', ''' 1287 validate(
1288 'simple link resolver',
1289 '''
958 resolve [this] thing 1290 resolve [this] thing
959 ''', ''' 1291 ''',
1292 '''
960 <p>resolve ~=[,,_this_,,]:3 thing</p> 1293 <p>resolve ~=[,,_this_,,]:3 thing</p>
961 ''', linkResolver: nyanResolver); 1294 ''',
962 validate('simple image resolver', ''' 1295 linkResolver: nyanResolver);
1296 validate(
1297 'simple image resolver',
1298 '''
963 resolve ![this] thing 1299 resolve ![this] thing
964 ''', ''' 1300 ''',
1301 '''
965 <p>resolve ~=[,,_this_,,]:3 thing</p> 1302 <p>resolve ~=[,,_this_,,]:3 thing</p>
966 ''', imageLinkResolver: nyanResolver); 1303 ''',
1304 imageLinkResolver: nyanResolver);
967 1305
968 validate('can resolve link containing inline tags', ''' 1306 validate(
1307 'can resolve link containing inline tags',
1308 '''
969 resolve [*star* _underline_] thing 1309 resolve [*star* _underline_] thing
970 ''', ''' 1310 ''',
1311 '''
971 <p>resolve ~=[,,_*star* _underline__,,]:3 thing</p> 1312 <p>resolve ~=[,,_*star* _underline__,,]:3 thing</p>
972 ''', linkResolver: nyanResolver); 1313 ''',
1314 linkResolver: nyanResolver);
973 }); 1315 });
974 1316
975 group('Custom inline syntax', () { 1317 group('Custom inline syntax', () {
976 var nyanSyntax = [new TextSyntax('nyan', sub: '~=[,,_,,]:3')]; 1318 var nyanSyntax = [new TextSyntax('nyan', sub: '~=[,,_,,]:3')];
977 1319
978 validate('simple inline syntax', ''' 1320 validate(
1321 'simple inline syntax',
1322 '''
979 nyan 1323 nyan
980 ''', ''' 1324 ''',
1325 '''
981 <p>~=[,,_,,]:3</p> 1326 <p>~=[,,_,,]:3</p>
982 ''', inlineSyntaxes: nyanSyntax); 1327 ''',
1328 inlineSyntaxes: nyanSyntax);
983 1329
984 validate('dart custom links', 'links [are<foo>] awesome', 1330 validate('dart custom links', 'links [are<foo>] awesome',
985 '<p>links <a>are&lt;foo></a> awesome</p>', 1331 '<p>links <a>are&lt;foo></a> awesome</p>',
986 linkResolver: (text) => new Element.text( 1332 linkResolver: (text) =>
987 'a', text.replaceAll('<', '&lt;'))); 1333 new Element.text('a', text.replaceAll('<', '&lt;')));
988 1334
989 // TODO(amouravski): need more tests here for custom syntaxes, as some 1335 // TODO(amouravski): need more tests here for custom syntaxes, as some
990 // things are not quite working properly. The regexps are sometime a little 1336 // things are not quite working properly. The regexps are sometime a little
991 // too greedy, I think. 1337 // too greedy, I think.
992 }); 1338 });
993 1339
994 group('Inline only', () { 1340 group('Inline only', () {
995 validate('simple line', ''' 1341 validate(
1342 'simple line',
1343 '''
996 This would normally create a paragraph. 1344 This would normally create a paragraph.
997 ''', ''' 1345 ''',
1346 '''
998 This would normally create a paragraph. 1347 This would normally create a paragraph.
999 ''', inlineOnly: true); 1348 ''',
1000 validate('strong and em', ''' 1349 inlineOnly: true);
1350 validate(
1351 'strong and em',
1352 '''
1001 This would _normally_ create a **paragraph**. 1353 This would _normally_ create a **paragraph**.
1002 ''', ''' 1354 ''',
1355 '''
1003 This would <em>normally</em> create a <strong>paragraph</strong>. 1356 This would <em>normally</em> create a <strong>paragraph</strong>.
1004 ''', inlineOnly: true); 1357 ''',
1005 validate('link', ''' 1358 inlineOnly: true);
1359 validate(
1360 'link',
1361 '''
1006 This [link](http://www.example.com/) will work normally. 1362 This [link](http://www.example.com/) will work normally.
1007 ''', ''' 1363 ''',
1364 '''
1008 This <a href="http://www.example.com/">link</a> will work normally. 1365 This <a href="http://www.example.com/">link</a> will work normally.
1009 ''', inlineOnly: true); 1366 ''',
1010 validate('references do not work', ''' 1367 inlineOnly: true);
1368 validate(
1369 'references do not work',
1370 '''
1011 [This][] shouldn't work, though. 1371 [This][] shouldn't work, though.
1012 ''', ''' 1372 ''',
1373 '''
1013 [This][] shouldn't work, though. 1374 [This][] shouldn't work, though.
1014 ''', inlineOnly: true); 1375 ''',
1015 validate('less than and ampersand are escaped', ''' 1376 inlineOnly: true);
1377 validate(
1378 'less than and ampersand are escaped',
1379 '''
1016 < & 1380 < &
1017 ''', ''' 1381 ''',
1382 '''
1018 &lt; &amp; 1383 &lt; &amp;
1019 ''', inlineOnly: true); 1384 ''',
1020 validate('keeps newlines', ''' 1385 inlineOnly: true);
1386 validate(
1387 'keeps newlines',
1388 '''
1021 This paragraph 1389 This paragraph
1022 continues after a newline. 1390 continues after a newline.
1023 ''', ''' 1391 ''',
1392 '''
1024 This paragraph 1393 This paragraph
1025 continues after a newline. 1394 continues after a newline.
1026 ''', inlineOnly: true); 1395 ''',
1027 validate('ignores block-level markdown syntax', ''' 1396 inlineOnly: true);
1397 validate(
1398 'ignores block-level markdown syntax',
1399 '''
1028 1. This will not be an <ol>. 1400 1. This will not be an <ol>.
1029 ''', ''' 1401 ''',
1402 '''
1030 1. This will not be an &lt;ol>. 1403 1. This will not be an &lt;ol>.
1031 ''', inlineOnly: true); 1404 ''',
1405 inlineOnly: true);
1032 }); 1406 });
1033 } 1407 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | test/util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698