public void ParseNumbers() { // ConsumeInteger() { Substring subs= new Substring(); int result; UT_EQ( false, subs.ConsumeInteger( out result ) ); UT_EQ( 0, result ); subs.Set( "" ); UT_EQ( false, subs.ConsumeInteger( out result ) ); UT_EQ( 0, result ); subs.Set( " ABC" ); UT_EQ( false, subs.ConsumeInteger( out result ) ); UT_EQ( 0, result ); subs.Set( " 12345" ); UT_EQ( true , subs.ConsumeInteger( out result ) ); UT_EQ( 12345, result ); subs.Set( " 12 45" ); UT_EQ( true , subs.ConsumeInteger( out result ) ); UT_EQ( 12, result ); UT_EQ( true , subs.ConsumeInteger( out result ) ); UT_EQ( 45, result ); subs.Set( " 42 ; 7 ; 6 "); UT_EQ( true , subs.ConsumeInteger( out result ) ); UT_EQ( 42, result ); UT_EQ( false, subs.ConsumeInteger( out result ) ); UT_EQ( 0, result ); UT_EQ( false, subs.ConsumeInteger( out result ) ); UT_EQ( 0, result ); char[] ws= " ;".ToCharArray(); subs.Set( " 42 ; 7 ; 6 "); UT_EQ( true , subs.ConsumeInteger( out result, ws ) ); UT_EQ( 42, result ); UT_EQ( true , subs.ConsumeInteger( out result, ws ) ); UT_EQ( 7, result ); UT_EQ( true , subs.ConsumeInteger( out result, ws ) ); UT_EQ( 6, result ); UT_EQ( false, subs.ConsumeInteger( out result, ws ) ); UT_EQ( 0, result ); UT_EQ( false, subs.ConsumeInteger( out result, ws ) ); UT_EQ( 0, result ); } // ConsumeFloat() { Substring subs= new Substring(); double result; UT_EQ( false, subs.ConsumeFloat ( out result ) ); UT_EQ( 0.0, result ); subs.Set( "" ) ; UT_EQ( false, subs.ConsumeFloat ( out result ) ); UT_EQ( 0.0, result ); subs.Set( " ABC" ) ; UT_EQ( false, subs.ConsumeFloat ( out result ) ); UT_EQ( 0.0, result ); subs.Set( " 12345" ) ; UT_EQ( true , subs.ConsumeFloat ( out result ) ); UT_EQ( 12345.0, result ); subs.Set( " 12.45 " ) ; UT_EQ( true , subs.ConsumeFloat ( out result ) ); UT_EQ( 12.45, result ); subs.Set( " 12 45" ) ; UT_EQ( true , subs.ConsumeFloat ( out result ) ); UT_EQ( 12.0, result ); UT_EQ( true , subs.ConsumeFloat ( out result ) ); UT_EQ( 45.0, result ); char[] ws= " ;".ToCharArray(); subs.Set( " 42.3 ; 0.7 ; 6 " ); UT_EQ( true , subs.ConsumeFloat ( out result, null, ws ) ); UT_EQ( 42.3, result ); UT_EQ( true , subs.ConsumeFloat ( out result, null, ws ) ); UT_EQ( 0.7, result ); UT_EQ( true , subs.ConsumeFloat ( out result, null, ws ) ); UT_EQ( 6.0, result ); UT_EQ( false, subs.ConsumeFloat ( out result, null, ws ) ); UT_EQ( 0.0, result ); UT_EQ( false, subs.ConsumeFloat ( out result, null, ws ) ); UT_EQ( 0.0, result ); } }