1
0

test.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://codemirror.net/LICENSE
  3. (function() {
  4. var mode = CodeMirror.getMode({tabSize: 4}, "gfm");
  5. function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
  6. var modeHighlightFormatting = CodeMirror.getMode({tabSize: 4}, {name: "gfm", highlightFormatting: true});
  7. function FT(name) { test.mode(name, modeHighlightFormatting, Array.prototype.slice.call(arguments, 1)); }
  8. FT("codeBackticks",
  9. "[comment&formatting&formatting-code `][comment foo][comment&formatting&formatting-code `]");
  10. FT("doubleBackticks",
  11. "[comment&formatting&formatting-code ``][comment foo ` bar][comment&formatting&formatting-code ``]");
  12. FT("codeBlock",
  13. "[comment&formatting&formatting-code-block ```css]",
  14. "[tag foo]",
  15. "[comment&formatting&formatting-code-block ```]");
  16. FT("taskList",
  17. "[variable-2&formatting&formatting-list&formatting-list-ul - ][meta&formatting&formatting-task [ ]]][variable-2 foo]",
  18. "[variable-2&formatting&formatting-list&formatting-list-ul - ][property&formatting&formatting-task [x]]][variable-2 foo]");
  19. FT("formatting_strikethrough",
  20. "[strikethrough&formatting&formatting-strikethrough ~~][strikethrough foo][strikethrough&formatting&formatting-strikethrough ~~]");
  21. FT("formatting_strikethrough",
  22. "foo [strikethrough&formatting&formatting-strikethrough ~~][strikethrough bar][strikethrough&formatting&formatting-strikethrough ~~]");
  23. MT("emInWordAsterisk",
  24. "foo[em *bar*]hello");
  25. MT("emInWordUnderscore",
  26. "foo_bar_hello");
  27. MT("emStrongUnderscore",
  28. "[strong __][em&strong _foo__][em _] bar");
  29. MT("fencedCodeBlocks",
  30. "[comment ```]",
  31. "[comment foo]",
  32. "",
  33. "[comment ```]",
  34. "bar");
  35. MT("fencedCodeBlockModeSwitching",
  36. "[comment ```javascript]",
  37. "[variable foo]",
  38. "",
  39. "[comment ```]",
  40. "bar");
  41. MT("taskListAsterisk",
  42. "[variable-2 * []] foo]", // Invalid; must have space or x between []
  43. "[variable-2 * [ ]]bar]", // Invalid; must have space after ]
  44. "[variable-2 * [x]]hello]", // Invalid; must have space after ]
  45. "[variable-2 * ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links
  46. " [variable-3 * ][property [x]]][variable-3 foo]"); // Valid; can be nested
  47. MT("taskListPlus",
  48. "[variable-2 + []] foo]", // Invalid; must have space or x between []
  49. "[variable-2 + [ ]]bar]", // Invalid; must have space after ]
  50. "[variable-2 + [x]]hello]", // Invalid; must have space after ]
  51. "[variable-2 + ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links
  52. " [variable-3 + ][property [x]]][variable-3 foo]"); // Valid; can be nested
  53. MT("taskListDash",
  54. "[variable-2 - []] foo]", // Invalid; must have space or x between []
  55. "[variable-2 - [ ]]bar]", // Invalid; must have space after ]
  56. "[variable-2 - [x]]hello]", // Invalid; must have space after ]
  57. "[variable-2 - ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links
  58. " [variable-3 - ][property [x]]][variable-3 foo]"); // Valid; can be nested
  59. MT("taskListNumber",
  60. "[variable-2 1. []] foo]", // Invalid; must have space or x between []
  61. "[variable-2 2. [ ]]bar]", // Invalid; must have space after ]
  62. "[variable-2 3. [x]]hello]", // Invalid; must have space after ]
  63. "[variable-2 4. ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links
  64. " [variable-3 1. ][property [x]]][variable-3 foo]"); // Valid; can be nested
  65. MT("SHA",
  66. "foo [link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] bar");
  67. MT("SHAEmphasis",
  68. "[em *foo ][em&link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2][em *]");
  69. MT("shortSHA",
  70. "foo [link be6a8cc] bar");
  71. MT("tooShortSHA",
  72. "foo be6a8c bar");
  73. MT("longSHA",
  74. "foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd22 bar");
  75. MT("badSHA",
  76. "foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cg2 bar");
  77. MT("userSHA",
  78. "foo [link bar@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] hello");
  79. MT("userSHAEmphasis",
  80. "[em *foo ][em&link bar@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2][em *]");
  81. MT("userProjectSHA",
  82. "foo [link bar/hello@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] world");
  83. MT("userProjectSHAEmphasis",
  84. "[em *foo ][em&link bar/hello@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2][em *]");
  85. MT("num",
  86. "foo [link #1] bar");
  87. MT("numEmphasis",
  88. "[em *foo ][em&link #1][em *]");
  89. MT("badNum",
  90. "foo #1bar hello");
  91. MT("userNum",
  92. "foo [link bar#1] hello");
  93. MT("userNumEmphasis",
  94. "[em *foo ][em&link bar#1][em *]");
  95. MT("userProjectNum",
  96. "foo [link bar/hello#1] world");
  97. MT("userProjectNumEmphasis",
  98. "[em *foo ][em&link bar/hello#1][em *]");
  99. MT("vanillaLink",
  100. "foo [link http://www.example.com/] bar");
  101. MT("vanillaLinkPunctuation",
  102. "foo [link http://www.example.com/]. bar");
  103. MT("vanillaLinkExtension",
  104. "foo [link http://www.example.com/index.html] bar");
  105. MT("vanillaLinkEmphasis",
  106. "foo [em *][em&link http://www.example.com/index.html][em *] bar");
  107. MT("notALink",
  108. "[comment ```css]",
  109. "[tag foo] {[property color]:[keyword black];}",
  110. "[comment ```][link http://www.example.com/]");
  111. MT("notALink",
  112. "[comment ``foo `bar` http://www.example.com/``] hello");
  113. MT("notALink",
  114. "[comment `foo]",
  115. "[link http://www.example.com/]",
  116. "[comment `foo]",
  117. "",
  118. "[link http://www.example.com/]");
  119. MT("headerCodeBlockGithub",
  120. "[header&header-1 # heading]",
  121. "",
  122. "[comment ```]",
  123. "[comment code]",
  124. "[comment ```]",
  125. "",
  126. "Commit: [link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2]",
  127. "Issue: [link #1]",
  128. "Link: [link http://www.example.com/]");
  129. MT("strikethrough",
  130. "[strikethrough ~~foo~~]");
  131. MT("strikethroughWithStartingSpace",
  132. "~~ foo~~");
  133. MT("strikethroughUnclosedStrayTildes",
  134. "[strikethrough ~~foo~~~]");
  135. MT("strikethroughUnclosedStrayTildes",
  136. "[strikethrough ~~foo ~~]");
  137. MT("strikethroughUnclosedStrayTildes",
  138. "[strikethrough ~~foo ~~ bar]");
  139. MT("strikethroughUnclosedStrayTildes",
  140. "[strikethrough ~~foo ~~ bar~~]hello");
  141. MT("strikethroughOneLetter",
  142. "[strikethrough ~~a~~]");
  143. MT("strikethroughWrapped",
  144. "[strikethrough ~~foo]",
  145. "[strikethrough foo~~]");
  146. MT("strikethroughParagraph",
  147. "[strikethrough ~~foo]",
  148. "",
  149. "foo[strikethrough ~~bar]");
  150. MT("strikethroughEm",
  151. "[strikethrough ~~foo][em&strikethrough *bar*][strikethrough ~~]");
  152. MT("strikethroughEm",
  153. "[em *][em&strikethrough ~~foo~~][em *]");
  154. MT("strikethroughStrong",
  155. "[strikethrough ~~][strong&strikethrough **foo**][strikethrough ~~]");
  156. MT("strikethroughStrong",
  157. "[strong **][strong&strikethrough ~~foo~~][strong **]");
  158. })();