public void TestOutputInRaw() { Helper.AssertTemplateResult("<< test >>", "{% raw %}<< test >>{% endraw %}"); }
public void TestForReversed() { Hash assigns = Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3 } }); Helper.AssertTemplateResult("321", "{%for item in array reversed %}{{item}}{%endfor%}", assigns); }
public void TestRawAndFollowing() { Helper.AssertTemplateResult("{{ test }}65", "{% raw %}{{ test }}{% endraw %}6{{ 5 }}"); }
public void TestMultipleCycles() { Helper.AssertTemplateResult("1 2 1 1 2 3 1", "{%cycle 1,2%} {%cycle 1,2%} {%cycle 1,2%} {%cycle 1,2,3%} {%cycle 1,2,3%} {%cycle 1,2,3%} {%cycle 1,2,3%}"); }
public void TestSizeOfArray() { Hash assigns = Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3, 4 } }); Helper.AssertTemplateResult("array has 4 elements", "array has {{ array.size }} elements", assigns); }
public void TestOffsetOnly() { Hash assigns = Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 } }); Helper.AssertTemplateResult("890", "{%for i in array offset:7 %}{{ i }}{%endfor%}", assigns); }
public void TestCaptureDetectsBadSyntax() { Assert.Throws <SyntaxException>(() => Helper.AssertTemplateResult("content foo content foo ", "{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}", Hash.FromAnonymousObject(new { var = "content" }))); }
public void TestAssignWithDrop() { Helper.AssertTemplateResult(".MyValue.", @"{% assign foo = value %}.{{ foo.my_property }}.", Hash.FromAnonymousObject(new { value = new AssignDrop() })); }
public void TestIf() { Helper.AssertTemplateResult(" ", " {% if false %} this text should not go into the output {% endif %} "); Helper.AssertTemplateResult(" this text should go into the output ", " {% if true %} this text should go into the output {% endif %} "); Helper.AssertTemplateResult(" you rock ?", "{% if false %} you suck {% endif %} {% if true %} you rock {% endif %}?"); }
public void TestAssignDecimalInlineWithInvariantDecimalSeparatorInFrenchCulture() { Helper.AssertTemplateResult(string.Format("2{0}5", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator), "{% assign foo = 2.5 %}{{ foo }}"); }
public void TestAssignWithFilter() { Helper.AssertTemplateResult(".bar.", "{% assign foo = values | split: ',' %}.{{ foo[1] }}.", Hash.FromAnonymousObject(new { values = "foo,bar,baz" })); }
public void TestAssignDecimalInlineWithEnglishGroupSeparator() { Helper.AssertTemplateResult("2500", "{% assign foo = 2,500 %}{{ foo }}"); }
public void TestAssignDecimal() { Helper.AssertTemplateResult(string.Format("10{0}05", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator), "{% assign foo = decimal %}{{ foo }}", Hash.FromAnonymousObject(new { @decimal = 10.05d })); }
public void TestAssignMinus() { Hash assigns = Hash.FromAnonymousObject(new { notused = "content" }); Helper.AssertTemplateResult("var2: var2:-1", "var2:{{var2}} {% assign var2 = -1 %} var2:{{var2}}", assigns); }
public void TestForAndIf() { Helper.AssertTemplateResult("+--", "{%for item in array%}{% if forloop.first %}+{% else %}-{% endif %}{%endfor%}", Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3 } })); }
public void TestSyntaxErrorNoVariable() { Assert.Throws <SyntaxException>(() => Helper.AssertTemplateResult("", "{% if jerry == 1 %}")); }
public void TestNestedFor() { Hash assigns = Hash.FromAnonymousObject(new { array = new[] { new[] { 1, 2 }, new[] { 3, 4 }, new[] { 5, 6 } } }); Helper.AssertTemplateResult("123456", "{%for item in array%}{%for i in item%}{{ i }}{%endfor%}{%endfor%}", assigns); }
public void TestSyntaxErrorNoExpression() { Assert.Throws <SyntaxException>(() => Helper.AssertTemplateResult("", "{% if %}")); }
public void TestAssign() { Hash assigns = Hash.FromAnonymousObject(new { var = "content" }); Helper.AssertTemplateResult("var2: var2:content", "var2:{{var2}} {%assign var2 = var%} var2:{{var2}}", assigns); }
public void TestIfElse() { Helper.AssertTemplateResult(" YES ", "{% if false %} NO {% else %} YES {% endif %}"); Helper.AssertTemplateResult(" YES ", "{% if true %} YES {% else %} NO {% endif %}"); Helper.AssertTemplateResult(" YES ", "{% if 'foo' %} YES {% else %} NO {% endif %}"); }
public void TestCaseDetectsBadSyntax() { Assert.Throws <SyntaxException>(() => Helper.AssertTemplateResult("", "{% case false %}{% when %}true{% endcase %}", new Hash())); Assert.Throws <SyntaxException>(() => Helper.AssertTemplateResult("", "{% case false %}{% huh %}true{% endcase %}", new Hash())); }
public void TestIfBoolean() { Helper.AssertTemplateResult(" YES ", "{% if var %} YES {% endif %}", Hash.FromAnonymousObject(new { var = true })); }
public void TestMultipleNamedCycles() { Helper.AssertTemplateResult("one one two two one one", "{%cycle 1: 'one', 'two' %} {%cycle 2: 'one', 'two' %} {%cycle 1: 'one', 'two' %} {%cycle 2: 'one', 'two' %} {%cycle 1: 'one', 'two' %} {%cycle 2: 'one', 'two' %}"); }
public void TestIfAnd() { Helper.AssertTemplateResult(" YES ", "{% if true and true %} YES {% endif %}"); Helper.AssertTemplateResult("", "{% if false and true %} YES {% endif %}"); Helper.AssertTemplateResult("", "{% if false and true %} YES {% endif %}"); }
public void TestSizeOfHash() { Hash assigns = Hash.FromAnonymousObject(new { hash = Hash.FromAnonymousObject(new { a = 1, b = 2, c = 3, d = 4 }) }); Helper.AssertTemplateResult("hash has 4 elements", "hash has {{ hash.size }} elements", assigns); }
public void TestHashMissGeneratesFalse() { Helper.AssertTemplateResult("", "{% if foo.bar %} NO {% endif %}", Hash.FromAnonymousObject(new { foo = new Hash() })); }
public void TestOutputInRaw() { Helper.AssertTemplateResult("{{ test }}", "{% raw %}{{ test }}{% endraw %}"); }
public void TestForWithRange() { Helper.AssertTemplateResult(" 1 2 3 ", "{%for item in (1..3) %} {{item}} {%endfor%}"); }
public void TestTagInRaw() { Helper.AssertTemplateResult("{% comment %} test {% endcomment %}", "{% raw %}{% comment %} test {% endcomment %}{% endraw %}"); }
public void TestMultilineTag() { Helper.AssertTemplateResult("0 1 2 3", "0{%\nfor i in (1..3)\n%} {{\ni\n}}{%\nendfor\n%}"); //Helper.AssertTemplateResult("0 1 2 3", "0{%for i in (1..3)%}{{i}}{%endfor%}"); }