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: WAsAbbreviationForLongOptionTest.java,v 1.15 2007/04/10 20:06:26 pholser Exp $
13: */
14: public class WAsAbbreviationForLongOptionTest extends
15: AbstractOptionParserFixture {
16: protected void setUp() throws Exception {
17: super .setUp();
18:
19: parser.accepts("Wally").withRequiredArg();
20: }
21:
22: public void testAbbreviation() {
23: OptionSet options = parser
24: .parse(new String[] { "--W", "silent" });
25: assertOptionDetected(options, "Wally");
26: assertOptionNotDetected(options, "W");
27: assertEquals(Collections.singletonList("silent"), options
28: .argumentsOf("Wally"));
29: assertEquals(Collections.EMPTY_LIST, options
30: .nonOptionArguments());
31: }
32:
33: public void testRecognizeLongOptionsTrumpsLongOptionAbbreviation() {
34: parser.recognizeAlternativeLongOptions(true);
35:
36: try {
37: parser.parse(new String[] { "--W", "silent" });
38: fail();
39: } catch (UnrecognizedOptionException expected) {
40: assertEquals("silent", expected.option());
41: }
42: }
43: }
|