public virtual void testMissingEndDelimiter()
 {
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplateErrorListener errors = new ErrorBuffer();
     group.setErrorListener(errors);
     StringTemplate t = new StringTemplate(group, "stuff $a then more junk etc...");
     String expectingError = "problem parsing template 'anonymous': line 1:31: expecting '$', found '<EOF>'";
     //System.out.println("error: '"+errors+"'");
     //System.out.println("expecting: '"+expectingError+"'");
     Assert.AreEqual(errors.ToString(), expectingError);
 }
 public virtual void testMultiLevelInheritance()
 {
     // must loop up two levels to find bold()
     StringTemplateGroup rootgroup = new StringTemplateGroup("root");
     StringTemplateGroup level1 = new StringTemplateGroup("level1");
     StringTemplateGroup level2 = new StringTemplateGroup("level2");
     rootgroup.defineTemplate("bold", "<b>$it$</b>");
     level1.setSuperGroup(rootgroup);
     level2.setSuperGroup(level1);
     StringTemplateErrorListener errors = new ErrorBuffer();
     rootgroup.setErrorListener(errors);
     level1.setErrorListener(errors);
     level2.setErrorListener(errors);
     StringTemplate duh = new StringTemplate(level2, "$name:bold()$");
     duh.setAttribute("name", "Terence");
     String expecting = "<b>Terence</b>";
     Assert.AreEqual(duh.ToString(), expecting);
 }
 public virtual void testEmptyIteratedConditionalWithElseValueGetsSeparator()
 {
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplateErrorListener errors = new ErrorBuffer();
     group.setErrorListener(errors);
     StringTemplate t = new StringTemplate(group, "$users:{$if(it.ok)$$it.name$$else$$endif$}; separator=\",\"$");
     t.setAttribute("users.{name,ok}", "Terence", true);
     t.setAttribute("users.{name,ok}", "Tom", false);
     t.setAttribute("users.{name,ok}", "Frank", true);
     t.setAttribute("users.{name,ok}", "Johnny", false);
     // empty conditional values get no separator
     String expecting = "Terence,,Frank,"; // haven't solved the last empty value problem yet
     String result = t.ToString();
     Assert.AreEqual(result, expecting);
 }
 public virtual void testEmptyIteratedValueGetsSeparator()
 {
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplateErrorListener errors = new ErrorBuffer();
     group.setErrorListener(errors);
     StringTemplate t = new StringTemplate(group, "$names; separator=\",\"$");
     t.setAttribute("names", "Terence");
     t.setAttribute("names", "");
     t.setAttribute("names", "");
     t.setAttribute("names", "Tom");
     t.setAttribute("names", "Frank");
     t.setAttribute("names", "");
     // empty values get separator still
     String expecting = "Terence,,,Tom,Frank,";
     String result = t.ToString();
     Assert.AreEqual(result, expecting);
 }
 public virtual void testSizeZeroOnLineWithIndentGetsNoOutput()
 {
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplateErrorListener errors = new ErrorBuffer();
     group.setErrorListener(errors);
     StringTemplate t = new StringTemplate(group, "begin\n" + "  $name$\n" + "	$users:{name: $it$}$\n" + "	$users:{name: $it$$\\n$}$\n" + "end\n");
     String expecting = "begin\nend\n";
     String result = t.ToString();
     Assert.AreEqual(result, expecting);
 }
 public virtual void testSizeZeroButNonNullListGetsNoOutput()
 {
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplateErrorListener errors = new ErrorBuffer();
     group.setErrorListener(errors);
     StringTemplate t = new StringTemplate(group, "$duh.users:{name: $it$}; separator=\", \"$");
     t.setAttribute("duh", new Duh());
     String expecting = "";
     String result = t.ToString();
     Assert.AreEqual(result, expecting);
 }
 public virtual void testSimpleInheritance()
 {
     // make a bold template in the super group that you can inherit from sub
     StringTemplateGroup supergroup = new StringTemplateGroup("super");
     StringTemplateGroup subgroup = new StringTemplateGroup("sub");
     StringTemplate bold = supergroup.defineTemplate("bold", "<b>$it$</b>");
     subgroup.setSuperGroup(supergroup);
     StringTemplateErrorListener errors = new ErrorBuffer();
     subgroup.setErrorListener(errors);
     supergroup.setErrorListener(errors);
     StringTemplate duh = new StringTemplate(subgroup, "$name:bold()$");
     duh.setAttribute("name", "Terence");
     String expecting = "<b>Terence</b>";
     Assert.AreEqual(duh.ToString(), expecting);
 }
 public virtual void testSetButNotRefd()
 {
     StringTemplate.setLintMode(true);
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplate t = new StringTemplate(group, "$a$ then $b$ and $c$ refs.");
     t.setAttribute("a", "Terence");
     t.setAttribute("b", "Terence");
     t.setAttribute("cc", "Terence"); // oops...should be 'c'
     String newline = System.Environment.NewLine;
     StringTemplateErrorListener errors = new ErrorBuffer();
     group.setErrorListener(errors);
     String expectingError = "anonymous: set but not used: cc";
     String result = t.ToString(); // result is irrelevant
     //System.out.println("result error: '"+errors+"'");
     //System.out.println("expecting: '"+expectingError+"'");
     StringTemplate.setLintMode(false);
     Assert.AreEqual(errors.ToString(), expectingError);
 }
 public virtual void testNullTemplateToMultiValuedApplication()
 {
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplateErrorListener errors = new ErrorBuffer();
     group.setErrorListener(errors);
     StringTemplate t = new StringTemplate(group, "$names:bold(x=it)$");
     t.setAttribute("names", "Terence");
     t.setAttribute("names", "Tom");
     //System.out.println(t);
     String expecting = null; // bold not found...empty string
     String result = null;
     String error = null;
     try
     {
         result = t.ToString();
     }
     catch (System.ArgumentException iae)
     {
         error = iae.Message;
     }
     Assert.AreEqual(error, "Can't load template bold.st");
 }