Permalink
Browse files

Add unit test for remembering regexp state for Find Next after search…

… bar is closed.

Also refactors out some common code from the case sensitivity test.
  • Loading branch information...
1 parent d5f3022 commit 7b1f77d719715ef8064d2858ee0a808b76f99e8a @njx njx committed Mar 1, 2014
Showing with 43 additions and 10 deletions.
  1. +43 −10 test/spec/FindReplace-test.js
@@ -107,6 +107,16 @@ define(function (require, exports, module) {
}
expect(actualHighlights.length).toEqual(expectedDOMHighlightCount);
}
+ function expectFindNextSelections(selections) {
+ var i;
+ for (i = 0; i < selections.length; i++) {
+ expectSelection(selections[i]);
+ twCommandManager.execute(Commands.EDIT_FIND_NEXT);
+ }
+
+ // next find should wraparound
+ expectSelection(selections[0]);
+ }
function getSearchBar() {
@@ -422,15 +432,7 @@ define(function (require, exports, module) {
waitsForSearchBarClose();
runs(function () {
- expectSelection(capitalFooSelections[0]);
- twCommandManager.execute(Commands.EDIT_FIND_NEXT);
- expectSelection(capitalFooSelections[1]);
- twCommandManager.execute(Commands.EDIT_FIND_NEXT);
- expectSelection(capitalFooSelections[2]);
-
- // next find should wraparound since it should skip the lowercase "foo()"
- twCommandManager.execute(Commands.EDIT_FIND_NEXT);
- expectSelection(capitalFooSelections[0]);
+ expectFindNextSelections(capitalFooSelections);
});
});
@@ -695,6 +697,37 @@ define(function (require, exports, module) {
expectSelection(expectedSelections[0]);
});
+
+ it("should Find Next after search bar closed, remembering last used regexp", function () {
+ var expectedSelections = [
+ {start: {line: LINE_FIRST_REQUIRE + 1, ch: 8}, end: {line: LINE_FIRST_REQUIRE + 1, ch: 11}},
+ {start: {line: LINE_FIRST_REQUIRE + 1, ch: 31}, end: {line: LINE_FIRST_REQUIRE + 1, ch: 34}},
+ {start: {line: LINE_FIRST_REQUIRE + 2, ch: 8}, end: {line: LINE_FIRST_REQUIRE + 2, ch: 11}},
+ {start: {line: LINE_FIRST_REQUIRE + 2, ch: 31}, end: {line: LINE_FIRST_REQUIRE + 2, ch: 34}}
+ ];
+
+ runs(function () {
+ myEditor.setCursorPos(0, 0);
+
+ twCommandManager.execute(Commands.EDIT_FIND);
+
+ toggleRegexp(true);
+ enterSearchText("Ba.");
+ pressEscape();
+ expectHighlightedMatches([]);
+ });
+
+ waitsForSearchBarClose();
+
+ runs(function () {
+ expectFindNextSelections(expectedSelections);
+
+ // explicitly clean up since we closed the search bar
+ twCommandManager.execute(Commands.EDIT_FIND);
+ toggleRegexp(false);
+ });
+ });
+
it("toggling regexp option should update results immediately", function () {
myEditor.setCursorPos(0, 0);
@@ -745,7 +778,7 @@ define(function (require, exports, module) {
expectHighlightedMatches(expectedSelections);
expectSelection(expectedSelections[0]);
});
-
+
it("shouldn't choke on invalid regexp", function () {
myEditor.setCursorPos(0, 0);

0 comments on commit 7b1f77d

Please sign in to comment.