1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/sourceeditor/test/cm_search_test.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,62 @@ 1.4 +(function() { 1.5 + "use strict"; 1.6 + 1.7 + function test(name) { 1.8 + var text = Array.prototype.slice.call(arguments, 1, arguments.length - 1).join("\n"); 1.9 + var body = arguments[arguments.length - 1]; 1.10 + return window.test("search_" + name, function() { 1.11 + body(new CodeMirror.Doc(text)); 1.12 + }); 1.13 + } 1.14 + 1.15 + function run(doc, query, insensitive) { 1.16 + var cursor = doc.getSearchCursor(query, null, insensitive); 1.17 + for (var i = 3; i < arguments.length; i += 4) { 1.18 + var found = cursor.findNext(); 1.19 + is(found, "not enough results (forward)"); 1.20 + eqPos(Pos(arguments[i], arguments[i + 1]), cursor.from(), "from, forward, " + (i - 3) / 4); 1.21 + eqPos(Pos(arguments[i + 2], arguments[i + 3]), cursor.to(), "to, forward, " + (i - 3) / 4); 1.22 + } 1.23 + is(!cursor.findNext(), "too many matches (forward)"); 1.24 + for (var i = arguments.length - 4; i >= 3; i -= 4) { 1.25 + var found = cursor.findPrevious(); 1.26 + is(found, "not enough results (backwards)"); 1.27 + eqPos(Pos(arguments[i], arguments[i + 1]), cursor.from(), "from, backwards, " + (i - 3) / 4); 1.28 + eqPos(Pos(arguments[i + 2], arguments[i + 3]), cursor.to(), "to, backwards, " + (i - 3) / 4); 1.29 + } 1.30 + is(!cursor.findPrevious(), "too many matches (backwards)"); 1.31 + } 1.32 + 1.33 + test("simple", "abcdefg", "abcdefg", function(doc) { 1.34 + run(doc, "cde", false, 0, 2, 0, 5, 1, 2, 1, 5); 1.35 + }); 1.36 + 1.37 + test("multiline", "hallo", "goodbye", function(doc) { 1.38 + run(doc, "llo\ngoo", false, 0, 2, 1, 3); 1.39 + run(doc, "blah\nhall", false); 1.40 + run(doc, "bye\neye", false); 1.41 + }); 1.42 + 1.43 + test("regexp", "abcde", "abcde", function(doc) { 1.44 + run(doc, /bcd/, false, 0, 1, 0, 4, 1, 1, 1, 4); 1.45 + run(doc, /BCD/, false); 1.46 + run(doc, /BCD/i, false, 0, 1, 0, 4, 1, 1, 1, 4); 1.47 + }); 1.48 + 1.49 + test("insensitive", "hallo", "HALLO", "oink", "hAllO", function(doc) { 1.50 + run(doc, "All", false, 3, 1, 3, 4); 1.51 + run(doc, "All", true, 0, 1, 0, 4, 1, 1, 1, 4, 3, 1, 3, 4); 1.52 + }); 1.53 + 1.54 + test("multilineInsensitive", "zie ginds komT", "De Stoomboot", "uit Spanje weer aan", function(doc) { 1.55 + run(doc, "komt\nde stoomboot\nuit", false); 1.56 + run(doc, "komt\nde stoomboot\nuit", true, 0, 10, 2, 3); 1.57 + run(doc, "kOMt\ndE stOOmboot\nuiT", true, 0, 10, 2, 3); 1.58 + }); 1.59 + 1.60 + test("expandingCaseFold", "<b>İİ İİ</b>", "<b>uu uu</b>", function(doc) { 1.61 + if (phantom) return; // A Phantom bug makes this hang 1.62 + run(doc, "</b>", true, 0, 8, 0, 12, 1, 8, 1, 12); 1.63 + run(doc, "İİ", true, 0, 3, 0, 5, 0, 6, 0, 8); 1.64 + }); 1.65 +})();