Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | (function() { |
michael@0 | 2 | "use strict"; |
michael@0 | 3 | |
michael@0 | 4 | var Pos = CodeMirror.Pos; |
michael@0 | 5 | namespace = "sublime_"; |
michael@0 | 6 | |
michael@0 | 7 | function stTest(name) { |
michael@0 | 8 | var actions = Array.prototype.slice.call(arguments, 1); |
michael@0 | 9 | testCM(name, function(cm) { |
michael@0 | 10 | for (var i = 0; i < actions.length; i++) { |
michael@0 | 11 | var action = actions[i]; |
michael@0 | 12 | if (typeof action == "string" && i == 0) |
michael@0 | 13 | cm.setValue(action); |
michael@0 | 14 | else if (typeof action == "string") |
michael@0 | 15 | cm.execCommand(action); |
michael@0 | 16 | else if (action instanceof Pos) |
michael@0 | 17 | cm.setCursor(action); |
michael@0 | 18 | else |
michael@0 | 19 | action(cm); |
michael@0 | 20 | } |
michael@0 | 21 | }); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function at(line, ch, msg) { |
michael@0 | 25 | return function(cm) { |
michael@0 | 26 | eq(cm.listSelections().length, 1); |
michael@0 | 27 | eqPos(cm.getCursor("head"), Pos(line, ch), msg); |
michael@0 | 28 | eqPos(cm.getCursor("anchor"), Pos(line, ch), msg); |
michael@0 | 29 | }; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function val(content, msg) { |
michael@0 | 33 | return function(cm) { eq(cm.getValue(), content, msg); }; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function argsToRanges(args) { |
michael@0 | 37 | if (args.length % 4) throw new Error("Wrong number of arguments for ranges."); |
michael@0 | 38 | var ranges = []; |
michael@0 | 39 | for (var i = 0; i < args.length; i += 4) |
michael@0 | 40 | ranges.push({anchor: Pos(args[i], args[i + 1]), |
michael@0 | 41 | head: Pos(args[i + 2], args[i + 3])}); |
michael@0 | 42 | return ranges; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function setSel() { |
michael@0 | 46 | var ranges = argsToRanges(arguments); |
michael@0 | 47 | return function(cm) { cm.setSelections(ranges, 0); }; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function hasSel() { |
michael@0 | 51 | var ranges = argsToRanges(arguments); |
michael@0 | 52 | return function(cm) { |
michael@0 | 53 | var sels = cm.listSelections(); |
michael@0 | 54 | if (sels.length != ranges.length) |
michael@0 | 55 | throw new Failure("Expected " + ranges.length + " selections, but found " + sels.length); |
michael@0 | 56 | for (var i = 0; i < sels.length; i++) { |
michael@0 | 57 | eqPos(sels[i].anchor, ranges[i].anchor, "anchor " + i); |
michael@0 | 58 | eqPos(sels[i].head, ranges[i].head, "head " + i); |
michael@0 | 59 | } |
michael@0 | 60 | }; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | stTest("bySubword", "the foo_bar DooDahBah \n a", |
michael@0 | 64 | "goSubwordLeft", at(0, 0), |
michael@0 | 65 | "goSubwordRight", at(0, 3), |
michael@0 | 66 | "goSubwordRight", at(0, 7), |
michael@0 | 67 | "goSubwordRight", at(0, 11), |
michael@0 | 68 | "goSubwordRight", at(0, 15), |
michael@0 | 69 | "goSubwordRight", at(0, 18), |
michael@0 | 70 | "goSubwordRight", at(0, 21), |
michael@0 | 71 | "goSubwordRight", at(0, 22), |
michael@0 | 72 | "goSubwordRight", at(1, 0), |
michael@0 | 73 | "goSubwordRight", at(1, 2), |
michael@0 | 74 | "goSubwordRight", at(1, 2), |
michael@0 | 75 | "goSubwordLeft", at(1, 1), |
michael@0 | 76 | "goSubwordLeft", at(1, 0), |
michael@0 | 77 | "goSubwordLeft", at(0, 22), |
michael@0 | 78 | "goSubwordLeft", at(0, 18), |
michael@0 | 79 | "goSubwordLeft", at(0, 15), |
michael@0 | 80 | "goSubwordLeft", at(0, 12), |
michael@0 | 81 | "goSubwordLeft", at(0, 8), |
michael@0 | 82 | "goSubwordLeft", at(0, 4), |
michael@0 | 83 | "goSubwordLeft", at(0, 0)); |
michael@0 | 84 | |
michael@0 | 85 | stTest("splitSelectionByLine", "abc\ndef\nghi", |
michael@0 | 86 | setSel(0, 1, 2, 2), |
michael@0 | 87 | "splitSelectionByLine", |
michael@0 | 88 | hasSel(0, 1, 0, 3, |
michael@0 | 89 | 1, 0, 1, 3, |
michael@0 | 90 | 2, 0, 2, 2)); |
michael@0 | 91 | |
michael@0 | 92 | stTest("splitSelectionByLineMulti", "abc\ndef\nghi\njkl", |
michael@0 | 93 | setSel(0, 1, 1, 1, |
michael@0 | 94 | 1, 2, 3, 2, |
michael@0 | 95 | 3, 3, 3, 3), |
michael@0 | 96 | "splitSelectionByLine", |
michael@0 | 97 | hasSel(0, 1, 0, 3, |
michael@0 | 98 | 1, 0, 1, 1, |
michael@0 | 99 | 1, 2, 1, 3, |
michael@0 | 100 | 2, 0, 2, 3, |
michael@0 | 101 | 3, 0, 3, 2, |
michael@0 | 102 | 3, 3, 3, 3)); |
michael@0 | 103 | |
michael@0 | 104 | stTest("selectLine", "abc\ndef\nghi", |
michael@0 | 105 | setSel(0, 1, 0, 1, |
michael@0 | 106 | 2, 0, 2, 1), |
michael@0 | 107 | "selectLine", |
michael@0 | 108 | hasSel(0, 0, 1, 0, |
michael@0 | 109 | 2, 0, 2, 3), |
michael@0 | 110 | setSel(0, 1, 1, 0), |
michael@0 | 111 | "selectLine", |
michael@0 | 112 | hasSel(0, 0, 2, 0)); |
michael@0 | 113 | |
michael@0 | 114 | stTest("insertLineAfter", "abcde\nfghijkl\nmn", |
michael@0 | 115 | setSel(0, 1, 0, 1, |
michael@0 | 116 | 0, 3, 0, 3, |
michael@0 | 117 | 1, 2, 1, 2, |
michael@0 | 118 | 1, 3, 1, 5), "insertLineAfter", |
michael@0 | 119 | hasSel(1, 0, 1, 0, |
michael@0 | 120 | 3, 0, 3, 0), val("abcde\n\nfghijkl\n\nmn")); |
michael@0 | 121 | |
michael@0 | 122 | stTest("insertLineBefore", "abcde\nfghijkl\nmn", |
michael@0 | 123 | setSel(0, 1, 0, 1, |
michael@0 | 124 | 0, 3, 0, 3, |
michael@0 | 125 | 1, 2, 1, 2, |
michael@0 | 126 | 1, 3, 1, 5), "insertLineBefore", |
michael@0 | 127 | hasSel(0, 0, 0, 0, |
michael@0 | 128 | 2, 0, 2, 0), val("\nabcde\n\nfghijkl\nmn")); |
michael@0 | 129 | |
michael@0 | 130 | stTest("selectNextOccurrence", "a foo bar\nfoobar foo", |
michael@0 | 131 | setSel(0, 2, 0, 5), |
michael@0 | 132 | "selectNextOccurrence", hasSel(0, 2, 0, 5, |
michael@0 | 133 | 1, 0, 1, 3), |
michael@0 | 134 | "selectNextOccurrence", hasSel(0, 2, 0, 5, |
michael@0 | 135 | 1, 0, 1, 3, |
michael@0 | 136 | 1, 7, 1, 10), |
michael@0 | 137 | "selectNextOccurrence", hasSel(0, 2, 0, 5, |
michael@0 | 138 | 1, 0, 1, 3, |
michael@0 | 139 | 1, 7, 1, 10), |
michael@0 | 140 | Pos(0, 3), "selectNextOccurrence", hasSel(0, 2, 0, 5), |
michael@0 | 141 | "selectNextOccurrence", hasSel(0, 2, 0, 5, |
michael@0 | 142 | 1, 7, 1, 10), |
michael@0 | 143 | setSel(0, 6, 0, 9), |
michael@0 | 144 | "selectNextOccurrence", hasSel(0, 6, 0, 9, |
michael@0 | 145 | 1, 3, 1, 6)); |
michael@0 | 146 | |
michael@0 | 147 | stTest("selectScope", "foo(a) {\n bar[1, 2];\n}", |
michael@0 | 148 | "selectScope", hasSel(0, 0, 2, 1), |
michael@0 | 149 | Pos(0, 4), "selectScope", hasSel(0, 4, 0, 5), |
michael@0 | 150 | Pos(0, 5), "selectScope", hasSel(0, 4, 0, 5), |
michael@0 | 151 | Pos(0, 6), "selectScope", hasSel(0, 0, 2, 1), |
michael@0 | 152 | Pos(0, 8), "selectScope", hasSel(0, 8, 2, 0), |
michael@0 | 153 | Pos(1, 2), "selectScope", hasSel(0, 8, 2, 0), |
michael@0 | 154 | Pos(1, 6), "selectScope", hasSel(1, 6, 1, 10), |
michael@0 | 155 | Pos(1, 9), "selectScope", hasSel(1, 6, 1, 10)); |
michael@0 | 156 | |
michael@0 | 157 | stTest("goToBracket", "foo(a) {\n bar[1, 2];\n}", |
michael@0 | 158 | Pos(0, 0), "goToBracket", at(0, 0), |
michael@0 | 159 | Pos(0, 4), "goToBracket", at(0, 5), "goToBracket", at(0, 4), |
michael@0 | 160 | Pos(0, 8), "goToBracket", at(2, 0), "goToBracket", at(0, 8), |
michael@0 | 161 | Pos(1, 2), "goToBracket", at(2, 0), |
michael@0 | 162 | Pos(1, 7), "goToBracket", at(1, 10), "goToBracket", at(1, 6)); |
michael@0 | 163 | |
michael@0 | 164 | stTest("swapLine", "1\n2\n3---\n4\n5", |
michael@0 | 165 | "swapLineDown", val("2\n1\n3---\n4\n5"), |
michael@0 | 166 | "swapLineUp", val("1\n2\n3---\n4\n5"), |
michael@0 | 167 | "swapLineUp", val("1\n2\n3---\n4\n5"), |
michael@0 | 168 | Pos(4, 1), "swapLineDown", val("1\n2\n3---\n4\n5"), |
michael@0 | 169 | setSel(0, 1, 0, 1, |
michael@0 | 170 | 1, 0, 2, 0, |
michael@0 | 171 | 2, 2, 2, 2), |
michael@0 | 172 | "swapLineDown", val("4\n1\n2\n3---\n5"), |
michael@0 | 173 | hasSel(1, 1, 1, 1, |
michael@0 | 174 | 2, 0, 3, 0, |
michael@0 | 175 | 3, 2, 3, 2), |
michael@0 | 176 | "swapLineUp", val("1\n2\n3---\n4\n5"), |
michael@0 | 177 | hasSel(0, 1, 0, 1, |
michael@0 | 178 | 1, 0, 2, 0, |
michael@0 | 179 | 2, 2, 2, 2)); |
michael@0 | 180 | |
michael@0 | 181 | stTest("swapLineUpFromEnd", "a\nb\nc", |
michael@0 | 182 | Pos(2, 1), "swapLineUp", |
michael@0 | 183 | hasSel(1, 1, 1, 1), val("a\nc\nb")); |
michael@0 | 184 | |
michael@0 | 185 | stTest("joinLines", "abc\ndef\nghi\njkl", |
michael@0 | 186 | "joinLines", val("abc def\nghi\njkl"), at(0, 4), |
michael@0 | 187 | "undo", |
michael@0 | 188 | setSel(0, 2, 1, 1), "joinLines", |
michael@0 | 189 | val("abc def ghi\njkl"), hasSel(0, 2, 0, 8), |
michael@0 | 190 | "undo", |
michael@0 | 191 | setSel(0, 1, 0, 1, |
michael@0 | 192 | 1, 1, 1, 1, |
michael@0 | 193 | 3, 1, 3, 1), "joinLines", |
michael@0 | 194 | val("abc def ghi\njkl"), hasSel(0, 4, 0, 4, |
michael@0 | 195 | 0, 8, 0, 8, |
michael@0 | 196 | 1, 3, 1, 3)); |
michael@0 | 197 | |
michael@0 | 198 | stTest("duplicateLine", "abc\ndef\nghi", |
michael@0 | 199 | Pos(1, 0), "duplicateLine", val("abc\ndef\ndef\nghi"), at(2, 0), |
michael@0 | 200 | "undo", |
michael@0 | 201 | setSel(0, 1, 0, 1, |
michael@0 | 202 | 1, 1, 1, 1, |
michael@0 | 203 | 2, 1, 2, 1), "duplicateLine", |
michael@0 | 204 | val("abc\nabc\ndef\ndef\nghi\nghi"), hasSel(1, 1, 1, 1, |
michael@0 | 205 | 3, 1, 3, 1, |
michael@0 | 206 | 5, 1, 5, 1)); |
michael@0 | 207 | stTest("duplicateLineSelection", "abcdef", |
michael@0 | 208 | setSel(0, 1, 0, 1, |
michael@0 | 209 | 0, 2, 0, 4, |
michael@0 | 210 | 0, 5, 0, 5), |
michael@0 | 211 | "duplicateLine", |
michael@0 | 212 | val("abcdef\nabcdcdef\nabcdcdef"), hasSel(2, 1, 2, 1, |
michael@0 | 213 | 2, 4, 2, 6, |
michael@0 | 214 | 2, 7, 2, 7)); |
michael@0 | 215 | |
michael@0 | 216 | stTest("selectLinesUpward", "123\n345\n789\n012", |
michael@0 | 217 | setSel(0, 1, 0, 1, |
michael@0 | 218 | 1, 1, 1, 3, |
michael@0 | 219 | 2, 0, 2, 0, |
michael@0 | 220 | 3, 0, 3, 0), |
michael@0 | 221 | "selectLinesUpward", |
michael@0 | 222 | hasSel(0, 1, 0, 1, |
michael@0 | 223 | 0, 3, 0, 3, |
michael@0 | 224 | 1, 0, 1, 0, |
michael@0 | 225 | 1, 1, 1, 3, |
michael@0 | 226 | 2, 0, 2, 0, |
michael@0 | 227 | 3, 0, 3, 0)); |
michael@0 | 228 | |
michael@0 | 229 | stTest("selectLinesDownward", "123\n345\n789\n012", |
michael@0 | 230 | setSel(0, 1, 0, 1, |
michael@0 | 231 | 1, 1, 1, 3, |
michael@0 | 232 | 2, 0, 2, 0, |
michael@0 | 233 | 3, 0, 3, 0), |
michael@0 | 234 | "selectLinesDownward", |
michael@0 | 235 | hasSel(0, 1, 0, 1, |
michael@0 | 236 | 1, 1, 1, 3, |
michael@0 | 237 | 2, 0, 2, 0, |
michael@0 | 238 | 2, 3, 2, 3, |
michael@0 | 239 | 3, 0, 3, 0)); |
michael@0 | 240 | |
michael@0 | 241 | stTest("sortLines", "c\nb\na\nC\nB\nA", |
michael@0 | 242 | "sortLines", val("A\nB\nC\na\nb\nc"), |
michael@0 | 243 | "undo", |
michael@0 | 244 | setSel(0, 0, 2, 0, |
michael@0 | 245 | 3, 0, 5, 0), |
michael@0 | 246 | "sortLines", val("a\nb\nc\nA\nB\nC"), |
michael@0 | 247 | hasSel(0, 0, 2, 1, |
michael@0 | 248 | 3, 0, 5, 1), |
michael@0 | 249 | "undo", |
michael@0 | 250 | setSel(1, 0, 4, 0), "sortLinesInsensitive", val("c\na\nB\nb\nC\nA")); |
michael@0 | 251 | |
michael@0 | 252 | stTest("bookmarks", "abc\ndef\nghi\njkl", |
michael@0 | 253 | Pos(0, 1), "toggleBookmark", |
michael@0 | 254 | setSel(1, 1, 1, 2), "toggleBookmark", |
michael@0 | 255 | setSel(2, 1, 2, 2), "toggleBookmark", |
michael@0 | 256 | "nextBookmark", hasSel(0, 1, 0, 1), |
michael@0 | 257 | "nextBookmark", hasSel(1, 1, 1, 2), |
michael@0 | 258 | "nextBookmark", hasSel(2, 1, 2, 2), |
michael@0 | 259 | "prevBookmark", hasSel(1, 1, 1, 2), |
michael@0 | 260 | "prevBookmark", hasSel(0, 1, 0, 1), |
michael@0 | 261 | "prevBookmark", hasSel(2, 1, 2, 2), |
michael@0 | 262 | "prevBookmark", hasSel(1, 1, 1, 2), |
michael@0 | 263 | "toggleBookmark", |
michael@0 | 264 | "prevBookmark", hasSel(2, 1, 2, 2), |
michael@0 | 265 | "prevBookmark", hasSel(0, 1, 0, 1), |
michael@0 | 266 | "selectBookmarks", hasSel(0, 1, 0, 1, |
michael@0 | 267 | 2, 1, 2, 2), |
michael@0 | 268 | "clearBookmarks", |
michael@0 | 269 | Pos(0, 0), "selectBookmarks", at(0, 0)); |
michael@0 | 270 | |
michael@0 | 271 | stTest("upAndDowncaseAtCursor", "abc\ndef x\nghI", |
michael@0 | 272 | setSel(0, 1, 0, 3, |
michael@0 | 273 | 1, 1, 1, 1, |
michael@0 | 274 | 1, 4, 1, 4), "upcaseAtCursor", |
michael@0 | 275 | val("aBC\nDEF x\nghI"), hasSel(0, 1, 0, 3, |
michael@0 | 276 | 1, 3, 1, 3, |
michael@0 | 277 | 1, 4, 1, 4), |
michael@0 | 278 | "downcaseAtCursor", |
michael@0 | 279 | val("abc\ndef x\nghI"), hasSel(0, 1, 0, 3, |
michael@0 | 280 | 1, 3, 1, 3, |
michael@0 | 281 | 1, 4, 1, 4)); |
michael@0 | 282 | |
michael@0 | 283 | stTest("mark", "abc\ndef\nghi", |
michael@0 | 284 | Pos(1, 1), "setSublimeMark", |
michael@0 | 285 | Pos(2, 1), "selectToSublimeMark", hasSel(2, 1, 1, 1), |
michael@0 | 286 | Pos(0, 1), "swapWithSublimeMark", at(1, 1), "swapWithSublimeMark", at(0, 1), |
michael@0 | 287 | "deleteToSublimeMark", val("aef\nghi"), |
michael@0 | 288 | "sublimeYank", val("abc\ndef\nghi"), at(1, 1)); |
michael@0 | 289 | |
michael@0 | 290 | stTest("findUnder", "foo foobar a", |
michael@0 | 291 | "findUnder", hasSel(0, 4, 0, 7), |
michael@0 | 292 | "findUnder", hasSel(0, 0, 0, 3), |
michael@0 | 293 | "findUnderPrevious", hasSel(0, 4, 0, 7), |
michael@0 | 294 | "findUnderPrevious", hasSel(0, 0, 0, 3), |
michael@0 | 295 | Pos(0, 4), "findUnder", hasSel(0, 4, 0, 10), |
michael@0 | 296 | Pos(0, 11), "findUnder", hasSel(0, 11, 0, 11)); |
michael@0 | 297 | })(); |