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: import java.util.Collections;
10:
11: /**
12: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
13: * @version $Id: ShortOptionsNoArgumentTest.java,v 1.12 2007/04/10 20:06:26 pholser Exp $
14: */
15: public class ShortOptionsNoArgumentTest extends
16: AbstractOptionParserFixture {
17: protected void setUp() throws Exception {
18: super .setUp();
19:
20: parser.accepts("a");
21: parser.accepts("b");
22: parser.accepts("c");
23: }
24:
25: public void testSingleOption() {
26: OptionSet options = parser.parse(new String[] { "-a" });
27: assertOptionDetected(options, "a");
28: assertNull(options.argumentOf("a"));
29: assertEquals(Collections.EMPTY_LIST, options
30: .nonOptionArguments());
31: }
32:
33: public void testTwoSingleOptions() {
34: OptionSet options = parser.parse(new String[] { "-a", "-b" });
35: assertOptionDetected(options, "a");
36: assertOptionDetected(options, "b");
37: assertNull(options.argumentOf("a"));
38: assertNull(options.argumentOf("b"));
39: assertEquals(Collections.EMPTY_LIST, options
40: .nonOptionArguments());
41: }
42:
43: public void testSingleOptionWithOneNonOptionArgument() {
44: OptionSet options = parser.parse(new String[] { "-c", "foo" });
45: assertOptionDetected(options, "c");
46: assertNull(options.argumentOf("c"));
47: assertEquals(Collections.singletonList("foo"), options
48: .nonOptionArguments());
49: }
50:
51: public void testClusteredOptions() {
52: OptionSet options = parser.parse(new String[] { "-bac" });
53: assertOptionDetected(options, "a");
54: assertOptionDetected(options, "b");
55: assertOptionDetected(options, "c");
56: assertNull(options.argumentOf("a"));
57: assertNull(options.argumentOf("b"));
58: assertNull(options.argumentOf("c"));
59: assertEquals(Collections.EMPTY_LIST, options
60: .nonOptionArguments());
61: }
62:
63: public void testOptionsTerminator() {
64: OptionSet options = parser.parse(new String[] { "-a",
65: ParserRules.OPTION_TERMINATOR, "-a", "-b" });
66: assertOptionDetected(options, "a");
67: assertNull(options.argumentOf("a"));
68: assertOptionNotDetected(options, "b");
69: assertEquals(Arrays.asList(new String[] { "-a", "-b" }),
70: options.nonOptionArguments());
71: }
72:
73: public void testAppearingMultipleTimes() {
74: OptionSet options = parser.parse(new String[] { "-b", "-b",
75: "-b" });
76: assertOptionDetected(options, "b");
77: assertNull(options.argumentOf("b"));
78: assertEquals(Collections.EMPTY_LIST, options
79: .nonOptionArguments());
80: }
81: }
|