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 TestAssignDecimalInlineWithInvariantDecimalSeparatorInFrenchCulture() { Helper.AssertTemplateResult(string.Format("2{0}5", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator), "{% assign foo = 2.5 %}{{ foo }}"); }
public void TestForWithRange() { Helper.AssertTemplateResult(" 1 2 3 ", "{%for item in (1..3) %} {{item}} {%endfor%}"); }
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 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 TestForReversed() { Hash assigns = Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3 } }); Helper.AssertTemplateResult("321", "{%for item in array reversed %}{{item}}{%endfor%}", assigns); }
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 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 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 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 TestCaptureDetectsBadSyntax() { Assert.Throws <SyntaxException>(() => Helper.AssertTemplateResult("content foo content foo ", "{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}", Hash.FromAnonymousObject(new { var = "content" }))); }
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 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 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 TestForAndIf() { Helper.AssertTemplateResult("+--", "{%for item in array%}{% if forloop.first %}+{% else %}-{% endif %}{%endfor%}", Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3 } })); }