public void Url_noargs() { string tt = "{% url 'noargs_url' %}"; TemplateEngine te = new TemplateEngine (tt); Assert.Equal ("/page/", te.Render (null)); }
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)); }
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)); }
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)); }
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 void Url_posArgUrl() { string tt = "{% url 'pos_arg_url' 7 %}"; TemplateEngine te = new TemplateEngine (tt); Assert.Equal ("/page/7/", te.Render (null)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }