michael@0: namespace = "comment_"; michael@0: michael@0: (function() { michael@0: function test(name, mode, run, before, after) { michael@0: return testCM(name, function(cm) { michael@0: run(cm); michael@0: eq(cm.getValue(), after); michael@0: }, {value: before, mode: mode}); michael@0: } michael@0: michael@0: var simpleProg = "function foo() {\n return bar;\n}"; michael@0: michael@0: test("block", "javascript", function(cm) { michael@0: cm.blockComment(Pos(0, 3), Pos(3, 0), {blockCommentLead: " *"}); michael@0: }, simpleProg + "\n", "/* function foo() {\n * return bar;\n * }\n */"); michael@0: michael@0: test("blockToggle", "javascript", function(cm) { michael@0: cm.blockComment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"}); michael@0: cm.uncomment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"}); michael@0: }, simpleProg, simpleProg); michael@0: michael@0: test("line", "javascript", function(cm) { michael@0: cm.lineComment(Pos(1, 1), Pos(1, 1)); michael@0: }, simpleProg, "function foo() {\n// return bar;\n}"); michael@0: michael@0: test("lineToggle", "javascript", function(cm) { michael@0: cm.lineComment(Pos(0, 0), Pos(2, 1)); michael@0: cm.uncomment(Pos(0, 0), Pos(2, 1)); michael@0: }, simpleProg, simpleProg); michael@0: michael@0: // test("fallbackToBlock", "css", function(cm) { michael@0: // cm.lineComment(Pos(0, 0), Pos(2, 1)); michael@0: // }, "html {\n border: none;\n}", "/* html {\n border: none;\n} */"); michael@0: michael@0: // test("fallbackToLine", "ruby", function(cm) { michael@0: // cm.blockComment(Pos(0, 0), Pos(1)); michael@0: // }, "def blah()\n return hah\n", "# def blah()\n# return hah\n"); michael@0: michael@0: test("commentRange", "javascript", function(cm) { michael@0: cm.blockComment(Pos(1, 2), Pos(1, 13), {fullLines: false}); michael@0: }, simpleProg, "function foo() {\n /*return bar;*/\n}"); michael@0: michael@0: test("indented", "javascript", function(cm) { michael@0: cm.lineComment(Pos(1, 0), Pos(2), {indent: true}); michael@0: }, simpleProg, "function foo() {\n // return bar;\n // }"); michael@0: michael@0: test("singleEmptyLine", "javascript", function(cm) { michael@0: cm.setCursor(1); michael@0: cm.execCommand("toggleComment"); michael@0: }, "a;\n\nb;", "a;\n// \nb;"); michael@0: michael@0: test("dontMessWithStrings", "javascript", function(cm) { michael@0: cm.execCommand("toggleComment"); michael@0: }, "console.log(\"/*string*/\");", "// console.log(\"/*string*/\");"); michael@0: michael@0: test("dontMessWithStrings2", "javascript", function(cm) { michael@0: cm.execCommand("toggleComment"); michael@0: }, "console.log(\"// string\");", "// console.log(\"// string\");"); michael@0: michael@0: test("dontMessWithStrings3", "javascript", function(cm) { michael@0: cm.execCommand("toggleComment"); michael@0: }, "// console.log(\"// string\");", "console.log(\"// string\");"); michael@0: })();