ArgParserTestpublic final class ArgParserTest extends TestCase
Fields Summary |
---|
static final String | TAB_STR | static final String | NEWLINE_STR | static final String | RETURN_STR | static final String | ESCAPE_CHAR_STR |
Constructors Summary |
---|
public ArgParserTest()
|
Methods Summary |
---|
public void | TestFailureCases()
boolean success;
final String [] failureExpressions = new String []
{
"{",
"(",
"()",
"(a-b-c)",
"(.abc)",
"({",
"(int)",
"\"\"\"",
"\"",
};
final int numFailureExprs = failureExpressions.length;
String together = "{";
for( int i = 0; i < numFailureExprs; ++i )
{
try
{
testExpr( false, failureExpressions[ i ] );
}
catch( Exception e )
{
fail( "ERROR: case failed: " + failureExpressions[ i ] + "\n" + e.toString() );
}
together = together + failureExpressions[ i ] + ",";
}
together = together + "}";
try
{
testExpr( false, together );
}
catch( Exception e )
{
fail( "ERROR: case failed: " + together + "\n" + e.toString() );
}
| void | dm(java.lang.Object o)
System.out.println( o.toString() );
| com.sun.cli.jmx.support.ParseResult | otherWithCast(java.lang.String str, java.lang.String cast)
return( new ParseResult( ParseResult.OTHER, str, cast ) );
| com.sun.cli.jmx.support.ParseResult | otherWithoutCast(java.lang.String str)
return( new ParseResult( ParseResult.OTHER, str) );
| java.lang.String | quoteString(java.lang.String s)
return( '\"" + s + '\"" );
| com.sun.cli.jmx.support.ParseResult | stringWithCast(java.lang.String str)
return( new ParseResult( ParseResult.LITERAL_STRING, str, "String" ) );
| com.sun.cli.jmx.support.ParseResult | stringWithoutCast(java.lang.String str)
return( new ParseResult( ParseResult.OTHER, str ) );
| public void | testCreate()
new ArgParserImpl();
| public void | testEmpty()
final ArgParserImpl ap = new ArgParserImpl( );
final ParseResult [] results = ap.Parse( "", false );
assertEquals( 0, results.length );
| public void | testEmptyArray()
final String input = "{}";
final ParseResult [] results = new ArgParserImpl().Parse( input, false );
assertEquals( 1, results.length );
final ParseResult expected =
new ParseResult( ParseResult.ARRAY, new ParseResult [ 0 ] );
assertEquals( expected, results[ 0 ] );
| public void | testEmptyStringWithCast()
final ParseResult [] results = new ArgParserImpl().Parse( "(String)", false );
assertEquals( 1, results.length );
assertEquals( stringWithCast( "" ), results[ 0 ] );
| public void | testEscapeCharsInQuotedString()
final String input = TAB_STR + NEWLINE_STR + RETURN_STR + ESCAPE_CHAR_STR;
final ParseResult [] results = new ArgParserImpl().Parse( quoteString( input ), false );
assertEquals( 1, results.length );
assertEquals( stringWithCast( "\t\n\r\\" ), results[ 0 ] );
| public void | testEscapeCharsInUnquotedString()
final String input = TAB_STR + NEWLINE_STR + RETURN_STR + ESCAPE_CHAR_STR;
final ParseResult [] results = new ArgParserImpl().Parse( input, false );
assertEquals( 1, results.length );
assertEquals( stringWithoutCast( "\t\n\r\\" ), results[ 0 ] );
| private void | testExpr(boolean namedArgs, java.lang.String expr)
boolean success = false;
final ParseResult [] results = new ArgParserImpl().Parse( expr, namedArgs );
| public void | testMultiArray()
final String input = "{\"hello\",1,(String)there}";
final ParseResult [] results = new ArgParserImpl().Parse( input, false );
assertEquals( 1, results.length );
final ParseResult [] expectedArrayElements =
{
stringWithCast( "hello" ),
otherWithoutCast( "1" ),
stringWithCast( "there" ),
};
final ParseResult expected = new ParseResult( ParseResult.ARRAY, expectedArrayElements );
assertEquals( 1, results.length );
assertEquals( expected, results[ 0 ] );
| public void | testMultipleStringsWithCast()
final String input = "(String)s1,\"s2\",(String)s3";
final ParseResult [] results = new ArgParserImpl().Parse( input, false );
assertEquals( 3, results.length );
final ParseResult [] expected =
{
stringWithCast( "s1" ),
stringWithCast( "s2" ),
stringWithCast( "s3" ),
};
assertEquals( expected[ 0 ], results[ 0 ] );
assertEquals( expected[ 1 ], results[ 1 ] );
assertEquals( expected[ 2 ], results[ 2 ] );
| public void | testNamedSuccessCases()
// test valid cases
boolean success;
final String [] expressions = new String []
{
"test=hello\\,world",
"hello=1,world=there",
"arg1=1,arg2=2,arg3=3,argString=(String)hello\\,world",
"count=1",
"name=server1,cluster=cluster1,type=instance",
"empty1=,empty2=,empty3="
};
final int numExprs = expressions.length;
String togetherList = "";
for( int i = 0; i < numExprs; ++i )
{
final String testString = expressions[ i ];
try
{
testExpr( true, testString );
}
catch( Exception e )
{
fail( "ERROR: case failed: " + expressions[ i ] + "\n" + e.toString() );
}
togetherList = togetherList + testString + ",";
}
testExpr( false, togetherList );
| public void | testNonNamedSuccessCases()
// test valid cases
boolean success;
final String [] expressions = new String []
{
"1",
"999.0003777",
"\"\"", // empty String
")", // a valid String
"}", // a valid String
"=", // a valid String
"(boolean)true",
"(Boolean)false",
"hello",
"(String)hello",
"\\(String)",
"\",,,,,,,,,\"",
"\"hello\"",
"1,2,3,4,5,6,\"hello\\,,,,,goodbye\",hello\\,goodbye",
"{}",
"{,,,,}",
"{1}",
"{1,2}",
"{1,2,3,4,5,6,hello}",
"{1,2,3,4,5,6,{hello,world}}",
"(Object){(int)1,(long)2,(Integer)3,4,5,6,(String){(String)\"hello\",world}}"
};
final int numExprs = expressions.length;
final String testName = "argName";
String togetherList = "";
String togetherNamed = "";
for( int i = 0; i < numExprs; ++i )
{
final String testString = expressions[ i ];
try
{
testExpr( false, testString );
}
catch( Exception e )
{
fail( "ERROR: case failed: " + expressions[ i ] );
}
togetherList = togetherList + testString + ",";
}
testExpr( false, togetherList );
testExpr( false, "{" + togetherList + "}" );
| public void | testSingleNonNamedStringWithCast()
final ParseResult [] results = new ArgParserImpl().Parse( "(String)hello", false );
assertEquals( 1, results.length );
assertEquals( stringWithCast( "hello" ), results[ 0 ] );
| public void | testSingleNonNamedStringWithoutCast()
final ParseResult [] results = new ArgParserImpl().Parse( "hello", false );
assertEquals( 1, results.length );
assertEquals( stringWithoutCast( "hello" ), results[ 0 ] );
|
|