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.Collections;
09:
10: /**
11: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
12: * @version $Id: LongOptionOptionalArgumentTest.java,v 1.12 2007/04/10 20:06:26 pholser Exp $
13: */
14: public class LongOptionOptionalArgumentTest extends
15: AbstractOptionParserFixture {
16: protected void setUp() throws Exception {
17: super .setUp();
18:
19: parser.accepts("output").withOptionalArg();
20: parser.accepts("a");
21: }
22:
23: public void testArgumentMissingTrailedByAnotherOption() {
24: OptionSet options = parser.parse(new String[] { "--output",
25: "-a" });
26: assertTrue(options.wasDetected("output"));
27: assertTrue(options.wasDetected("a"));
28: assertEquals(Collections.EMPTY_LIST, options
29: .argumentsOf("output"));
30: assertEquals(Collections.EMPTY_LIST, options
31: .nonOptionArguments());
32: }
33:
34: public void testArgumentSeparate() {
35: OptionSet options = parser.parse(new String[] { "--output",
36: "/opt" });
37: assertTrue(options.wasDetected("output"));
38: assertEquals(Collections.singletonList("/opt"), options
39: .argumentsOf("output"));
40: assertEquals(Collections.EMPTY_LIST, options
41: .nonOptionArguments());
42: }
43:
44: public void testArgumentTogether() {
45: OptionSet options = parser
46: .parse(new String[] { "--output=/opt" });
47: assertTrue(options.wasDetected("output"));
48: assertEquals(Collections.singletonList("/opt"), options
49: .argumentsOf("output"));
50: assertEquals(Collections.EMPTY_LIST, options
51: .nonOptionArguments());
52: }
53: }
|