Mercurial
comparison .cms/lib/codemirror/test/comment_test.js @ 0:78edf6b517a0 draft
24.10
author | Coffee CMS <info@coffee-cms.ru> |
---|---|
date | Fri, 11 Oct 2024 22:40:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78edf6b517a0 |
---|---|
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 var inlineBlock = "foo(/* bar */ true);"; | |
13 var inlineBlocks = "foo(/* bar */ true, /* baz */ false);"; | |
14 var multiLineInlineBlock = ["above();", "foo(/* bar */ true);", "below();"]; | |
15 | |
16 test("block", "javascript", function(cm) { | |
17 cm.blockComment(Pos(0, 3), Pos(3, 0), {blockCommentLead: " *"}); | |
18 }, simpleProg + "\n", "/* function foo() {\n * return bar;\n * }\n */"); | |
19 | |
20 test("blockToggle", "javascript", function(cm) { | |
21 cm.blockComment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"}); | |
22 cm.uncomment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"}); | |
23 }, simpleProg, simpleProg); | |
24 | |
25 test("blockToggle2", "javascript", function(cm) { | |
26 cm.setCursor({line: 0, ch: 7 /* inside the block comment */}); | |
27 cm.execCommand("toggleComment"); | |
28 }, inlineBlock, "foo(bar true);"); | |
29 | |
30 // This test should work but currently fails. | |
31 // test("blockToggle3", "javascript", function(cm) { | |
32 // cm.setCursor({line: 0, ch: 7 /* inside the first block comment */}); | |
33 // cm.execCommand("toggleComment"); | |
34 // }, inlineBlocks, "foo(bar true, /* baz */ false);"); | |
35 | |
36 test("line", "javascript", function(cm) { | |
37 cm.lineComment(Pos(1, 1), Pos(1, 1)); | |
38 }, simpleProg, "function foo() {\n// return bar;\n}"); | |
39 | |
40 test("lineToggle", "javascript", function(cm) { | |
41 cm.lineComment(Pos(0, 0), Pos(2, 1)); | |
42 cm.uncomment(Pos(0, 0), Pos(2, 1)); | |
43 }, simpleProg, simpleProg); | |
44 | |
45 test("fallbackToBlock", "css", function(cm) { | |
46 cm.lineComment(Pos(0, 0), Pos(2, 1)); | |
47 }, "html {\n border: none;\n}", "/* html {\n border: none;\n} */"); | |
48 | |
49 test("fallbackToLine", "ruby", function(cm) { | |
50 cm.blockComment(Pos(0, 0), Pos(1)); | |
51 }, "def blah()\n return hah\n", "# def blah()\n# return hah\n"); | |
52 | |
53 test("ignoreExternalBlockComments", "javascript", function(cm) { | |
54 cm.execCommand("toggleComment"); | |
55 }, inlineBlocks, "// " + inlineBlocks); | |
56 | |
57 test("ignoreExternalBlockComments2", "javascript", function(cm) { | |
58 cm.setCursor({line: 0, ch: null /* eol */}); | |
59 cm.execCommand("toggleComment"); | |
60 }, inlineBlocks, "// " + inlineBlocks); | |
61 | |
62 test("ignoreExternalBlockCommentsMultiLineAbove", "javascript", function(cm) { | |
63 cm.setSelection({line: 0, ch: 0}, {line: 1, ch: 1}); | |
64 cm.execCommand("toggleComment"); | |
65 }, multiLineInlineBlock.join("\n"), ["// " + multiLineInlineBlock[0], | |
66 "// " + multiLineInlineBlock[1], | |
67 multiLineInlineBlock[2]].join("\n")); | |
68 | |
69 test("ignoreExternalBlockCommentsMultiLineBelow", "javascript", function(cm) { | |
70 cm.setSelection({line: 1, ch: 13 /* after end of block comment */}, {line: 2, ch: 1}); | |
71 cm.execCommand("toggleComment"); | |
72 }, multiLineInlineBlock.join("\n"), [multiLineInlineBlock[0], | |
73 "// " + multiLineInlineBlock[1], | |
74 "// " + multiLineInlineBlock[2]].join("\n")); | |
75 | |
76 test("commentRange", "javascript", function(cm) { | |
77 cm.blockComment(Pos(1, 2), Pos(1, 13), {fullLines: false}); | |
78 }, simpleProg, "function foo() {\n /*return bar;*/\n}"); | |
79 | |
80 test("indented", "javascript", function(cm) { | |
81 cm.lineComment(Pos(1, 0), Pos(2), {indent: true}); | |
82 }, simpleProg, "function foo() {\n// return bar;\n// }"); | |
83 | |
84 test("emptyIndentedLine", "javascript", function(cm) { | |
85 cm.lineComment(Pos(1, 2), Pos(1, 2), {indent: true}); | |
86 }, "function foo() {\n \n}", "function foo() {\n // \n}"); | |
87 | |
88 test("singleEmptyLine", "javascript", function(cm) { | |
89 cm.setCursor(1); | |
90 cm.execCommand("toggleComment"); | |
91 }, "a;\n\nb;", "a;\n// \nb;"); | |
92 | |
93 test("dontMessWithStrings", "javascript", function(cm) { | |
94 cm.execCommand("toggleComment"); | |
95 }, "console.log(\"/*string*/\");", "// console.log(\"/*string*/\");"); | |
96 | |
97 test("dontMessWithStrings2", "javascript", function(cm) { | |
98 cm.execCommand("toggleComment"); | |
99 }, "console.log(\"// string\");", "// console.log(\"// string\");"); | |
100 | |
101 test("dontMessWithStrings3", "javascript", function(cm) { | |
102 cm.execCommand("toggleComment"); | |
103 }, "// console.log(\"// string\");", "console.log(\"// string\");"); | |
104 | |
105 test("includeLastLine", "javascript", function(cm) { | |
106 cm.execCommand("selectAll") | |
107 cm.execCommand("toggleComment") | |
108 }, "// foo\n// bar\nbaz", "// // foo\n// // bar\n// baz") | |
109 | |
110 test("uncommentWithTrailingBlockEnd", "xml", function(cm) { | |
111 cm.execCommand("toggleComment") | |
112 }, "<!-- foo --> -->", "foo -->") | |
113 | |
114 test("dontCommentInComment", "xml", function(cm) { | |
115 cm.setCursor(1, 0) | |
116 cm.execCommand("toggleComment") | |
117 }, "<!-- foo\nbar -->", "<!-- foo\nbar -->") | |
118 | |
119 test("toggleWithMultipleInnerComments", "javascript", function(cm) { | |
120 cm.execCommand("selectAll") | |
121 cm.execCommand("toggleComment") | |
122 }, "/* foo */\na\n/* bar */\nb", "// /* foo */\n// a\n// /* bar */\n// b") | |
123 | |
124 var before = 'console.log("//string gets corrupted.");'; | |
125 var after = '// console.log("//string gets corrupted.");'; | |
126 test("toggleWithStringContainingComment1", "javascript", function(cm) { | |
127 cm.setCursor({line: 0, ch: 16 /* after // inside string */}); | |
128 cm.execCommand("toggleComment"); | |
129 }, before, after) | |
130 test("toggleWithStringContainingComment2", "javascript", function(cm) { | |
131 cm.setCursor({line: 0, ch: 16 /* after // inside string */}); | |
132 cm.execCommand("toggleComment"); | |
133 cm.execCommand("toggleComment"); | |
134 }, before, before) | |
135 })(); |