public void TestThree() { using (var template = new Template(new CSharp(), "{%for(int i = 0; i < 5; i++){%}{%=i%}{%}%}", new String[0])) using (var output = new StringWriter()) { template.Render(output); Assert.AreEqual("01234", output.ToString()); } }
public void TestEmptyText() { using (Template template = new Template(new Java(), "", new string[0])) { using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("", output.ToString()); } } }
public void TestPlainText() { using (Template template = new Template(new Python(), "abcd", new string[0])) { using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("abcd", output.ToString()); } } }
public void TestArithmeticalExpression() { using (Template template = new Template(new Python(), "{%=-1+3%}abcd{%=3*3+2%}", new string[0])) { using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("2abcd11", output.ToString()); } } }
public void TestIfTag() { using (Template template = new Template(new Python(), "{%? 2 < 3 %}true{%?%}", new string[0])) { using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("true", output.ToString()); } } }
public void TestForTag() { using (Template template = new Template(new Python(), "{%@3%}!{%@%}", new string[0])) { using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("!!!", output.ToString()); } } }
public void TestIfTagWithExpression() { using (Template template = new Template(new Python(), @"{%? s == ""TEST"") %}true{%?%}", new string[0], new Variable("s", ArgumentType.String))) { using (TextWriter output = new StringWriter()) { template.Render(output, "TEST"); Assert.AreEqual("true", output.ToString()); } } }
public void TestIfTagWithDateTime() { using (Template template = new Template(new Java(), @"{%? date.get(Calendar.YEAR) == 2016 %}true{%?%}", new string[] { "java.util.Calendar" }, new Variable("date", ArgumentType.DateTime))) { using (TextWriter output = new StringWriter()) { template.Render(output, DateTime.Now); Assert.AreEqual("true", output.ToString()); } } }
public void TestTemplateFormatException() { using (Template template = new Template(new CSharp(), "{%=Math.Sqrtt(49)+4%}", new string[] { "System" })) using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("11", output.ToString()); } }
public void TestMathExpressionWithAddNamespace() { using (Template template = new Template(new CSharp(), "{%=Math.Sqrt(49)+4%}", new string[] { "System" })) using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("11", output.ToString()); } }
public void TestMathExpressionWithAddNamespace() { using (Template template = new Template(new Python(), "{%=math.sqrt(49)+4%}", new string[0])) using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("11", output.ToString()); } }
public void TestUnicode() { var buffer = new StringBuilder(); for (int i = char.MinValue; i <= char.MaxValue; i++) buffer.Append((char)i); var text = string.Join("", Enumerable.Repeat(buffer.ToString(), 16)); using (Template template = new Template(new Python(), text, new string[0])) { using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual(text, output.ToString()); } } }
public void TestTextAtBegin() { using (Template template = new Template(new Python(), @"abcd{%@5%}*{%@%}", new string[0])) { using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("abcd*****", output.ToString()); } } }
public void TestTextAtEnd() { using (Template template = new Template(new Python(), @"{%@4%}!{%@%}abcd", new string[0])) { using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("!!!!abcd", output.ToString()); } } }
public void TestOneMoreNestedFor() { using (Template template = new Template(new Python(), "{%@n%}{%@m*2%}1{%@%}2{%@k+1%}3{%@%}{%@%}", new string[0], new Variable("n", ArgumentType.Integer), new Variable("m", ArgumentType.Integer), new Variable("k", ArgumentType.Integer))) { using (TextWriter output = new StringWriter()) { template.Render(output, 2, 2, 1); Assert.AreEqual("11112331111233", output.ToString()); } } }
public void TestIfAndNestedFor() { using (Template template = new Template(new Python(), @"{%=-1+3%}abcd{%?s == ""TEST""%}abcd{%?%}{%@2%}{%=1+3%}{%@3%}{%@3%}*{%@%}@{%@%}{%@%}asd{%@4%}*{%@%}abcd", new string[0], new Variable("s", ArgumentType.String))) { using (TextWriter output = new StringWriter()) { template.Render(output, "TEST"); Assert.AreEqual("2abcdabcd4***@***@***@4***@***@***@asd****abcd", output.ToString()); } } }
public void TestTemplateRuntimeException() { using (Template template = new Template(new CSharp(), "{% String a = null; a.ToString(); %}", new string[] { "System" })) using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("", output.ToString()); } }
public void TestRussianPlainText() { using (Template template = new Template(new Java(), "текст123", new string[0])) using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("текст123", output.ToString()); } }
public void TestWithNoClosedBracket() { using (Template template = new Template(new Java(), "{%@n+1%}*{%@n+m%}{%@3%}!{%@%}{%@%}", new string[0], new Variable("n", ArgumentType.Integer), new Variable("m", ArgumentType.Integer))) { using (var output = new StringWriter()) { template.Render(output, 2, 2); Assert.AreEqual("*!!!!!!!!!!!!*!!!!!!!!!!!!*!!!!!!!!!!!!", output.ToString()); } } }
public void TestTemplateFormatException() { string[] namespaces = new string[1]; namespaces[0] = "System"; using (Template template = new Template(new Java(), "{%=Math.Sqrtt(49)+4%}", namespaces)) using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("11", output.ToString()); } }
public void TestMathExpressionWithAddNamespace() { using (Template template = new Template(new Java(), "{%=Math.sqrt(49)+4%}", new string[] { "java.lang.Math" })) using (TextWriter output = new StringWriter()) { template.Render(output); Assert.AreEqual("11.0", output.ToString()); } }
public void TestIfTagWithDateTime() { using (Template template = new Template(new Python(), @"{%? date.year == 2016 %}true{%?%}", new string[0], new Variable("date", ArgumentType.DateTime))) { using (TextWriter output = new StringWriter()) { template.Render(output, DateTime.Now); Assert.AreEqual("true", output.ToString()); } } }
public void TestNestedFor() { using (Template template = new Template(new Python(), "{%@n+1%}<{%@n+m%}!{%@%}>{%@%}", new string[0], new Variable("n", ArgumentType.Integer), new Variable("m", ArgumentType.Integer))) { using (TextWriter output = new StringWriter()) { template.Render(output, 2, 2); Assert.AreEqual("<!!!!><!!!!><!!!!>", output.ToString()); } } }