package org.jetbrains.plugins.ideavim.helper;

import com.maddyhome.idea.vim.helper.SearchHelper;
import org.jetbrains.plugins.ideavim.VimTestCase;

public class SearchHelperTest extends VimTestCase {
  public void testFindNextWord() {
    String text = "first second";
    int nextWordPosition = SearchHelper.findNextWord(text, 0, text.length(), 1, true, false);

    assertEquals(nextWordPosition, text.indexOf("second"));
  }

  public void testFindSecondNextWord() {
    String text = "first second third";
    int nextWordPosition = SearchHelper.findNextWord(text, 0, text.length(), 2, true, false);

    assertEquals(nextWordPosition, text.indexOf("third"));
  }

  public void testFindAfterLastWord() {
    String text = "first second";
    int nextWordPosition = SearchHelper.findNextWord(text, 0, text.length(), 3, true, false);

    assertEquals(nextWordPosition, text.length());
  }

  public void testFindPreviousWord() {
    String text = "first second";
    int previousWordPosition = SearchHelper.findNextWord(text, text.indexOf("second"), text.length(), -1, true, false);

    assertEquals(previousWordPosition, text.indexOf("first"));
  }

  public void testFindSecondPreviousWord() {
    String text = "first second third";
    int previousWordPosition = SearchHelper.findNextWord(text, text.indexOf("third"), text.length(), -2, true, false);

    assertEquals(previousWordPosition, text.indexOf("first"));
  }

  public void testFindBeforeFirstWord() {
    String text = "first second";
    int previousWordPosition = SearchHelper.findNextWord(text, text.indexOf("second"), text.length(), -3, true, false);

    assertEquals(previousWordPosition, text.indexOf("first"));
  }

  public void testFindPreviousWordWhenCursorOutOfBound() {
    String text = "first second";
    int previousWordPosition = SearchHelper.findNextWord(text, text.length(), text.length(), -1, true, false);

    assertEquals(previousWordPosition, text.indexOf("second"));
  }
}

@@ -142,16 +142,85 @@
 tCase;%0A%0A
+import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;%0A%0A
 public c
@@ -2029,11 +2029,189 @@
 %22));%0A  %7D
+%0A%0A  public void testMotionOuterWordAction() %7B%0A    typeTextInFile(parseKeys(%22v%22, %22a(%22), %22((int) nu%3Ccaret%3Em)%22);%0A    myFixture.checkResult(%22%3Cselection%3E((int) num)%3C/selection%3E%22);%0A  %7D
 %0A%7D%0A

Add a unit test