//--------------------------------------------------------------------------------------------------
//--- Test Constructors
//--------------------------------------------------------------------------------------------------
void constructorTest( String inputString, AString result, bool trim )
{
    Substring tok= new Substring( inputString );
    if ( trim )
        tok.Trim();
    tok.CopyTo( result );
}
public void SubstringConstructor()
{
    AString astr=   new AString();
    AString res=    new AString();

    constructorTest( "a"        , res, false ); UT_EQ( "a",        res );
    constructorTest( " a"       , res, false ); UT_EQ( " a",       res );
    constructorTest( "a "       , res, false ); UT_EQ( "a ",       res );
    constructorTest( "a b"      , res, false ); UT_EQ( "a b",      res );
    constructorTest( " a b"     , res, false ); UT_EQ( " a b",     res );
    constructorTest( "a b "     , res, false ); UT_EQ( "a b ",     res );

    constructorTest( "a"        , res, true  ); UT_EQ( "a",        res );
    constructorTest( " a"       , res, true  ); UT_EQ( "a",        res );
    constructorTest( "a "       , res, true  ); UT_EQ( "a",        res );
    constructorTest( "a b"      , res, true  ); UT_EQ( "a b",      res );
    constructorTest( " a b"     , res, true  ); UT_EQ( "a b",      res );
    constructorTest( "a b "     , res, true  ); UT_EQ( "a b",      res );

    // changing whitespaces
    {
        {
            astr.Clear()._( "xy xz abc xy" );
            Substring subs= new Substring();
            subs.Set(astr).Trim("xy ".ToCharArray()).CopyTo( res );
            UT_EQ( "z abc",      res );
        }

        {
            Substring subs= new Substring( "xy xz abc xy" );
            subs.TrimStart("xy ".ToCharArray());
            subs.TrimEnd("xy ".ToCharArray());
            subs.CopyTo( res );
            UT_EQ( "z abc",      res );
        }
    }

    // test other constructors
    {
        astr.Clear()._( " astring ");
        UT_TRUE  ( (new Substring()).IsEmpty() );
        UT_TRUE  ( (new Substring()).IsNull() );
        UT_EQ( "astring",  (new Substring( astr)).Trim() .ToString() );
        UT_EQ( "str",      (new Substring( astr,  2, 3 )).ToString() );
        UT_EQ( "",         (new Substring( astr, 20, 3 )).ToString() );
        UT_TRUE (          (new Substring( astr, 20, 3 )).IsEmpty()  );
        UT_FALSE(          (new Substring( astr, 20, 3 )).IsNull()   );


        Substring s2= new Substring( astr);
        UT_EQ( "astring",  new Substring( s2.Trim().ToString() ).ToString() );
        UT_EQ( "str",      (new Substring( (new Substring( astr, 2,3  )))).ToString() );
    }

}