comment_test.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. namespace = "comment_";
  2. (function() {
  3. function test(name, mode, run, before, after) {
  4. return testCM(name, function(cm) {
  5. run(cm);
  6. eq(cm.getValue(), after);
  7. }, {value: before, mode: mode});
  8. }
  9. var simpleProg = "function foo() {\n return bar;\n}";
  10. test("block", "javascript", function(cm) {
  11. cm.blockComment(Pos(0, 3), Pos(3, 0), {blockCommentLead: " *"});
  12. }, simpleProg + "\n", "/* function foo() {\n * return bar;\n * }\n */");
  13. test("blockToggle", "javascript", function(cm) {
  14. cm.blockComment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"});
  15. cm.uncomment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"});
  16. }, simpleProg, simpleProg);
  17. test("line", "javascript", function(cm) {
  18. cm.lineComment(Pos(1, 1), Pos(1, 1));
  19. }, simpleProg, "function foo() {\n// return bar;\n}");
  20. test("lineToggle", "javascript", function(cm) {
  21. cm.lineComment(Pos(0, 0), Pos(2, 1));
  22. cm.uncomment(Pos(0, 0), Pos(2, 1));
  23. }, simpleProg, simpleProg);
  24. test("fallbackToBlock", "css", function(cm) {
  25. cm.lineComment(Pos(0, 0), Pos(2, 1));
  26. }, "html {\n border: none;\n}", "/* html {\n border: none;\n} */");
  27. test("fallbackToLine", "ruby", function(cm) {
  28. cm.blockComment(Pos(0, 0), Pos(1));
  29. }, "def blah()\n return hah\n", "# def blah()\n# return hah\n");
  30. test("commentRange", "javascript", function(cm) {
  31. cm.blockComment(Pos(1, 2), Pos(1, 13), {fullLines: false});
  32. }, simpleProg, "function foo() {\n /*return bar;*/\n}");
  33. test("indented", "javascript", function(cm) {
  34. cm.lineComment(Pos(1, 0), Pos(2), {indent: true});
  35. }, simpleProg, "function foo() {\n // return bar;\n // }");
  36. })();