01: /*
02: Copyright 2004-2007 Paul R. Holser, Jr. All rights reserved.
03: Licensed under the Academic Free License version 3.0
04: */
05:
06: package joptsimple;
07:
08: import java.util.Arrays;
09:
10: import junit.framework.Test;
11: import junit.framework.TestCase;
12: import junit.framework.TestSuite;
13:
14: /**
15: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
16: * @version $Id: PosixlyCorrectOptionParserTest.java,v 1.17 2007/04/10 20:06:27 pholser Exp $
17: */
18: public class PosixlyCorrectOptionParserTest extends TestCase {
19: private OptionParser parser;
20:
21: private PosixlyCorrectOptionParserTest(String name,
22: OptionParser parser) {
23: super (name);
24:
25: this .parser = parser;
26: }
27:
28: protected void runTest() {
29: OptionSet options = parser.parse(new String[] { "-ibar", "-i",
30: "junk", "xyz", "-jixnay", "foo", "-k", "blah", "--",
31: "yermom" });
32:
33: assertTrue("i?", options.wasDetected("i"));
34: assertFalse("j?", options.wasDetected("j"));
35: assertFalse("k?", options.wasDetected("k"));
36: assertEquals("args of i?", Arrays.asList(new String[] { "bar",
37: "junk" }), options.argumentsOf("i"));
38: assertEquals("non-option args?", Arrays
39: .asList(new String[] { "xyz", "-jixnay", "foo", "-k",
40: "blah", "--", "yermom" }), options
41: .nonOptionArguments());
42: }
43:
44: public static Test suite() {
45: TestSuite suite = new TestSuite("Posixly-Correct parser tests");
46:
47: OptionParser parser = new OptionParser() {
48: {
49: setPosixlyCorrect(true);
50: accepts("i").withRequiredArg();
51: accepts("j").withOptionalArg();
52: accepts("k");
53: }
54: };
55:
56: suite.addTest(new PosixlyCorrectOptionParserTest(
57: "from factory method", parser));
58:
59: suite.addTest(new PosixlyCorrectOptionParserTest(
60: "from specification string",
61: new OptionParser("+i:j::k")));
62:
63: return suite;
64: }
65: }
|