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.
1 (function() {
2 "use strict";
4 function test(name) {
5 var text = Array.prototype.slice.call(arguments, 1, arguments.length - 1).join("\n");
6 var body = arguments[arguments.length - 1];
7 return window.test("search_" + name, function() {
8 body(new CodeMirror.Doc(text));
9 });
10 }
12 function run(doc, query, insensitive) {
13 var cursor = doc.getSearchCursor(query, null, insensitive);
14 for (var i = 3; i < arguments.length; i += 4) {
15 var found = cursor.findNext();
16 is(found, "not enough results (forward)");
17 eqPos(Pos(arguments[i], arguments[i + 1]), cursor.from(), "from, forward, " + (i - 3) / 4);
18 eqPos(Pos(arguments[i + 2], arguments[i + 3]), cursor.to(), "to, forward, " + (i - 3) / 4);
19 }
20 is(!cursor.findNext(), "too many matches (forward)");
21 for (var i = arguments.length - 4; i >= 3; i -= 4) {
22 var found = cursor.findPrevious();
23 is(found, "not enough results (backwards)");
24 eqPos(Pos(arguments[i], arguments[i + 1]), cursor.from(), "from, backwards, " + (i - 3) / 4);
25 eqPos(Pos(arguments[i + 2], arguments[i + 3]), cursor.to(), "to, backwards, " + (i - 3) / 4);
26 }
27 is(!cursor.findPrevious(), "too many matches (backwards)");
28 }
30 test("simple", "abcdefg", "abcdefg", function(doc) {
31 run(doc, "cde", false, 0, 2, 0, 5, 1, 2, 1, 5);
32 });
34 test("multiline", "hallo", "goodbye", function(doc) {
35 run(doc, "llo\ngoo", false, 0, 2, 1, 3);
36 run(doc, "blah\nhall", false);
37 run(doc, "bye\neye", false);
38 });
40 test("regexp", "abcde", "abcde", function(doc) {
41 run(doc, /bcd/, false, 0, 1, 0, 4, 1, 1, 1, 4);
42 run(doc, /BCD/, false);
43 run(doc, /BCD/i, false, 0, 1, 0, 4, 1, 1, 1, 4);
44 });
46 test("insensitive", "hallo", "HALLO", "oink", "hAllO", function(doc) {
47 run(doc, "All", false, 3, 1, 3, 4);
48 run(doc, "All", true, 0, 1, 0, 4, 1, 1, 1, 4, 3, 1, 3, 4);
49 });
51 test("multilineInsensitive", "zie ginds komT", "De Stoomboot", "uit Spanje weer aan", function(doc) {
52 run(doc, "komt\nde stoomboot\nuit", false);
53 run(doc, "komt\nde stoomboot\nuit", true, 0, 10, 2, 3);
54 run(doc, "kOMt\ndE stOOmboot\nuiT", true, 0, 10, 2, 3);
55 });
57 test("expandingCaseFold", "<b>İİ İİ</b>", "<b>uu uu</b>", function(doc) {
58 if (phantom) return; // A Phantom bug makes this hang
59 run(doc, "</b>", true, 0, 8, 0, 12, 1, 8, 1, 12);
60 run(doc, "İİ", true, 0, 3, 0, 5, 0, 6, 0, 8);
61 });
62 })();