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

Commit

Permalink
added tests for valid command lines
Browse files Browse the repository at this point in the history
  • Loading branch information
tenorviol committed Jan 2, 2012
1 parent f8e8eac commit d44354d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Binary file modified lib/gitsearch-0.1.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/CommandLine.java
Expand Up @@ -53,7 +53,7 @@ public static void help() {
// + " [-index INDEX_PATH] [-docs DOCS_PATH] [-update]\n\n"
// + "This indexes the documents in DOCS_PATH, creating a Lucene index"
// + "in INDEX_PATH that can be searched with SearchFiles";
System.out.println("java com.github.tenorviol.gitsearch.CommandLine --index <index path> search <query term(s)>");
System.out.println("java com.github.tenorviol.gitsearch.CommandLine --index <index path> query <query term(s)>");
//String usage =
// "Usage:\tjava org.apache.lucene.demo.SearchFiles [-index dir] [-field f] [-repeat n] [-queries file] [-query string] [-raw] [-paging hitsPerPage]\n\nSee http://lucene.apache.org/java/4_0/demo.html for details.";
}
Expand Down
35 changes: 30 additions & 5 deletions test/CommandLineTest.java
Expand Up @@ -3,18 +3,21 @@

import com.github.tenorviol.gitsearch.CommandLine;

import java.util.Arrays;
import java.util.List;

public class CommandLineTest {

@DataProvider(name = "invalid-command-lines")
public Object[][] illegalCommandLineProvider() {
return new Object[][] {
{ null },
{ "--index" },
{ "--index ./.index" },
{ "--index ./.index index" },
{ "--index ./.index query" },
{ "--index ./.index non-command" },
{ "query --index ./.index foo" },
{ "--index path/to/index" },
{ "--index path/to/index index" },
{ "--index path/to/index query" },
{ "--index path/to/index non-command" },
{ "query --index path/to/index add/to/index" },
};
}

Expand All @@ -24,4 +27,26 @@ public void testInvalidCommandLineThrowsIllegalArgumentException(String commandL
String[] args = (null == commandLine) ? new String[] {} : commandLine.split(" ");
CommandLine cl = new CommandLine(args);
}

@DataProvider(name = "command-lines")
public Object[][] commandLineProvider() {
return new Object[][] {
{ "--index path/to/index index add/to/index second/add/to/index" },
{ "--index path/to/index query word1 word2 field:word3" },
};
}

@Test(dataProvider = "command-lines")
public void testIndexCommand(String commandLine) {
String[] args = commandLine.split(" ");
CommandLine cl = new CommandLine(args);

Assert.assertEquals(cl.indexPath, args[1]);
Assert.assertEquals(cl.command, args[2]);
Assert.assertEquals(cl.commandArgs.size(), args.length - 3);

List list = Arrays.asList(args);
list = list.subList(3, list.size());
Assert.assertEquals(cl.commandArgs, list);
}
}

0 comments on commit d44354d

Please sign in to comment.