[stringtemplate-interest] More Issues with Collections
Kenny Cockburn
kenny.cockburn at ntlworld.com
Sat Jun 3 09:46:19 PDT 2006
Hi,
I thave found what I think are problems with IEnumerator
1. IEnumerator does not call rest() after the collection has finished
the iteration
2.IEnumerator First() works but rest() call misses a row in the collection
here is the code to show both problems :
static void Main()
{
string simpleIfTest = @"
group TestIEnum ;
Action(Arg) ::=<<
iterate 1
$Arg:{X=$it$ # }$
---- /
iterate 2
$Arg:{X=$it$ # }$
----
>>
ActionFirstRest(Arg) ::=<<
First Rest Tests
iterate 1
First
$first(Arg):{X=$it$ # }$
Rest
$rest(Arg):{X=$it$ # }$
---- /
iterate 2
First
$first(Arg):{X=$it$ # }$
Rest
$rest(Arg):{X=$it$ # }$
----
>>
";
StringTemplateGroup stg = new StringTemplateGroup(new
StringReader(simpleIfTest), typeof(DefaultTemplateLexer));
int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };
System.Console.WriteLine("Run Test with simple Array");
StringTemplate sta3 = stg.GetInstanceOf("Action");
sta3.SetAttribute("Arg", myIntArray);
System.Console.WriteLine(sta3.ToString());
System.Console.WriteLine("Run Test with type only supporting
IEnumerator");
sta3 = stg.GetInstanceOf("Action");
sta3.SetAttribute("Arg", myIntArray.GetEnumerator() );
System.Console.WriteLine(sta3.ToString());
System.Console.WriteLine("Run First Rest Test with simple
Array");
sta3 = stg.GetInstanceOf("ActionFirstRest");
sta3.SetAttribute("Arg", myIntArray);
System.Console.WriteLine(sta3.ToString());
System.Console.WriteLine("Run First Rest Test with type only
supporting IEnumerator");
sta3 = stg.GetInstanceOf("ActionFirstRest");
sta3.SetAttribute("Arg", myIntArray.GetEnumerator());
System.Console.WriteLine(sta3.ToString());
}
More information about the stringtemplate-interest
mailing list