Пример #1
0
 public void TestNestedIterationWithArg()
 {
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("test"), "<users:{u | <u.id:{id | <id>=}><u.name>}>!");
     ST st = group.GetInstanceOf("test");
     st.Add("users", new TestCoreBasics.User(1, "parrt"));
     st.Add("users", new TestCoreBasics.User(2, "tombu"));
     st.Add("users", new TestCoreBasics.User(3, "sri"));
     String expected = "1=parrt2=tombu3=sri!";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #2
0
 public void TestAttrSeparator()
 {
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("test"), "hi <name; separator=sep>!");
     ST st = group.GetInstanceOf("test");
     st.Add("sep", ", ");
     st.Add("name", "Ter");
     st.Add("name", "Tom");
     st.Add("name", "Sumana");
     String expected = "hi Ter, Tom, Sumana!";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #3
0
 public void TestIllegalOption()
 {
     ErrorBuffer errors = new ErrorBuffer();
     ErrorManager.ErrorListener = errors;
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("test"), "<name; bad=\"ugly\">");
     ST st = group.GetInstanceOf("test");
     st.Add("name", "Ter");
     String expected = "Ter";
     String result = st.Render();
     Assert.AreEqual(expected, result);
     expected = "1:7: no such option: bad" + newline;
     Assert.AreEqual(expected, errors.ToString());
 }
 public void TestIndirectMap()
 {
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("a"), "[<it>]");
     group.DefineTemplate(new TemplateName("test"), "hi <names:(templateName)()>!");
     ST st = group.GetInstanceOf("test");
     st.Add("names", "Ter");
     st.Add("names", "Tom");
     st.Add("names", "Sumana");
     st.Add("templateName", "a");
     String expected =
         "hi [Ter][Tom][Sumana]!";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #5
0
 public void TestSeparatorWithNullFirstValueAndNullOption()
 {
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("test"), "hi <name; null=\"n/a\", separator=\", \">!");
     ST st = group.GetInstanceOf("test");
     st.Add("name", null);
     st.Add("name", "Tom");
     st.Add("name", "Sumana");
     String expected = "hi n/a, Tom, Sumana!";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #6
0
 public void TestOptionDoesntApplyToNestedTemplate()
 {
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("foo"), "<zippo>");
     group.DefineTemplate(new TemplateName("test"), "<foo(); null=\"n/a\">");
     ST st = group.GetInstanceOf("test");
     st.Add("zippo", null);
     String expected = "";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #7
0
 public void Test_it_NotDefinedWithArgSingleValue()
 {
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("test"), "<names:{n | <it>}>!");
     ST st = group.GetInstanceOf("test");
     st.Add("names", "Ter");
     String expected = "!";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #8
0
 public void TestSimpleIterationWithArg()
 {
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("test"), "<names:{n | <n>}>!");
     ST st = group.GetInstanceOf("test");
     st.Add("names", "Ter");
     st.Add("names", "Tom");
     st.Add("names", "Sumana");
     String expected = "TerTomSumana!";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #9
0
 public void TestITDoesntPropagate()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate(new TemplateName("foo"), "<it>");   // <it> not visible
     string template = "<names:{<foo()>}>"; // <it> visible only to {...} here
     group.DefineTemplate(new TemplateName("test"), template);
     Template st = group.GetInstanceOf("test");
     st.Add("names", "Ter");
     st.Add("names", "Tom");
     string expected = "";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #10
0
 public void TestTrimNewlineInSubtemplates()
 {
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("test"), "<names:{n |\n" +
                                  "<n>}>!");
     ST st = group.GetInstanceOf("test");
     st.Add("names", "Ter");
     st.Add("names", "Tom");
     st.Add("names", "Sumana");
     String expected = "TerTomSumana!";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #11
0
 public void TestRoundRobinMap()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate(new TemplateName("a"), "[<it>]");
     group.DefineTemplate(new TemplateName("b"), "(<it>)");
     group.DefineTemplate(new TemplateName("test"), "hi <name:a(),b()>!");
     Template st = group.GetInstanceOf("test");
     st.Add("name", "Ter");
     st.Add("name", "Tom");
     st.Add("name", "Sumana");
     string expected =
         "hi [Ter](Tom)[Sumana]!";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #12
0
 public void TestParallelMapWith3Versus2Elements()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate(new TemplateName("test"), "hi <names,phones:{n,p | <n>:<p>;}>");
     Template st = group.GetInstanceOf("test");
     st.Add("names", "Ter");
     st.Add("names", "Tom");
     st.Add("names", "Sumana");
     st.Add("phones", "x5001");
     st.Add("phones", "x5002");
     string expected =
         "hi Ter:x5001;Tom:x5002;Sumana:;";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #13
0
 public void TestMapSingleValue()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate(new TemplateName("a"), "[<it>]");
     group.DefineTemplate(new TemplateName("test"), "hi <name:a()>!");
     Template st = group.GetInstanceOf("test");
     st.Add("name", "Ter");
     string expected = "hi [Ter]!";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #14
0
 public void TestMapIndexes()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate(new TemplateName("inc"), "<i>:<it>");
     group.DefineTemplate(new TemplateName("test"), "<name:inc(); separator=\", \">");
     Template st = group.GetInstanceOf("test");
     st.Add("name", "Ter");
     st.Add("name", "Tom");
     st.Add("name", null); // don't count this one
     st.Add("name", "Sumana");
     string expected =
         "1:Ter, 2:Tom, 3:Sumana";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #15
0
 public void TestMap()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate(new TemplateName("inc"), "[<it>]");
     group.DefineTemplate(new TemplateName("test"), "hi <name:inc()>!");
     Template st = group.GetInstanceOf("test");
     st.Add("name", "Ter");
     st.Add("name", "Tom");
     st.Add("name", "Sumana");
     string expected =
         "hi [Ter][Tom][Sumana]!";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
 public void TestIndirectTemplateInclude()
 {
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("foo"), "bar");
     String template = "<(name)()>";
     group.DefineTemplate(new TemplateName("test"), template);
     ST st = group.GetInstanceOf("test");
     st.Add("name", "foo");
     String expected = "bar";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #17
0
 public void TestMissingValueAndNullOption()
 {
     STGroup group = new STGroup();
     group.DefineTemplate(new TemplateName("test"), "<name; null=\"n/a\">");
     ST st = group.GetInstanceOf("test");
     String expected = "n/a";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Пример #18
0
 public void TestDefineTemplate()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate(new TemplateName("inc"), "<it>+1");
     group.DefineTemplate(new TemplateName("test"), "hi <name>!");
     Template st = group.GetInstanceOf("test");
     st.Add("name", "Ter");
     st.Add("name", "Tom");
     st.Add("name", "Sumana");
     string expected =
         "hi TerTomSumana!";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }