1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/sourceeditor/test/cm_comment_test.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +namespace = "comment_"; 1.5 + 1.6 +(function() { 1.7 + function test(name, mode, run, before, after) { 1.8 + return testCM(name, function(cm) { 1.9 + run(cm); 1.10 + eq(cm.getValue(), after); 1.11 + }, {value: before, mode: mode}); 1.12 + } 1.13 + 1.14 + var simpleProg = "function foo() {\n return bar;\n}"; 1.15 + 1.16 + test("block", "javascript", function(cm) { 1.17 + cm.blockComment(Pos(0, 3), Pos(3, 0), {blockCommentLead: " *"}); 1.18 + }, simpleProg + "\n", "/* function foo() {\n * return bar;\n * }\n */"); 1.19 + 1.20 + test("blockToggle", "javascript", function(cm) { 1.21 + cm.blockComment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"}); 1.22 + cm.uncomment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"}); 1.23 + }, simpleProg, simpleProg); 1.24 + 1.25 + test("line", "javascript", function(cm) { 1.26 + cm.lineComment(Pos(1, 1), Pos(1, 1)); 1.27 + }, simpleProg, "function foo() {\n// return bar;\n}"); 1.28 + 1.29 + test("lineToggle", "javascript", function(cm) { 1.30 + cm.lineComment(Pos(0, 0), Pos(2, 1)); 1.31 + cm.uncomment(Pos(0, 0), Pos(2, 1)); 1.32 + }, simpleProg, simpleProg); 1.33 + 1.34 + // test("fallbackToBlock", "css", function(cm) { 1.35 + // cm.lineComment(Pos(0, 0), Pos(2, 1)); 1.36 + // }, "html {\n border: none;\n}", "/* html {\n border: none;\n} */"); 1.37 + 1.38 + // test("fallbackToLine", "ruby", function(cm) { 1.39 + // cm.blockComment(Pos(0, 0), Pos(1)); 1.40 + // }, "def blah()\n return hah\n", "# def blah()\n# return hah\n"); 1.41 + 1.42 + test("commentRange", "javascript", function(cm) { 1.43 + cm.blockComment(Pos(1, 2), Pos(1, 13), {fullLines: false}); 1.44 + }, simpleProg, "function foo() {\n /*return bar;*/\n}"); 1.45 + 1.46 + test("indented", "javascript", function(cm) { 1.47 + cm.lineComment(Pos(1, 0), Pos(2), {indent: true}); 1.48 + }, simpleProg, "function foo() {\n // return bar;\n // }"); 1.49 + 1.50 + test("singleEmptyLine", "javascript", function(cm) { 1.51 + cm.setCursor(1); 1.52 + cm.execCommand("toggleComment"); 1.53 + }, "a;\n\nb;", "a;\n// \nb;"); 1.54 + 1.55 + test("dontMessWithStrings", "javascript", function(cm) { 1.56 + cm.execCommand("toggleComment"); 1.57 + }, "console.log(\"/*string*/\");", "// console.log(\"/*string*/\");"); 1.58 + 1.59 + test("dontMessWithStrings2", "javascript", function(cm) { 1.60 + cm.execCommand("toggleComment"); 1.61 + }, "console.log(\"// string\");", "// console.log(\"// string\");"); 1.62 + 1.63 + test("dontMessWithStrings3", "javascript", function(cm) { 1.64 + cm.execCommand("toggleComment"); 1.65 + }, "// console.log(\"// string\");", "console.log(\"// string\");"); 1.66 +})();