browser/devtools/sourceeditor/test/cm_search_test.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial