f16791728995e251cfc687cca305066c090bb33b
[myslice.git] / third-party / codemirror-3.15 / mode / markdown / test.js
1 (function() {
2   var mode = CodeMirror.getMode({tabSize: 4}, "markdown");
3   function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
4
5   MT("plainText",
6      "foo");
7
8   // Don't style single trailing space
9   MT("trailingSpace1",
10      "foo ");
11
12   // Two or more trailing spaces should be styled with line break character
13   MT("trailingSpace2",
14      "foo[trailing-space-a  ][trailing-space-new-line  ]");
15
16   MT("trailingSpace3",
17      "foo[trailing-space-a  ][trailing-space-b  ][trailing-space-new-line  ]");
18
19   MT("trailingSpace4",
20      "foo[trailing-space-a  ][trailing-space-b  ][trailing-space-a  ][trailing-space-new-line  ]");
21
22   // Code blocks using 4 spaces (regardless of CodeMirror.tabSize value)
23   MT("codeBlocksUsing4Spaces",
24      "    [comment foo]");
25
26   // Code blocks using 4 spaces with internal indentation
27   MT("codeBlocksUsing4SpacesIndentation",
28      "    [comment bar]",
29      "        [comment hello]",
30      "            [comment world]",
31      "    [comment foo]",
32      "bar");
33
34   // Code blocks using 4 spaces with internal indentation
35   MT("codeBlocksUsing4SpacesIndentation",
36      " foo",
37      "    [comment bar]",
38      "        [comment hello]",
39      "    [comment world]");
40
41   // Code blocks using 1 tab (regardless of CodeMirror.indentWithTabs value)
42   MT("codeBlocksUsing1Tab",
43      "\t[comment foo]");
44
45   // Inline code using backticks
46   MT("inlineCodeUsingBackticks",
47      "foo [comment `bar`]");
48
49   // Block code using single backtick (shouldn't work)
50   MT("blockCodeSingleBacktick",
51      "[comment `]",
52      "foo",
53      "[comment `]");
54
55   // Unclosed backticks
56   // Instead of simply marking as CODE, it would be nice to have an
57   // incomplete flag for CODE, that is styled slightly different.
58   MT("unclosedBackticks",
59      "foo [comment `bar]");
60
61   // Per documentation: "To include a literal backtick character within a
62   // code span, you can use multiple backticks as the opening and closing
63   // delimiters"
64   MT("doubleBackticks",
65      "[comment ``foo ` bar``]");
66
67   // Tests based on Dingus
68   // http://daringfireball.net/projects/markdown/dingus
69   //
70   // Multiple backticks within an inline code block
71   MT("consecutiveBackticks",
72      "[comment `foo```bar`]");
73
74   // Multiple backticks within an inline code block with a second code block
75   MT("consecutiveBackticks",
76      "[comment `foo```bar`] hello [comment `world`]");
77
78   // Unclosed with several different groups of backticks
79   MT("unclosedBackticks",
80      "[comment ``foo ``` bar` hello]");
81
82   // Closed with several different groups of backticks
83   MT("closedBackticks",
84      "[comment ``foo ``` bar` hello``] world");
85
86   // atx headers
87   // http://daringfireball.net/projects/markdown/syntax#header
88
89   MT("atxH1",
90      "[header # foo]");
91
92   MT("atxH2",
93      "[header ## foo]");
94
95   MT("atxH3",
96      "[header ### foo]");
97
98   MT("atxH4",
99      "[header #### foo]");
100
101   MT("atxH5",
102      "[header ##### foo]");
103
104   MT("atxH6",
105      "[header ###### foo]");
106
107   // H6 - 7x '#' should still be H6, per Dingus
108   // http://daringfireball.net/projects/markdown/dingus
109   MT("atxH6NotH7",
110      "[header ####### foo]");
111
112   // Setext headers - H1, H2
113   // Per documentation, "Any number of underlining =’s or -’s will work."
114   // http://daringfireball.net/projects/markdown/syntax#header
115   // Ideally, the text would be marked as `header` as well, but this is
116   // not really feasible at the moment. So, instead, we're testing against
117   // what works today, to avoid any regressions.
118   //
119   // Check if single underlining = works
120   MT("setextH1",
121      "foo",
122      "[header =]");
123
124   // Check if 3+ ='s work
125   MT("setextH1",
126      "foo",
127      "[header ===]");
128
129   // Check if single underlining - works
130   MT("setextH2",
131      "foo",
132      "[header -]");
133
134   // Check if 3+ -'s work
135   MT("setextH2",
136      "foo",
137      "[header ---]");
138
139   // Single-line blockquote with trailing space
140   MT("blockquoteSpace",
141      "[atom > foo]");
142
143   // Single-line blockquote
144   MT("blockquoteNoSpace",
145      "[atom >foo]");
146
147   // No blank line before blockquote
148   MT("blockquoteNoBlankLine",
149      "foo",
150      "[atom > bar]");
151
152   // Nested blockquote
153   MT("blockquoteSpace",
154      "[atom > foo]",
155      "[number > > foo]",
156      "[atom > > > foo]");
157
158   // Single-line blockquote followed by normal paragraph
159   MT("blockquoteThenParagraph",
160      "[atom >foo]",
161      "",
162      "bar");
163
164   // Multi-line blockquote (lazy mode)
165   MT("multiBlockquoteLazy",
166      "[atom >foo]",
167      "[atom bar]");
168
169   // Multi-line blockquote followed by normal paragraph (lazy mode)
170   MT("multiBlockquoteLazyThenParagraph",
171      "[atom >foo]",
172      "[atom bar]",
173      "",
174      "hello");
175
176   // Multi-line blockquote (non-lazy mode)
177   MT("multiBlockquote",
178      "[atom >foo]",
179      "[atom >bar]");
180
181   // Multi-line blockquote followed by normal paragraph (non-lazy mode)
182   MT("multiBlockquoteThenParagraph",
183      "[atom >foo]",
184      "[atom >bar]",
185      "",
186      "hello");
187
188   // Check list types
189
190   MT("listAsterisk",
191      "foo",
192      "bar",
193      "",
194      "[variable-2 * foo]",
195      "[variable-2 * bar]");
196
197   MT("listPlus",
198      "foo",
199      "bar",
200      "",
201      "[variable-2 + foo]",
202      "[variable-2 + bar]");
203
204   MT("listDash",
205      "foo",
206      "bar",
207      "",
208      "[variable-2 - foo]",
209      "[variable-2 - bar]");
210
211   MT("listNumber",
212      "foo",
213      "bar",
214      "",
215      "[variable-2 1. foo]",
216      "[variable-2 2. bar]");
217
218   // Lists require a preceding blank line (per Dingus)
219   MT("listBogus",
220      "foo",
221      "1. bar",
222      "2. hello");
223
224   // Formatting in lists (*)
225   MT("listAsteriskFormatting",
226      "[variable-2 * ][variable-2&em *foo*][variable-2  bar]",
227      "[variable-2 * ][variable-2&strong **foo**][variable-2  bar]",
228      "[variable-2 * ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2  bar]",
229      "[variable-2 * ][variable-2&comment `foo`][variable-2  bar]");
230
231   // Formatting in lists (+)
232   MT("listPlusFormatting",
233      "[variable-2 + ][variable-2&em *foo*][variable-2  bar]",
234      "[variable-2 + ][variable-2&strong **foo**][variable-2  bar]",
235      "[variable-2 + ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2  bar]",
236      "[variable-2 + ][variable-2&comment `foo`][variable-2  bar]");
237
238   // Formatting in lists (-)
239   MT("listDashFormatting",
240      "[variable-2 - ][variable-2&em *foo*][variable-2  bar]",
241      "[variable-2 - ][variable-2&strong **foo**][variable-2  bar]",
242      "[variable-2 - ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2  bar]",
243      "[variable-2 - ][variable-2&comment `foo`][variable-2  bar]");
244
245   // Formatting in lists (1.)
246   MT("listNumberFormatting",
247      "[variable-2 1. ][variable-2&em *foo*][variable-2  bar]",
248      "[variable-2 2. ][variable-2&strong **foo**][variable-2  bar]",
249      "[variable-2 3. ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2  bar]",
250      "[variable-2 4. ][variable-2&comment `foo`][variable-2  bar]");
251
252   // Paragraph lists
253   MT("listParagraph",
254      "[variable-2 * foo]",
255      "",
256      "[variable-2 * bar]");
257
258   // Multi-paragraph lists
259   //
260   // 4 spaces
261   MT("listMultiParagraph",
262      "[variable-2 * foo]",
263      "",
264      "[variable-2 * bar]",
265      "",
266      "    [variable-2 hello]");
267
268   // 4 spaces, extra blank lines (should still be list, per Dingus)
269   MT("listMultiParagraphExtra",
270      "[variable-2 * foo]",
271      "",
272      "[variable-2 * bar]",
273      "",
274      "",
275      "    [variable-2 hello]");
276
277   // 4 spaces, plus 1 space (should still be list, per Dingus)
278   MT("listMultiParagraphExtraSpace",
279      "[variable-2 * foo]",
280      "",
281      "[variable-2 * bar]",
282      "",
283      "     [variable-2 hello]",
284      "",
285      "    [variable-2 world]");
286
287   // 1 tab
288   MT("listTab",
289      "[variable-2 * foo]",
290      "",
291      "[variable-2 * bar]",
292      "",
293      "\t[variable-2 hello]");
294
295   // No indent
296   MT("listNoIndent",
297      "[variable-2 * foo]",
298      "",
299      "[variable-2 * bar]",
300      "",
301      "hello");
302
303   // Blockquote
304   MT("blockquote",
305      "[variable-2 * foo]",
306      "",
307      "[variable-2 * bar]",
308      "",
309      "    [variable-2&atom > hello]");
310
311   // Code block
312   MT("blockquoteCode",
313      "[variable-2 * foo]",
314      "",
315      "[variable-2 * bar]",
316      "",
317      "        [comment > hello]",
318      "",
319      "    [variable-2 world]");
320
321   // Code block followed by text
322   MT("blockquoteCodeText",
323      "[variable-2 * foo]",
324      "",
325      "    [variable-2 bar]",
326      "",
327      "        [comment hello]",
328      "",
329      "    [variable-2 world]");
330
331   // Nested list
332
333   MT("listAsteriskNested",
334      "[variable-2 * foo]",
335      "",
336      "    [variable-3 * bar]");
337
338   MT("listPlusNested",
339      "[variable-2 + foo]",
340      "",
341      "    [variable-3 + bar]");
342
343   MT("listDashNested",
344      "[variable-2 - foo]",
345      "",
346      "    [variable-3 - bar]");
347
348   MT("listNumberNested",
349      "[variable-2 1. foo]",
350      "",
351      "    [variable-3 2. bar]");
352
353   MT("listMixed",
354      "[variable-2 * foo]",
355      "",
356      "    [variable-3 + bar]",
357      "",
358      "        [keyword - hello]",
359      "",
360      "            [variable-2 1. world]");
361
362   MT("listBlockquote",
363      "[variable-2 * foo]",
364      "",
365      "    [variable-3 + bar]",
366      "",
367      "        [atom&variable-3 > hello]");
368
369   MT("listCode",
370      "[variable-2 * foo]",
371      "",
372      "    [variable-3 + bar]",
373      "",
374      "            [comment hello]");
375
376   // Code with internal indentation
377   MT("listCodeIndentation",
378      "[variable-2 * foo]",
379      "",
380      "        [comment bar]",
381      "            [comment hello]",
382      "                [comment world]",
383      "        [comment foo]",
384      "    [variable-2 bar]");
385
386   // List nesting edge cases
387   MT("listNested",
388     "[variable-2 * foo]",
389     "",
390     "    [variable-3 * bar]",
391     "",
392     "       [variable-2 hello]"
393   );
394   MT("listNested",
395     "[variable-2 * foo]",
396     "",
397     "    [variable-3 * bar]",
398     "",
399     "      [variable-3 * foo]"
400   );
401
402   // Code followed by text
403   MT("listCodeText",
404      "[variable-2 * foo]",
405      "",
406      "        [comment bar]",
407      "",
408      "hello");
409
410   // Following tests directly from official Markdown documentation
411   // http://daringfireball.net/projects/markdown/syntax#hr
412
413   MT("hrSpace",
414      "[hr * * *]");
415
416   MT("hr",
417      "[hr ***]");
418
419   MT("hrLong",
420      "[hr *****]");
421
422   MT("hrSpaceDash",
423      "[hr - - -]");
424
425   MT("hrDashLong",
426      "[hr ---------------------------------------]");
427
428   // Inline link with title
429   MT("linkTitle",
430      "[link [[foo]]][string (http://example.com/ \"bar\")] hello");
431
432   // Inline link without title
433   MT("linkNoTitle",
434      "[link [[foo]]][string (http://example.com/)] bar");
435
436   // Inline link with image
437   MT("linkImage",
438      "[link [[][tag ![[foo]]][string (http://example.com/)][link ]]][string (http://example.com/)] bar");
439
440   // Inline link with Em
441   MT("linkEm",
442      "[link [[][link&em *foo*][link ]]][string (http://example.com/)] bar");
443
444   // Inline link with Strong
445   MT("linkStrong",
446      "[link [[][link&strong **foo**][link ]]][string (http://example.com/)] bar");
447
448   // Inline link with EmStrong
449   MT("linkEmStrong",
450      "[link [[][link&strong **][link&em&strong *foo**][link&em *][link ]]][string (http://example.com/)] bar");
451
452   // Image with title
453   MT("imageTitle",
454      "[tag ![[foo]]][string (http://example.com/ \"bar\")] hello");
455
456   // Image without title
457   MT("imageNoTitle",
458      "[tag ![[foo]]][string (http://example.com/)] bar");
459
460   // Image with asterisks
461   MT("imageAsterisks",
462      "[tag ![[*foo*]]][string (http://example.com/)] bar");
463
464   // Not a link. Should be normal text due to square brackets being used
465   // regularly in text, especially in quoted material, and no space is allowed
466   // between square brackets and parentheses (per Dingus).
467   MT("notALink",
468      "[[foo]] (bar)");
469
470   // Reference-style links
471   MT("linkReference",
472      "[link [[foo]]][string [[bar]]] hello");
473
474   // Reference-style links with Em
475   MT("linkReferenceEm",
476      "[link [[][link&em *foo*][link ]]][string [[bar]]] hello");
477
478   // Reference-style links with Strong
479   MT("linkReferenceStrong",
480      "[link [[][link&strong **foo**][link ]]][string [[bar]]] hello");
481
482   // Reference-style links with EmStrong
483   MT("linkReferenceEmStrong",
484      "[link [[][link&strong **][link&em&strong *foo**][link&em *][link ]]][string [[bar]]] hello");
485
486   // Reference-style links with optional space separator (per docuentation)
487   // "You can optionally use a space to separate the sets of brackets"
488   MT("linkReferenceSpace",
489      "[link [[foo]]] [string [[bar]]] hello");
490
491   // Should only allow a single space ("...use *a* space...")
492   MT("linkReferenceDoubleSpace",
493      "[[foo]]  [[bar]] hello");
494
495   // Reference-style links with implicit link name
496   MT("linkImplicit",
497      "[link [[foo]]][string [[]]] hello");
498
499   // @todo It would be nice if, at some point, the document was actually
500   // checked to see if the referenced link exists
501
502   // Link label, for reference-style links (taken from documentation)
503
504   MT("labelNoTitle",
505      "[link [[foo]]:] [string http://example.com/]");
506
507   MT("labelIndented",
508      "   [link [[foo]]:] [string http://example.com/]");
509
510   MT("labelSpaceTitle",
511      "[link [[foo bar]]:] [string http://example.com/ \"hello\"]");
512
513   MT("labelDoubleTitle",
514      "[link [[foo bar]]:] [string http://example.com/ \"hello\"] \"world\"");
515
516   MT("labelTitleDoubleQuotes",
517      "[link [[foo]]:] [string http://example.com/  \"bar\"]");
518
519   MT("labelTitleSingleQuotes",
520      "[link [[foo]]:] [string http://example.com/  'bar']");
521
522   MT("labelTitleParenthese",
523      "[link [[foo]]:] [string http://example.com/  (bar)]");
524
525   MT("labelTitleInvalid",
526      "[link [[foo]]:] [string http://example.com/] bar");
527
528   MT("labelLinkAngleBrackets",
529      "[link [[foo]]:] [string <http://example.com/>  \"bar\"]");
530
531   MT("labelTitleNextDoubleQuotes",
532      "[link [[foo]]:] [string http://example.com/]",
533      "[string \"bar\"] hello");
534
535   MT("labelTitleNextSingleQuotes",
536      "[link [[foo]]:] [string http://example.com/]",
537      "[string 'bar'] hello");
538
539   MT("labelTitleNextParenthese",
540      "[link [[foo]]:] [string http://example.com/]",
541      "[string (bar)] hello");
542
543   MT("labelTitleNextMixed",
544      "[link [[foo]]:] [string http://example.com/]",
545      "(bar\" hello");
546
547   MT("linkWeb",
548      "[link <http://example.com/>] foo");
549
550   MT("linkWebDouble",
551      "[link <http://example.com/>] foo [link <http://example.com/>]");
552
553   MT("linkEmail",
554      "[link <user@example.com>] foo");
555
556   MT("linkEmailDouble",
557      "[link <user@example.com>] foo [link <user@example.com>]");
558
559   MT("emAsterisk",
560      "[em *foo*] bar");
561
562   MT("emUnderscore",
563      "[em _foo_] bar");
564
565   MT("emInWordAsterisk",
566      "foo[em *bar*]hello");
567
568   MT("emInWordUnderscore",
569      "foo[em _bar_]hello");
570
571   // Per documentation: "...surround an * or _ with spaces, it’ll be
572   // treated as a literal asterisk or underscore."
573
574   MT("emEscapedBySpaceIn",
575      "foo [em _bar _ hello_] world");
576
577   MT("emEscapedBySpaceOut",
578      "foo _ bar[em _hello_]world");
579
580   // Unclosed emphasis characters
581   // Instead of simply marking as EM / STRONG, it would be nice to have an
582   // incomplete flag for EM and STRONG, that is styled slightly different.
583   MT("emIncompleteAsterisk",
584      "foo [em *bar]");
585
586   MT("emIncompleteUnderscore",
587      "foo [em _bar]");
588
589   MT("strongAsterisk",
590      "[strong **foo**] bar");
591
592   MT("strongUnderscore",
593      "[strong __foo__] bar");
594
595   MT("emStrongAsterisk",
596      "[em *foo][em&strong **bar*][strong hello**] world");
597
598   MT("emStrongUnderscore",
599      "[em _foo][em&strong __bar_][strong hello__] world");
600
601   // "...same character must be used to open and close an emphasis span.""
602   MT("emStrongMixed",
603      "[em _foo][em&strong **bar*hello__ world]");
604
605   MT("emStrongMixed",
606      "[em *foo][em&strong __bar_hello** world]");
607
608   // These characters should be escaped:
609   // \   backslash
610   // `   backtick
611   // *   asterisk
612   // _   underscore
613   // {}  curly braces
614   // []  square brackets
615   // ()  parentheses
616   // #   hash mark
617   // +   plus sign
618   // -   minus sign (hyphen)
619   // .   dot
620   // !   exclamation mark
621
622   MT("escapeBacktick",
623      "foo \\`bar\\`");
624
625   MT("doubleEscapeBacktick",
626      "foo \\\\[comment `bar\\\\`]");
627
628   MT("escapeAsterisk",
629      "foo \\*bar\\*");
630
631   MT("doubleEscapeAsterisk",
632      "foo \\\\[em *bar\\\\*]");
633
634   MT("escapeUnderscore",
635      "foo \\_bar\\_");
636
637   MT("doubleEscapeUnderscore",
638      "foo \\\\[em _bar\\\\_]");
639
640   MT("escapeHash",
641      "\\# foo");
642
643   MT("doubleEscapeHash",
644      "\\\\# foo");
645
646
647   // Tests to make sure GFM-specific things aren't getting through
648
649   MT("taskList",
650      "[variable-2 * [ ]] bar]");
651
652   MT("fencedCodeBlocks",
653      "[comment ```]",
654      "foo",
655      "[comment ```]");
656 })();