browser/devtools/sourceeditor/test/cm_comment_test.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 namespace = "comment_";
michael@0 2
michael@0 3 (function() {
michael@0 4 function test(name, mode, run, before, after) {
michael@0 5 return testCM(name, function(cm) {
michael@0 6 run(cm);
michael@0 7 eq(cm.getValue(), after);
michael@0 8 }, {value: before, mode: mode});
michael@0 9 }
michael@0 10
michael@0 11 var simpleProg = "function foo() {\n return bar;\n}";
michael@0 12
michael@0 13 test("block", "javascript", function(cm) {
michael@0 14 cm.blockComment(Pos(0, 3), Pos(3, 0), {blockCommentLead: " *"});
michael@0 15 }, simpleProg + "\n", "/* function foo() {\n * return bar;\n * }\n */");
michael@0 16
michael@0 17 test("blockToggle", "javascript", function(cm) {
michael@0 18 cm.blockComment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"});
michael@0 19 cm.uncomment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"});
michael@0 20 }, simpleProg, simpleProg);
michael@0 21
michael@0 22 test("line", "javascript", function(cm) {
michael@0 23 cm.lineComment(Pos(1, 1), Pos(1, 1));
michael@0 24 }, simpleProg, "function foo() {\n// return bar;\n}");
michael@0 25
michael@0 26 test("lineToggle", "javascript", function(cm) {
michael@0 27 cm.lineComment(Pos(0, 0), Pos(2, 1));
michael@0 28 cm.uncomment(Pos(0, 0), Pos(2, 1));
michael@0 29 }, simpleProg, simpleProg);
michael@0 30
michael@0 31 // test("fallbackToBlock", "css", function(cm) {
michael@0 32 // cm.lineComment(Pos(0, 0), Pos(2, 1));
michael@0 33 // }, "html {\n border: none;\n}", "/* html {\n border: none;\n} */");
michael@0 34
michael@0 35 // test("fallbackToLine", "ruby", function(cm) {
michael@0 36 // cm.blockComment(Pos(0, 0), Pos(1));
michael@0 37 // }, "def blah()\n return hah\n", "# def blah()\n# return hah\n");
michael@0 38
michael@0 39 test("commentRange", "javascript", function(cm) {
michael@0 40 cm.blockComment(Pos(1, 2), Pos(1, 13), {fullLines: false});
michael@0 41 }, simpleProg, "function foo() {\n /*return bar;*/\n}");
michael@0 42
michael@0 43 test("indented", "javascript", function(cm) {
michael@0 44 cm.lineComment(Pos(1, 0), Pos(2), {indent: true});
michael@0 45 }, simpleProg, "function foo() {\n // return bar;\n // }");
michael@0 46
michael@0 47 test("singleEmptyLine", "javascript", function(cm) {
michael@0 48 cm.setCursor(1);
michael@0 49 cm.execCommand("toggleComment");
michael@0 50 }, "a;\n\nb;", "a;\n// \nb;");
michael@0 51
michael@0 52 test("dontMessWithStrings", "javascript", function(cm) {
michael@0 53 cm.execCommand("toggleComment");
michael@0 54 }, "console.log(\"/*string*/\");", "// console.log(\"/*string*/\");");
michael@0 55
michael@0 56 test("dontMessWithStrings2", "javascript", function(cm) {
michael@0 57 cm.execCommand("toggleComment");
michael@0 58 }, "console.log(\"// string\");", "// console.log(\"// string\");");
michael@0 59
michael@0 60 test("dontMessWithStrings3", "javascript", function(cm) {
michael@0 61 cm.execCommand("toggleComment");
michael@0 62 }, "// console.log(\"// string\");", "console.log(\"// string\");");
michael@0 63 })();

mercurial