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: WExtensionRequiredArgumentTest.java,v 1.14 2007/04/10 20:06:27 pholser Exp $
13: */
14: public class WExtensionRequiredArgumentTest extends
15: AbstractOptionParserFixture {
16: protected void setUp() throws Exception {
17: super .setUp();
18:
19: parser.recognizeAlternativeLongOptions(true);
20: parser.accepts("silent").withOptionalArg();
21: }
22:
23: public void testSeparateArgument() {
24: OptionSet options = parser.parse(new String[] { "-W", "silent",
25: "4" });
26: assertOptionNotDetected(options, "W");
27: assertOptionDetected(options, "silent");
28: assertEquals(Collections.singletonList("4"), options
29: .argumentsOf("silent"));
30: assertEquals(Collections.EMPTY_LIST, options
31: .nonOptionArguments());
32: }
33:
34: public void testTogetherArgument() {
35: OptionSet options = parser.parse(new String[] { "-W",
36: "silent=6" });
37: assertOptionNotDetected(options, "W");
38: assertOptionDetected(options, "silent");
39: assertEquals(Collections.singletonList("6"), options
40: .argumentsOf("silent"));
41: assertEquals(Collections.EMPTY_LIST, options
42: .nonOptionArguments());
43: }
44:
45: public void testAbbreviationWithTogetherArgument() {
46: OptionSet options = parser.parse(new String[] { "-W", "s=6" });
47: assertOptionNotDetected(options, "W");
48: assertOptionDetected(options, "silent");
49: assertOptionNotDetected(options, "s");
50: assertEquals(Collections.singletonList("6"), options
51: .argumentsOf("silent"));
52: assertEquals(Collections.EMPTY_LIST, options
53: .nonOptionArguments());
54: }
55:
56: public void testIllegalLongOption() {
57: try {
58: parser.parse(new String[] { "-W", "foo=bar" });
59: fail();
60: } catch (UnrecognizedOptionException expected) {
61: assertEquals("foo", expected.option());
62: }
63: }
64:
65: public void testNoMoreArguments() {
66: try {
67: parser.parse(new String[] { "-W" });
68: fail();
69: } catch (OptionMissingRequiredArgumentException expected) {
70: assertEquals("W", expected.option());
71: }
72: }
73: }
|