public void TestIndirectProp() { String template = "<u.(propname)>: <u.name>"; ST st = new ST(template); st.Add("u", new TestCoreBasics.User(1, "parrt")); st.Add("propname", "id"); String expected = "1: parrt"; String result = st.Render(); Assert.AreEqual(expected, result); }
public void TestAttrIsArray() { string template = "hi <name>!"; Template st = new Template(template); string[] names = new string[] { "Ter", "Tom" }; st.Add("name", names); st.Add("name", "Sumana"); // shouldn't alter my version of names list! string expected = "hi TerTomSumana!"; // ST sees 3 names string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestCatListAndSingleAttribute() { // replace first of yours with first of mine Template e = new Template( "<[mine,yours]; separator=\", \">" ); e.Add("mine", "1"); e.Add("mine", "2"); e.Add("mine", "3"); e.Add("yours", "a"); string expecting = "1, 2, 3, a"; Assert.AreEqual(expecting, e.Render()); }
public void TestAttrIsList() { string template = "hi <name>!"; Template st = new Template(template); var names = new ArrayList() { "Ter", "Tom" }; st.Add("name", names); st.Add("name", "Sumana"); // shouldn't alter my version of names list! string expected = "hi TerTomSumana!"; // ST sees 3 names string result = st.Render(); Assert.AreEqual(expected, result); Assert.IsTrue(names.Count == 2); // my names list is still just 2 }
public void TestCatListAndEmptyAttributes() { // + is overloaded to be cat strings and cat lists so the // two operands (from left to right) determine which way it // goes. In this case, x+mine is a list so everything from their // to the right becomes list cat. Template e = new Template( "<[x,mine,y,yours,z]; separator=\", \">" ); e.Add("mine", "1"); e.Add("mine", "2"); e.Add("mine", "3"); e.Add("yours", "a"); string expecting = "1, 2, 3, a"; Assert.AreEqual(expecting, e.Render()); }
public void TestIFInSubtemplate() { Template t = new Template( "<names:{n |" + newline + " <if(x)>" + newline + " <x>" + newline + " <else>" + newline + " <y>" + newline + " <endif>" + newline + "}>" + newline); t.Add("names", "Ter"); t.Add("y", "y"); String expecting = " y" + newline + newline; String result = t.Render(); Assert.AreEqual(expecting, result); }
public void TestEarlyEval() { String template = "<(name)>"; ST st = new ST(template); st.Add("name", "Ter"); String expected = "Ter"; String result = st.Render(); Assert.AreEqual(expected, result); }
public void TestAndNot() { string template = "<if(name&&!notThere)>works<else>fail<endif>"; Template st = new Template(template); st.Add("name", "Ter"); string expected = "works"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestAttr() { string template = "hi <name>!"; Template st = new Template(template); st.Add("name", "Ter"); string expected = "hi Ter!"; string result = st.Render(); st.code.Dump(); Assert.AreEqual(expected, result); }
public void TestIFWithIndentAndExprOnMultipleLines() { Template t = new Template( "begin" + newline + " <if(x)>" + newline + " <x>" + newline + " <else>" + newline + " <y>" + newline + " <endif>" + newline + "end" + newline); t.Add("y", "y"); String expecting = "begin" + newline + " y" + newline + "end" + newline; String result = t.Render(); Assert.AreEqual(expecting, result); }
public void TestParallelAttributeIteration() { ST e = new ST( "<names,phones,salaries:{n,p,s | <n>@<p>: <s>\n}>" ); e.Add("names", "Ter"); e.Add("names", "Tom"); e.Add("phones", "1"); e.Add("phones", "2"); e.Add("salaries", "big"); e.Add("salaries", "huge"); String expecting = "Ter@1: big" + newline + "Tom@2: huge" + newline; Assert.AreEqual(expecting, e.Render()); }
public void TestRestWithOneAttributeOp() { Template e = new Template( "<rest(names)>" ); e.Add("names", "Ter"); string expecting = ""; Assert.AreEqual(expecting, e.Render()); }
public void TestNonStringDictLookup() { String template = "<m.(intkey)>"; ST st = new ST(template); IDictionary<int, string> m = new Dictionary<int, String>(); m[36] = "foo"; st.Add("m", m); st.Add("intkey", 36); String expected = "foo"; String result = st.Render(); Assert.AreEqual(expected, result); }
public void TestCombinedOp() { // replace first of yours with first of mine Template e = new Template( "<[first(mine),rest(yours)]; separator=\", \">" ); e.Add("mine", "1"); e.Add("mine", "2"); e.Add("mine", "3"); e.Add("yours", "a"); e.Add("yours", "b"); string expecting = "1, b"; Assert.AreEqual(expecting, e.Render()); }
public void TestLastWithLengthOneListAttributeOp() { Template e = new Template( "<last(names)>" ); e.Add("names", new ArrayList() { "Ter" }); string expecting = "Ter"; Assert.AreEqual(expecting, e.Render()); }
public void TestTruncOp() { Template e = new Template( "<trunc(names); separator=\", \">" ); e.Add("names", "Ter"); e.Add("names", "Tom"); e.Add("names", "Sriram"); string expecting = "Ter, Tom"; Assert.AreEqual(expecting, e.Render()); }
public void TestParallelAttributeIterationWithMissingArgs() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; Template e = new Template( "<names,phones,salaries:{<n>@<p>}; separator=\", \">" ); e.Add("names", "Tom"); e.Add("phones", "2"); e.Add("salaries", "big"); e.Render(); // generate the error string errorExpecting = "context [anonymous] 1:1 missing argument definitions" + newline; Assert.AreEqual(errorExpecting, errors.ToString()); }
public void TestParallelAttributeIterationWithNullValue() { ST e = new ST( "<names,phones,salaries:{n,p,s | <n>@<p>: <s>\n}>" ); e.Add("names", "Ter"); e.Add("names", "Tom"); e.Add("names", "Sriram"); e.Add("phones", new object[] { "1", null, "3" }); e.Add("salaries", "big"); e.Add("salaries", "huge"); e.Add("salaries", "enormous"); String expecting = "Ter@1: big"+newline+ "Tom@: huge"+newline+ "Sriram@3: enormous"+newline; Assert.AreEqual(expecting, e.Render()); }
public void TestLength() { string template = "<length(names)>"; Template st = new Template(template); var names = new ArrayList() { "Ter", "Tom" }; st.Add("names", names); string expected = "2"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestRestOpEmptyList() { Template e = new Template( "<rest(names); separator=\", \">" ); e.Add("names", new ArrayList()); string expecting = ""; Assert.AreEqual(expecting, e.Render()); }
public void TestRepeatedRestOp() { Template e = new Template( "<rest(names)>, <rest(names)>" // gets 2nd element ); e.Add("names", "Ter"); e.Add("names", "Tom"); string expecting = "Tom, Tom"; Assert.AreEqual(expecting, e.Render()); }
public void TestNestedOp() { Template e = new Template( "<first(rest(names))>" // gets 2nd element ); e.Add("names", "Ter"); e.Add("names", "Tom"); e.Add("names", "Sriram"); string expecting = "Tom"; Assert.AreEqual(expecting, e.Render()); }
public void TestParallelAttributeIterationWithDifferentSizes() { ST e = new ST( "<names,phones,salaries:{n,p,s | <n>@<p>: <s>}; separator=\", \">" ); e.Add("names", "Ter"); e.Add("names", "Tom"); e.Add("names", "Sriram"); e.Add("phones", "1"); e.Add("phones", "2"); e.Add("salaries", "big"); String expecting = "Ter@1: big, Tom@2: , Sriram@: "; Assert.AreEqual(expecting, e.Render()); }
public void TestReverse() { Template e = new Template( "<reverse(names); separator=\", \">" ); e.Add("names", "Ter"); e.Add("names", "Tom"); e.Add("names", "Sriram"); string expecting = "Sriram, Tom, Ter"; Assert.AreEqual(expecting, e.Render()); }
public void TestParallelAttributeIterationWithSingletons() { ST e = new ST( "<names,phones,salaries:{n,p,s | <n>@<p>: <s>}; separator=\", \">" ); e.Add("names", "Ter"); e.Add("phones", "1"); e.Add("salaries", "big"); String expecting = "Ter@1: big"; Assert.AreEqual(expecting, e.Render()); }
public void TestStripOp() { var e = new Template( "<strip(names); null=\"n/a\">" ); e.Add("names", null); e.Add("names", "Tom"); e.Add("names", null); e.Add("names", null); e.Add("names", "Sriram"); e.Add("names", null); string expecting = "TomSriram"; Assert.AreEqual(expecting, e.Render()); }
public void TestParallelAttributeIterationWithMismatchArgListSizes() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; Template e = new Template( "<names,phones,salaries:{n,p | <n>@<p>}; separator=\", \">" ); e.Add("names", "Ter"); e.Add("names", "Tom"); e.Add("phones", "1"); e.Add("phones", "2"); e.Add("salaries", "big"); e.Render(); string errorExpecting = "context [anonymous] 1:1 iterating through 3 arguments but parallel map has 2 formal arguments" + newline; Assert.AreEqual(errorExpecting, errors.ToString()); string expecting = "Ter@1, Tom@2"; Assert.AreEqual(expecting, e.Render()); }
public void TestStrlen() { Template e = new Template( "<strlen(name)>" ); e.Add("name", "012345"); string expecting = "6"; Assert.AreEqual(expecting, e.Render()); }
public void TestStringTypeMismatch2() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; ST e = new ST("<strlen(s)>"); e.Add("s", 34); e.Render(); // generate the error String errorExpecting = "context [anonymous] 1:1 function strlen expects a string not System.Int32" + newline; Assert.AreEqual(errorExpecting, errors.ToString()); }
public void TestTrim() { Template e = new Template( "<trim(name)>" ); e.Add("name", " Ter \n"); string expecting = "Ter"; Assert.AreEqual(expecting, e.Render()); }