test.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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) {
  7. test.mode(name, mode, Array.prototype.slice.call(arguments, 1))
  8. }
  9. var modeHighlightFormatting = CodeMirror.getMode(config, { name: 'gfm', highlightFormatting: true })
  10. function FT(name) {
  11. test.mode(name, modeHighlightFormatting, Array.prototype.slice.call(arguments, 1))
  12. }
  13. FT('codeBackticks', '[comment&formatting&formatting-code `][comment foo][comment&formatting&formatting-code `]')
  14. FT('doubleBackticks', '[comment&formatting&formatting-code ``][comment foo ` bar][comment&formatting&formatting-code ``]')
  15. FT(
  16. '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. )
  20. FT('formatting_strikethrough', '[strikethrough&formatting&formatting-strikethrough ~~][strikethrough foo][strikethrough&formatting&formatting-strikethrough ~~]')
  21. FT('formatting_strikethrough', 'foo [strikethrough&formatting&formatting-strikethrough ~~][strikethrough bar][strikethrough&formatting&formatting-strikethrough ~~]')
  22. FT('formatting_emoji', 'foo [builtin&formatting&formatting-emoji :smile:] foo')
  23. MT('emInWordAsterisk', 'foo[em *bar*]hello')
  24. MT('emInWordUnderscore', 'foo_bar_hello')
  25. MT('emStrongUnderscore', '[em&strong ___foo___] bar')
  26. MT(
  27. 'taskListAsterisk',
  28. '[variable-2 * ][link&variable-2 [[]]][variable-2 foo]', // Invalid; must have space or x between []
  29. '[variable-2 * ][link&variable-2 [[ ]]][variable-2 bar]', // Invalid; must have space after ]
  30. '[variable-2 * ][link&variable-2 [[x]]][variable-2 hello]', // Invalid; must have space after ]
  31. '[variable-2 * ][meta [ ]]][variable-2 ][link&variable-2 [[world]]]', // Valid; tests reference style links
  32. ' [variable-3 * ][property [x]]][variable-3 foo]'
  33. ) // Valid; can be nested
  34. MT(
  35. 'taskListPlus',
  36. '[variable-2 + ][link&variable-2 [[]]][variable-2 foo]', // Invalid; must have space or x between []
  37. '[variable-2 + ][link&variable-2 [[x]]][variable-2 hello]', // Invalid; must have space after ]
  38. '[variable-2 + ][meta [ ]]][variable-2 ][link&variable-2 [[world]]]', // Valid; tests reference style links
  39. ' [variable-3 + ][property [x]]][variable-3 foo]'
  40. ) // Valid; can be nested
  41. MT(
  42. 'taskListDash',
  43. '[variable-2 - ][link&variable-2 [[]]][variable-2 foo]', // Invalid; must have space or x between []
  44. '[variable-2 - ][link&variable-2 [[x]]][variable-2 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]'
  47. ) // Valid; can be nested
  48. MT(
  49. 'taskListNumber',
  50. '[variable-2 1. ][link&variable-2 [[]]][variable-2 foo]', // Invalid; must have space or x between []
  51. '[variable-2 2. ][link&variable-2 [[ ]]][variable-2 bar]', // Invalid; must have space after ]
  52. '[variable-2 3. ][meta [ ]]][variable-2 world]', // Valid; tests reference style links
  53. ' [variable-3 1. ][property [x]]][variable-3 foo]'
  54. ) // Valid; can be nested
  55. MT('SHA', 'foo [link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] bar')
  56. MT('SHAEmphasis', '[em *foo ][em&link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2][em *]')
  57. MT('shortSHA', 'foo [link be6a8cc] bar')
  58. MT('tooShortSHA', 'foo be6a8c bar')
  59. MT('longSHA', 'foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd22 bar')
  60. MT('badSHA', 'foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cg2 bar')
  61. MT('userSHA', 'foo [link bar@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] hello')
  62. MT('userSHAEmphasis', '[em *foo ][em&link bar@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2][em *]')
  63. MT('userProjectSHA', 'foo [link bar/hello@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] world')
  64. MT('userProjectSHAEmphasis', '[em *foo ][em&link bar/hello@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2][em *]')
  65. MT('wordSHA', 'ask for feedback')
  66. MT('num', 'foo [link #1] bar')
  67. MT('numEmphasis', '[em *foo ][em&link #1][em *]')
  68. MT('badNum', 'foo #1bar hello')
  69. MT('userNum', 'foo [link bar#1] hello')
  70. MT('userNumEmphasis', '[em *foo ][em&link bar#1][em *]')
  71. MT('userProjectNum', 'foo [link bar/hello#1] world')
  72. MT('userProjectNumEmphasis', '[em *foo ][em&link bar/hello#1][em *]')
  73. MT('vanillaLink', 'foo [link http://www.example.com/] bar')
  74. MT('vanillaLinkNoScheme', 'foo [link www.example.com] bar')
  75. MT('vanillaLinkHttps', 'foo [link https://www.example.com/] bar')
  76. MT('vanillaLinkDataSchema', 'foo [link data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==] bar')
  77. MT('vanillaLinkPunctuation', 'foo [link http://www.example.com/]. bar')
  78. MT('vanillaLinkExtension', 'foo [link http://www.example.com/index.html] bar')
  79. MT('vanillaLinkEmphasis', 'foo [em *][em&link http://www.example.com/index.html][em *] bar')
  80. MT('notALink', 'foo asfd:asdf bar')
  81. MT('notALink', '[comment ``foo `bar` http://www.example.com/``] hello')
  82. MT('notALink', '[comment `foo]', '[comment&link http://www.example.com/]', '[comment `] foo', '', '[link http://www.example.com/]')
  83. MT('strikethrough', '[strikethrough ~~foo~~]')
  84. MT('strikethroughWithStartingSpace', '~~ foo~~')
  85. MT('strikethroughUnclosedStrayTildes', '[strikethrough ~~foo~~~]')
  86. MT('strikethroughUnclosedStrayTildes', '[strikethrough ~~foo ~~]')
  87. MT('strikethroughUnclosedStrayTildes', '[strikethrough ~~foo ~~ bar]')
  88. MT('strikethroughUnclosedStrayTildes', '[strikethrough ~~foo ~~ bar~~]hello')
  89. MT('strikethroughOneLetter', '[strikethrough ~~a~~]')
  90. MT('strikethroughWrapped', '[strikethrough ~~foo]', '[strikethrough foo~~]')
  91. MT('strikethroughParagraph', '[strikethrough ~~foo]', '', 'foo[strikethrough ~~bar]')
  92. MT('strikethroughEm', '[strikethrough ~~foo][em&strikethrough *bar*][strikethrough ~~]')
  93. MT('strikethroughEm', '[em *][em&strikethrough ~~foo~~][em *]')
  94. MT('strikethroughStrong', '[strikethrough ~~][strong&strikethrough **foo**][strikethrough ~~]')
  95. MT('strikethroughStrong', '[strong **][strong&strikethrough ~~foo~~][strong **]')
  96. MT('emoji', 'text [builtin :blush:] text [builtin :v:] text [builtin :+1:] text', ':text text: [builtin :smiley_cat:]')
  97. })()