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); }
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); }
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); }
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); }
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); }
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); }
//: 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); }
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); }
/// <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); }
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 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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public Template(TemplateGroup nativeGroup, string template) { code = nativeGroup.DefineTemplate(UnknownName, template); groupThatCreatedThisInstance = nativeGroup; }