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