|
1 | 1 | (function() { |
2 | 2 | "use strict"; |
3 | 3 |
|
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 | | - } |
11 | | - |
12 | | - function run(doc, query, insensitive) { |
13 | | - var cursor = doc.getSearchCursor(query, null, insensitive); |
| 4 | + function run(doc, query, options) { |
| 5 | + var cursor = doc.getSearchCursor(query, null, options); |
14 | 6 | for (var i = 3; i < arguments.length; i += 4) { |
15 | 7 | var found = cursor.findNext(); |
16 | 8 | is(found, "not enough results (forward)"); |
|
27 | 19 | is(!cursor.findPrevious(), "too many matches (backwards)"); |
28 | 20 | } |
29 | 21 |
|
30 | | - test("simple", "abcdefg", "abcdefg", function(doc) { |
| 22 | + function test(name, f) { window.test("search_" + name, f) } |
| 23 | + |
| 24 | + test("simple", function() { |
| 25 | + var doc = new CodeMirror.Doc("abcdefg\nabcdefg") |
31 | 26 | run(doc, "cde", false, 0, 2, 0, 5, 1, 2, 1, 5); |
32 | 27 | }); |
33 | 28 |
|
34 | | - test("multiline", "hallo", "a", "b", "goodbye", function(doc) { |
| 29 | + test("multiline", function() { |
| 30 | + var doc = new CodeMirror.Doc("hallo\na\nb\ngoodbye") |
35 | 31 | run(doc, "llo\na\nb\ngoo", false, 0, 2, 3, 3); |
36 | 32 | run(doc, "blah\na\nb\nhall", false); |
37 | 33 | run(doc, "bye\nx\neye", false); |
38 | 34 | }); |
39 | 35 |
|
40 | | - test("regexp", "abcde", "abcde", function(doc) { |
| 36 | + test("regexp", function() { |
| 37 | + var doc = new CodeMirror.Doc("abcde\nabcde") |
41 | 38 | run(doc, /bcd/, false, 0, 1, 0, 4, 1, 1, 1, 4); |
42 | 39 | run(doc, /BCD/, false); |
43 | 40 | run(doc, /BCD/i, false, 0, 1, 0, 4, 1, 1, 1, 4); |
44 | 41 | }); |
45 | 42 |
|
46 | | - test("insensitive", "hallo", "HALLO", "oink", "hAllO", function(doc) { |
| 43 | + test("regexpMultiline", function() { |
| 44 | + var doc = new CodeMirror.Doc("foo foo\nbar\nbaz") |
| 45 | + run(doc, /fo[^]*az/, {multiline: true}, 0, 0, 2, 3) |
| 46 | + run(doc, /[oa][^u]/, {multiline: true}, 0, 1, 0, 3, 0, 5, 0, 7, 1, 1, 1, 3, 2, 1, 2, 3) |
| 47 | + run(doc, /[a][^u]{2}/, {multiline: true}, 1, 1, 2, 0) |
| 48 | + }) |
| 49 | + |
| 50 | + test("insensitive", function() { |
| 51 | + var doc = new CodeMirror.Doc("hallo\nHALLO\noink\nhAllO") |
47 | 52 | run(doc, "All", false, 3, 1, 3, 4); |
48 | 53 | run(doc, "All", true, 0, 1, 0, 4, 1, 1, 1, 4, 3, 1, 3, 4); |
49 | 54 | }); |
50 | 55 |
|
51 | | - test("multilineInsensitive", "zie ginds komT", "De Stoomboot", "uit Spanje weer aan", function(doc) { |
| 56 | + test("multilineInsensitive", function() { |
| 57 | + var doc = new CodeMirror.Doc("zie ginds komT\nDe Stoomboot\nuit Spanje weer aan") |
52 | 58 | 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); |
| 59 | + run(doc, "komt\nde stoomboot\nuit", {caseFold: true}, 0, 10, 2, 3); |
| 60 | + run(doc, "kOMt\ndE stOOmboot\nuiT", {caseFold: true}, 0, 10, 2, 3); |
55 | 61 | }); |
56 | 62 |
|
57 | | - test("expandingCaseFold", "<b>İİ İİ</b>", "<b>uu uu</b>", function(doc) { |
| 63 | + test("multilineInsensitiveSlow", function() { |
| 64 | + var text = "" |
| 65 | + for (var i = 0; i < 1000; i++) text += "foo\nbar\n" |
| 66 | + var doc = new CodeMirror.Doc("find\nme\n" + text + "find\nme\n") |
| 67 | + var t0 = +new Date |
| 68 | + run(doc, /find\nme/, {multiline: true}, 0, 0, 1, 2, 2002, 0, 2003, 2) |
| 69 | + is(+new Date - t0 < 100) |
| 70 | + }) |
| 71 | + |
| 72 | + test("expandingCaseFold", function() { |
58 | 73 | if (phantom) return; // A Phantom bug makes this hang |
| 74 | + var doc = new CodeMirror.Doc("<b>İİ İİ</b>\n<b>uu uu</b>") |
59 | 75 | run(doc, "</b>", true, 0, 8, 0, 12, 1, 8, 1, 12); |
60 | 76 | run(doc, "İİ", true, 0, 3, 0, 5, 0, 6, 0, 8); |
61 | 77 | }); |
|
0 commit comments