[stringtemplate-interest] Problem with checking length of string

Kunle Odutola Kunle_Odutola at hotmail.com
Thu Jun 1 18:35:39 PDT 2006


Hi Kenny,

Thanks for the report and the tests.

> I had the following test script in c# 2.3b7 version
>
>       string TestIfStr = @"
> group Base ;
> TestStr(EmptyString) ::=<<
> $if(!EmptyString)$
>    String Passed is NULL
> $endif$
>
> $if(!EmptyString.Length )$
>    String Passed has a Zero Length
> $endif$
>
> $if( EmptyString )$
>    Test for non null String Passed is The value ""$EmptyString$""
> $endif$
>
> $if( EmptyString.Length )$
>    String Has a Non Zero Length and the value ""$EmptyString$""
> $endif$
>
>  >>
> ";
>             stg = new StringTemplateGroup(new StringReader(TestIfStr),
> typeof(DefaultTemplateLexer));
>             sta3 = stg.GetInstanceOf("TestStr");
>             sta3.SetAttribute("EmptyString", "I have set a Value");
>             System.Console.WriteLine("EmptyString Passing In Value");
>             System.Console.WriteLine(sta3.ToString());
>
>             sta3 = stg.GetInstanceOf("TestStr");
>             System.Console.WriteLine("EmptyString Set To Empty String");
>             sta3.SetAttribute("EmptyString", string.Empty);
>             System.Console.WriteLine(sta3.ToString());
>
>             sta3 = stg.GetInstanceOf("TestStr");
>             System.Console.WriteLine("EmptyString To the null value");
>             sta3.SetAttribute("EmptyString", null);
>             System.Console.WriteLine(sta3.ToString());
>
>
> -----
>
> The only test that worked was when the string being passed contained a
> Null reference ;

I ran the tests on a .NET 2.0 systems and this is the output I got:

<output>
EmptyString Passing In Value
   Test for non null String Passed is The value "I have set a Value"

   String Has a Non Zero Length and the value "I have set a Value"


EmptyString Set To Empty String
   Test for non null String Passed is The value ""

   String Has a Non Zero Length and the value ""


EmptyString To the null value
   String Passed is NULL
   String Passed has a Zero Length
</output>

Did you get the same?

The output confirms that ST# works as advertised. The $if()$
directive in ST/ST# is checks for attribute existence. If the
attribute exists and is of type 'bool', it also checks that the value is
"true".

Thank you.


Kunle


More information about the stringtemplate-interest mailing list