Methods Summary |
---|
protected void | newWayInner(com.darwinsys.lang.GetOpt go, java.util.Map map)
assertFalse(map.size() == 0);
if (map.size() == 0) {
throw new IllegalArgumentException(
"Unexpected empty map");
}
int errs = 0;
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
String key = (String)it.next();
char c = key.charAt(0);
String val = (String)map.get(key);
switch(c) {
case '?":
errs++; break;
case 'o": assertEquals(val, "outfile"); break;
case 'f":
case 'h":
case '1":
assertEquals(val, null);
break;
default:
throw new IllegalArgumentException(
"Unexpected c value " + c);
}
}
assertEquals(1, go.getFilenameList().size());
assertEquals("infile", go.getFilenameList().get(0));
|
void | process1(java.lang.String argChars, java.lang.String[] args, boolean shouldFail)
System.out.println("** START ** " + argChars);
GetOpt go = new GetOpt(argChars);
int errs = 0, ix = 0;
char c;
while ((c = go.getopt(args)) != 0) {
if (c == '?") {
System.out.print("Bad option");
++errs;
} else {
System.out.print("Found " + c);
if (go.optarg() != null)
System.out.print("; Option " + go.optarg());
}
System.out.println();
}
// Process any filename-like arguments.
for (int i=go.getOptInd(); i<args.length; i++) {
System.out.println("Filename-like arg " + args[i]);
}
|
void | process2(java.lang.String argChars, java.lang.String[] args, boolean shouldFail)
int errs = 0;
System.out.println("** START NEW WAY ** " + argChars);
GetOpt go2 = new GetOpt(argChars);
Map m = go2.parseArguments(args);
if (m.size() == 0)
System.out.println("NO ARGS MATCHED");
Iterator it = m.keySet().iterator();
while (it.hasNext()) {
Object key = it.next();
char c = ((String)key).charAt(0);
System.out.print("Found " + c);
if (c == '?")
errs++;
String val = (String)m.get(key);
if (val == null || val.equals(""))
System.out.print("; (no option)");
else
System.out.print("; Option " + val);
System.out.println();
}
List filenames = go2.getFilenameList();
for (int i = 0; i < filenames.size(); i++) {
System.out.println("Filename-like arg " + filenames.get(i));
}
if (shouldFail) {
if (errs != 0)
System.out.println("Expected error(s) found");
else
System.out.println("** FAILURE ** Expected errors not found");
} else {
if (errs == 0)
System.out.println("Expected error(s) found");
else
System.out.println("** FAILURE ** Expected errors not found");
}
|
public void | testBadArgChar()
String bad = "abc@";
try {
new GetOpt(bad);
fail("GetOpt(" + bad + ") did not throw expected exception");
} catch (IllegalArgumentException ex) {
System.err.println("Caught expected exception " + ex);
}
|
public void | testConstructorArgs()
try {
String bad = null;
new GetOpt(bad);
fail("GetOpt(null) did not throw expected exception");
} catch (IllegalArgumentException ex) {
System.err.println("Caught expected exception " + ex);
}
try {
new GetOpt("::");
fail("GetOpt(::) did not throw expected exception");
} catch (IllegalArgumentException ex) {
System.err.println("Caught expected exception " + ex);
}
new GetOpt("f:c:"); // this failed at one point - multiple : args
new GetOpt("foo"); // multiple occurrences of same letter - ok?
|
public void | testNewWayLong()
GetOpt go = new GetOpt(options);
Map map = go.parseArguments(goodLongArgs);
newWayInner(go, map);
|
public void | testNewWayShort()
GetOpt go = new GetOpt(options);
Map map = go.parseArguments(goodArgs);
newWayInner(go, map);
|
public void | testOldwayBadCharsBadArgs()
process1(badArgChars, badArgs, true);
process2(badArgChars, badArgs, true);
|
public void | testOldwayBadCharsGoodArgs()
process1(badArgChars, goodArgs, true);
process2(badArgChars, goodArgs, true);
|
public void | testOldwayGood()
process1(goodArgChars, goodArgs, false);
process2(goodArgChars, goodArgs, false);
|