test.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. (function() {
  2. var mode = CodeMirror.getMode({tabSize: 4}, "gfm");
  3. function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
  4. var modeHighlightFormatting = CodeMirror.getMode({tabSize: 4}, {name: "gfm", highlightFormatting: true});
  5. function FT(name) { test.mode(name, modeHighlightFormatting, Array.prototype.slice.call(arguments, 1)); }
  6. FT("codeBackticks",
  7. "[comment&formatting&formatting-code `][comment foo][comment&formatting&formatting-code `]");
  8. FT("doubleBackticks",
  9. "[comment&formatting&formatting-code ``][comment foo ` bar][comment&formatting&formatting-code ``]");
  10. FT("codeBlock",
  11. "[comment&formatting&formatting-code-block ```css]",
  12. "[tag foo]",
  13. "[comment&formatting&formatting-code-block ```]");
  14. FT("taskList",
  15. "[variable-2&formatting&formatting-list&formatting-list-ul - ][meta&formatting&formatting-task [ ]]][variable-2 foo]",
  16. "[variable-2&formatting&formatting-list&formatting-list-ul - ][property&formatting&formatting-task [x]]][variable-2 foo]");
  17. MT("emInWordAsterisk",
  18. "foo[em *bar*]hello");
  19. MT("emInWordUnderscore",
  20. "foo_bar_hello");
  21. MT("emStrongUnderscore",
  22. "[strong __][em&strong _foo__][em _] bar");
  23. MT("fencedCodeBlocks",
  24. "[comment ```]",
  25. "[comment foo]",
  26. "",
  27. "[comment ```]",
  28. "bar");
  29. MT("fencedCodeBlockModeSwitching",
  30. "[comment ```javascript]",
  31. "[variable foo]",
  32. "",
  33. "[comment ```]",
  34. "bar");
  35. MT("taskListAsterisk",
  36. "[variable-2 * []] foo]", // Invalid; must have space or x between []
  37. "[variable-2 * [ ]]bar]", // Invalid; must have space after ]
  38. "[variable-2 * [x]]hello]", // Invalid; must have space after ]
  39. "[variable-2 * ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links
  40. " [variable-3 * ][property [x]]][variable-3 foo]"); // Valid; can be nested
  41. MT("taskListPlus",
  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("taskListDash",
  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("taskListNumber",
  54. "[variable-2 1. []] foo]", // Invalid; must have space or x between []
  55. "[variable-2 2. [ ]]bar]", // Invalid; must have space after ]
  56. "[variable-2 3. [x]]hello]", // Invalid; must have space after ]
  57. "[variable-2 4. ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links
  58. " [variable-3 1. ][property [x]]][variable-3 foo]"); // Valid; can be nested
  59. MT("SHA",
  60. "foo [link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] bar");
  61. MT("shortSHA",
  62. "foo [link be6a8cc] bar");
  63. MT("tooShortSHA",
  64. "foo be6a8c bar");
  65. MT("longSHA",
  66. "foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd22 bar");
  67. MT("badSHA",
  68. "foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cg2 bar");
  69. MT("userSHA",
  70. "foo [link bar@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] hello");
  71. MT("userProjectSHA",
  72. "foo [link bar/hello@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] world");
  73. MT("num",
  74. "foo [link #1] bar");
  75. MT("badNum",
  76. "foo #1bar hello");
  77. MT("userNum",
  78. "foo [link bar#1] hello");
  79. MT("userProjectNum",
  80. "foo [link bar/hello#1] world");
  81. MT("vanillaLink",
  82. "foo [link http://www.example.com/] bar");
  83. MT("vanillaLinkPunctuation",
  84. "foo [link http://www.example.com/]. bar");
  85. MT("vanillaLinkExtension",
  86. "foo [link http://www.example.com/index.html] bar");
  87. MT("notALink",
  88. "[comment ```css]",
  89. "[tag foo] {[property color]:[keyword black];}",
  90. "[comment ```][link http://www.example.com/]");
  91. MT("notALink",
  92. "[comment ``foo `bar` http://www.example.com/``] hello");
  93. MT("notALink",
  94. "[comment `foo]",
  95. "[link http://www.example.com/]",
  96. "[comment `foo]",
  97. "",
  98. "[link http://www.example.com/]");
  99. })();