Esempio n. 1
0
 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());
     }
 }
Esempio n. 2
0
 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());
         }
     }
 }
Esempio n. 3
0
 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());
         }
     }
 }
Esempio n. 4
0
 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());
         }
     }
 }
Esempio n. 5
0
 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());
         }
     }
 }
Esempio n. 6
0
 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());
         }
     }
 }
Esempio n. 7
0
 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());
         }
     }
 }
Esempio n. 8
0
        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());
                }
            }
        }
Esempio n. 9
0
 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());
     }
 }
Esempio n. 10
0
 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());
     }
 }
Esempio n. 11
0
 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());
     }
 }
Esempio n. 12
0
 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());
         }
     }
 }
Esempio n. 13
0
 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());
         }
     }
 }
Esempio n. 14
0
 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());
         }
     }
 }
Esempio n. 15
0
 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());
         }
     }
 }
Esempio n. 16
0
 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());
         }
     }
 }
Esempio n. 17
0
 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());
     }
 }
Esempio n. 18
0
 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());
     }
 }
Esempio n. 19
0
 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());
         }
     }
 }
Esempio n. 20
0
 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());
     }
 }
Esempio n. 21
0
 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());
     }
 }
Esempio n. 22
0
        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());
                }
            }
        }
Esempio n. 23
0
 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());
         }
     }
 }