Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Add unit test for remembering regexp state for Find Next after search…
Browse files Browse the repository at this point in the history
… bar is closed.

Also refactors out some common code from the case sensitivity test.
  • Loading branch information
njx committed Mar 1, 2014
1 parent d5f3022 commit 7b1f77d
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions test/spec/FindReplace-test.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 7b1f77d

Please sign in to comment.