Mercurial
comparison .cms/lib/codemirror/test/annotatescrollbar.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 = "annotatescrollbar_"; | |
2 | |
3 (function () { | |
4 function test(name, run, content, query, expected) { | |
5 return testCM(name, function (cm) { | |
6 var annotation = cm.annotateScrollbar({ | |
7 listenForChanges: false, | |
8 className: "CodeMirror-search-match" | |
9 }); | |
10 var matches = []; | |
11 var cursor = cm.getSearchCursor(query, CodeMirror.Pos(0, 0)); | |
12 while (cursor.findNext()) { | |
13 var match = { | |
14 from: cursor.from(), | |
15 to: cursor.to() | |
16 }; | |
17 matches.push(match) | |
18 } | |
19 | |
20 if (run) run(cm); | |
21 | |
22 cm.display.barWidth = 5; | |
23 annotation.update(matches); | |
24 | |
25 var annotations = cm.getWrapperElement().getElementsByClassName(annotation.options.className); | |
26 eq(annotations.length, expected, "Expected " + expected + " annotations on the scrollbar.") | |
27 }, { | |
28 value: content, | |
29 mode: "javascript", | |
30 foldOptions: { | |
31 rangeFinder: CodeMirror.fold.brace | |
32 } | |
33 }); | |
34 } | |
35 | |
36 function doFold(cm) { | |
37 cm.foldCode(cm.getCursor()); | |
38 } | |
39 var simpleProg = "function foo() {\n\n return \"foo\";\n\n}\n\nfoo();\n"; | |
40 var consecutiveLineMatches = "function foo() {\n return \"foo\";\n}\nfoo();\n"; | |
41 var singleLineMatches = "function foo() { return \"foo\"; }foo();\n"; | |
42 | |
43 // Base case - expect 3 matches and 3 annotations | |
44 test("simple", null, simpleProg, "foo", 3); | |
45 // Consecutive line matches are combines into a single annotation - expect 3 matches and 2 annotations | |
46 test("combineConsecutiveLine", null, consecutiveLineMatches, "foo", 2); | |
47 // Matches on a single line get a single annotation - expect 3 matches and 1 annotation | |
48 test("combineSingleLine", null, singleLineMatches, "foo", 1); | |
49 // Matches within a fold are annotated on the folded line - expect 3 matches and 2 annotations | |
50 test("simpleFold", doFold, simpleProg, "foo", 2); | |
51 // Combination of combineConsecutiveLine and simpleFold cases - expect 3 matches and 1 annotation | |
52 test("foldedMatch", doFold, consecutiveLineMatches, "foo", 1); | |
53 // Hidden matches within a fold are annotated on the folded line - expect 1 match and 1 annotation | |
54 test("hiddenMatch", doFold, simpleProg, "return", 1); | |
55 })(); |