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