test.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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("fencedCodeBlockModeSwitchingObjc",
  42. "[comment ```objective-c]",
  43. "[keyword @property] [variable NSString] [operator *] [variable foo];",
  44. "[comment ```]",
  45. "bar");
  46. MT("fencedCodeBlocksNoTildes",
  47. "~~~",
  48. "foo",
  49. "~~~");
  50. MT("taskListAsterisk",
  51. "[variable-2 * []] foo]", // Invalid; must have space or x between []
  52. "[variable-2 * [ ]]bar]", // Invalid; must have space after ]
  53. "[variable-2 * [x]]hello]", // Invalid; must have space after ]
  54. "[variable-2 * ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links
  55. " [variable-3 * ][property [x]]][variable-3 foo]"); // Valid; can be nested
  56. MT("taskListPlus",
  57. "[variable-2 + []] foo]", // Invalid; must have space or x between []
  58. "[variable-2 + [ ]]bar]", // Invalid; must have space after ]
  59. "[variable-2 + [x]]hello]", // Invalid; must have space after ]
  60. "[variable-2 + ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links
  61. " [variable-3 + ][property [x]]][variable-3 foo]"); // Valid; can be nested
  62. MT("taskListDash",
  63. "[variable-2 - []] foo]", // Invalid; must have space or x between []
  64. "[variable-2 - [ ]]bar]", // Invalid; must have space after ]
  65. "[variable-2 - [x]]hello]", // Invalid; must have space after ]
  66. "[variable-2 - ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links
  67. " [variable-3 - ][property [x]]][variable-3 foo]"); // Valid; can be nested
  68. MT("taskListNumber",
  69. "[variable-2 1. []] foo]", // Invalid; must have space or x between []
  70. "[variable-2 2. [ ]]bar]", // Invalid; must have space after ]
  71. "[variable-2 3. [x]]hello]", // Invalid; must have space after ]
  72. "[variable-2 4. ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links
  73. " [variable-3 1. ][property [x]]][variable-3 foo]"); // Valid; can be nested
  74. MT("SHA",
  75. "foo [link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] bar");
  76. MT("SHAEmphasis",
  77. "[em *foo ][em&link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2][em *]");
  78. MT("shortSHA",
  79. "foo [link be6a8cc] bar");
  80. MT("tooShortSHA",
  81. "foo be6a8c bar");
  82. MT("longSHA",
  83. "foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd22 bar");
  84. MT("badSHA",
  85. "foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cg2 bar");
  86. MT("userSHA",
  87. "foo [link bar@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] hello");
  88. MT("userSHAEmphasis",
  89. "[em *foo ][em&link bar@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2][em *]");
  90. MT("userProjectSHA",
  91. "foo [link bar/hello@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] world");
  92. MT("userProjectSHAEmphasis",
  93. "[em *foo ][em&link bar/hello@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2][em *]");
  94. MT("num",
  95. "foo [link #1] bar");
  96. MT("numEmphasis",
  97. "[em *foo ][em&link #1][em *]");
  98. MT("badNum",
  99. "foo #1bar hello");
  100. MT("userNum",
  101. "foo [link bar#1] hello");
  102. MT("userNumEmphasis",
  103. "[em *foo ][em&link bar#1][em *]");
  104. MT("userProjectNum",
  105. "foo [link bar/hello#1] world");
  106. MT("userProjectNumEmphasis",
  107. "[em *foo ][em&link bar/hello#1][em *]");
  108. MT("vanillaLink",
  109. "foo [link http://www.example.com/] bar");
  110. MT("vanillaLinkNoScheme",
  111. "foo [link www.example.com] bar");
  112. MT("vanillaLinkHttps",
  113. "foo [link https://www.example.com/] bar");
  114. MT("vanillaLinkDataSchema",
  115. "foo [link data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==] bar");
  116. MT("vanillaLinkPunctuation",
  117. "foo [link http://www.example.com/]. bar");
  118. MT("vanillaLinkExtension",
  119. "foo [link http://www.example.com/index.html] bar");
  120. MT("vanillaLinkEmphasis",
  121. "foo [em *][em&link http://www.example.com/index.html][em *] bar");
  122. MT("notALink",
  123. "foo asfd:asdf bar");
  124. MT("notALink",
  125. "[comment ```css]",
  126. "[tag foo] {[property color]:[keyword black];}",
  127. "[comment ```][link http://www.example.com/]");
  128. MT("notALink",
  129. "[comment ``foo `bar` http://www.example.com/``] hello");
  130. MT("notALink",
  131. "[comment `foo]",
  132. "[comment&link http://www.example.com/]",
  133. "[comment `] foo",
  134. "",
  135. "[link http://www.example.com/]");
  136. MT("headerCodeBlockGithub",
  137. "[header&header-1 # heading]",
  138. "",
  139. "[comment ```]",
  140. "[comment code]",
  141. "[comment ```]",
  142. "",
  143. "Commit: [link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2]",
  144. "Issue: [link #1]",
  145. "Link: [link http://www.example.com/]");
  146. MT("strikethrough",
  147. "[strikethrough ~~foo~~]");
  148. MT("strikethroughWithStartingSpace",
  149. "~~ foo~~");
  150. MT("strikethroughUnclosedStrayTildes",
  151. "[strikethrough ~~foo~~~]");
  152. MT("strikethroughUnclosedStrayTildes",
  153. "[strikethrough ~~foo ~~]");
  154. MT("strikethroughUnclosedStrayTildes",
  155. "[strikethrough ~~foo ~~ bar]");
  156. MT("strikethroughUnclosedStrayTildes",
  157. "[strikethrough ~~foo ~~ bar~~]hello");
  158. MT("strikethroughOneLetter",
  159. "[strikethrough ~~a~~]");
  160. MT("strikethroughWrapped",
  161. "[strikethrough ~~foo]",
  162. "[strikethrough foo~~]");
  163. MT("strikethroughParagraph",
  164. "[strikethrough ~~foo]",
  165. "",
  166. "foo[strikethrough ~~bar]");
  167. MT("strikethroughEm",
  168. "[strikethrough ~~foo][em&strikethrough *bar*][strikethrough ~~]");
  169. MT("strikethroughEm",
  170. "[em *][em&strikethrough ~~foo~~][em *]");
  171. MT("strikethroughStrong",
  172. "[strikethrough ~~][strong&strikethrough **foo**][strikethrough ~~]");
  173. MT("strikethroughStrong",
  174. "[strong **][strong&strikethrough ~~foo~~][strong **]");
  175. })();