示例#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 TestEmptyExpr2()
 {
     String template = "hi <> ";
     TemplateGroup group = new TemplateGroup();
     String result = null;
     try
     {
         group.DefineTemplate(new TemplateName("test"), template);
     }
     catch (TemplateException se)
     {
         RecognitionException re = (RecognitionException)se.InnerException;
         result = new TemplateSyntaxErrorMessage(ErrorType.SyntaxError, re.Token, re, se.Message).ToString();
     }
     String expected = "1:3: doesn't look like an expression";
     Assert.AreEqual(expected, result);
 }
示例#6
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);
 }
 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);
 }
示例#8
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);
 }
示例#9
0
 //: this(TemplateGroup.defaultGroup, template)
 public Template(string template)
 {
     //code = TemplateGroup.defaultGroup.DefineTemplate(UnknownName, template);
     groupThatCreatedThisInstance = TemplateGroup.defaultGroup;
     code = groupThatCreatedThisInstance.Compile(TemplateName.Root, null, template);
     code.Name = UnknownName;
     groupThatCreatedThisInstance.DefineImplicitlyDefinedTemplates(code);
 }
示例#10
0
 public void TestRendererWithFormatAndSeparatorAndNull()
 {
     string template =
             "The names: <names; separator=\" and \", null=\"n/a\", format=\"upper\">";
     TemplateGroup group = new TemplateGroup();
     group.RegisterRenderer(typeof(string), new StringRenderer());
     Template st = new Template(template);
     st.groupThatCreatedThisInstance = group;
     IList names = new ArrayList();
     names.Add("ter");
     names.Add(null);
     names.Add("sriram");
     st.Add("names", names);
     string expecting = "The names: TER and N/A and SRIRAM";
     string result = st.Render();
     Assert.AreEqual(expecting, result);
 }
示例#11
0
        /// <summary>
        /// Make this group import templates/dictionaries from <paramref name="g"/>.
        /// </summary>
        public virtual void ImportTemplates(TemplateGroup g)
        {
            if (g == null)
                return;

            if (imports == null)
                imports = new List<TemplateGroup>();

            imports.Add(g);
        }
示例#12
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);
 }
示例#13
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);
 }
示例#14
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);
 }
示例#15
0
 public void TestWeirdChar()
 {
     string template = "   <*>";
     TemplateGroup group = new TemplateGroup();
     string result = null;
     try
     {
         group.DefineTemplate(new TemplateName("test"), template);
     }
     catch (TemplateException se)
     {
         RecognitionException re = (RecognitionException)se.InnerException;
         result = new TemplateSyntaxErrorMessage(ErrorType.SyntaxError, re.Token, re, se.Message).ToString();
     }
     string expected = "1:4: invalid character: *";
     Assert.AreEqual(expected, result);
 }
示例#16
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);
 }
示例#17
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);
 }
示例#18
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);
 }
示例#19
0
 public void TestRendererWithFormatAndList()
 {
     string template =
             "The names: <names; format=\"upper\">";
     TemplateGroup group = new TemplateGroup();
     group.RegisterRenderer(typeof(string), new StringRenderer());
     Template st = new Template(template);
     st.groupThatCreatedThisInstance = group;
     st.Add("names", "ter");
     st.Add("names", "tom");
     st.Add("names", "sriram");
     string expecting = "The names: TERTOMSRIRAM";
     string result = st.Render();
     Assert.AreEqual(expecting, result);
 }
示例#20
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);
 }
示例#21
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);
 }
示例#22
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);
 }
示例#23
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);
 }
示例#24
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);
 }
示例#25
0
 public Template(TemplateGroup nativeGroup, string template)
 {
     code = nativeGroup.DefineTemplate(UnknownName, template);
     groupThatCreatedThisInstance = nativeGroup;
 }