示例#1
0
        public void Url_noargs()
        {
            string tt = "{% url 'noargs_url' %}";
            TemplateEngine te = new TemplateEngine (tt);

            Assert.Equal ("/page/", te.Render (null));
        }
示例#2
0
        public void Url_namedArgUrl()
        {
            string tt = "{% url 'named_arg_url' page_num=7 %}";
            TemplateEngine te = new TemplateEngine (tt);

            Assert.Equal ("/page/7/", te.Render (null));
        }
示例#3
0
        public void Url_namedAndPosArgUrl()
        {
            string tt = "{% url 'named_and_pos_arg_url' product_name=product 7 %}";
            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();
            tc ["product"] = "badr";

            Assert.Equal ("/badr/page/7/", te.Render (tc));
        }
示例#4
0
        public void ForTag_in()
        {
            string tt = "{% for a in list %}{{ a }}, {% endfor %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext ();
            tc ["list"] = new int[]{1, 2, 3, 4, 5, 6, 7 ,8, 9 };

            Assert.Equal ("1, 2, 3, 4, 5, 6, 7, 8, 9, ", te.Render (tc));
        }
示例#5
0
        public void IfTag_andNot()
        {
            string tt = "{% if a < 10 and not a = 5 %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();

            tc ["a"] = 3;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = -7;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 5;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = 19;
            Assert.Equal ("false", te.Render (tc));
        }
示例#6
0
        public void IfTag_and()
        {
            string tt = "{% if a < 10 and a > -2 and a in list %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();
            tc ["list"] = new double[]{-11.7, -7, -1, 3, 5, 81};

            tc ["a"] = 3;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = -1;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 9;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = 81;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = -11.7;
            Assert.Equal ("false", te.Render (tc));
        }
 public TemplateException(string message, TemplateEngine templateEngine, Exception innerException = null)
     : base(message, innerException)
 {
     TemplateEngine = templateEngine;
 }
示例#8
0
        public void Url_posArgUrl()
        {
            string tt = "{% url 'pos_arg_url' 7 %}";
            TemplateEngine te = new TemplateEngine (tt);

            Assert.Equal ("/page/7/", te.Render (null));
        }
示例#9
0
        public void IfTag_or()
        {
            string tt = "{% if a = 1 or a < -50 or a in list %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();
            tc ["list"] = new double[]{-11.7, -7, -1, 3, 5, 81};

            tc ["a"] = 1;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 81;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 7;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = -2;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = -71.7;
            Assert.Equal ("true", te.Render (tc));
        }
示例#10
0
        public void IfTag_notIn()
        {
            string tt = "{% if a not in b %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext ();
            tc ["a"] = 2;
            tc ["b"] = new int[]{1, 3, 7};
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 1;
            Assert.Equal ("false", te.Render (tc));
        }
示例#11
0
        public void IfTag_noRhs()
        {
            string tt = "{% if a %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();

            tc ["a"] = true;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 0;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = null;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = false;
            Assert.Equal ("false", te.Render (tc));
        }
示例#12
0
        public void IfTag_lessThan()
        {
            string tt = "{% if a < b %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext ();
            tc ["a"] = 1;
            tc ["b"] = 1;
            Assert.Equal ("false", te.Render (tc));

            tc ["b"] = 2;
            Assert.Equal ("true", te.Render (tc));
        }
示例#13
0
        public void IfTag_and_or_mix()
        {
            string tt = "{% if a < 10 and not a = 5 or a > 10 and a < 20 and not a = 15 or a = 27 %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();

            tc ["a"] = 3;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 17;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 27;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = -77;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 5;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = 15;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = 77;
            Assert.Equal ("false", te.Render (tc));
        }