test.js 6.7 KB

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