public void TestGroupFileFormat() { string templates = "group test;" + newline + "t() ::= \"literal template\"" + newline + "bold(item) ::= \"<b>$item$</b>\"" + newline + "duh() ::= <<" + newline + "xx" + newline + ">>" + newline; StringTemplateGroup group = new StringTemplateGroup( new StringReader( templates ), typeof( DefaultTemplateLexer ) ); string expecting = "group test;" + newline + "bold(item) ::= <<<b>$item$</b>>>" + newline + "duh() ::= <<xx>>" + newline + "t() ::= <<literal template>>" + newline; Assert.AreEqual( expecting, group.ToString() ); StringTemplate a = group.GetInstanceOf( "t" ); expecting = "literal template"; Assert.AreEqual( expecting, a.ToString() ); StringTemplate b = group.GetInstanceOf( "bold" ); b.SetAttribute( "item", "dork" ); expecting = "<b>dork</b>"; Assert.AreEqual( expecting, b.ToString() ); }
public void TestEscapedTemplateDelimiters() { string templates = "group test;" + newline + "t() ::= <<$\"literal\":{a|$a$\\}}$ template\n>>" + newline + "bold(item) ::= <<<b>$item$</b\\>>>" + newline + "duh() ::= <<" + newline + "xx" + newline + ">>" + newline; StringTemplateGroup group = new StringTemplateGroup( new StringReader( templates ), typeof( DefaultTemplateLexer ) ); string expecting = "group test;" + newline + "bold(item) ::= <<<b>$item$</b>>>" + newline + "duh() ::= <<xx>>" + newline + "t() ::= <<$\"literal\":{a|$a$\\}}$ template>>" + newline; Assert.AreEqual( expecting, group.ToString() ); StringTemplate b = group.GetInstanceOf( "bold" ); b.SetAttribute( "item", "dork" ); expecting = "<b>dork</b>"; Assert.AreEqual( expecting, b.ToString() ); StringTemplate a = group.GetInstanceOf( "t" ); expecting = "literal} template"; Assert.AreEqual( expecting, a.ToString() ); }