Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void TestAssign()
        {
            Hash assigns = Hash.FromAnonymousObject(new { var = "content" });

            Helper.AssertTemplateResult("var2:  var2:content", "var2:{{var2}} {%assign var2 = var%} var2:{{var2}}", assigns);
        }
Beispiel #3
0
 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 TestNestedIncludeTagWithVariable()
        {
            Assert.AreEqual("Product: Draft 151cm details ",
                            Template.Parse("{% include 'nested_product_template' with product %}").Render(Hash.FromAnonymousObject(new { product = Hash.FromAnonymousObject(new { title = "Draft 151cm" }) })));

            Assert.AreEqual("Product: Draft 151cm details Product: Element 155cm details ",
                            Template.Parse("{% include 'nested_product_template' for products %}").Render(Hash.FromAnonymousObject(new { products = new[] { Hash.FromAnonymousObject(new { title = "Draft 151cm" }), Hash.FromAnonymousObject(new { title = "Element 155cm" }) } })));
        }
Beispiel #5
0
        public async Task TestIfOr()
        {
            await Helper.AssertTemplateResultAsync(" YES ", "{% if a or b %} YES {% endif %}", Hash.FromAnonymousObject(new { a = true, b = true }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if a or b %} YES {% endif %}", Hash.FromAnonymousObject(new { a = true, b = false }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if a or b %} YES {% endif %}", Hash.FromAnonymousObject(new { a = false, b = true }));

            await Helper.AssertTemplateResultAsync("", "{% if a or b %} YES {% endif %}", Hash.FromAnonymousObject(new { a = false, b = false }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if a or b or c %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { a = false, b = false, c = true }));

            await Helper.AssertTemplateResultAsync("", "{% if a or b or c %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { a = false, b = false, c = false }));
        }
Beispiel #6
0
 public void TestAssignDecimal()
 {
     Helper.AssertTemplateResult(string.Format("10{0}05", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator),
                                 "{% assign foo = decimal %}{{ foo }}",
                                 Hash.FromAnonymousObject(new { @decimal = 10.05d }));
 }
Beispiel #7
0
 public void TestAssignWithDrop()
 {
     Helper.AssertTemplateResult(".MyValue.", @"{% assign foo = value %}.{{ foo.my_property }}.",
                                 Hash.FromAnonymousObject(new { value = new AssignDrop() }));
 }
Beispiel #8
0
 public void TestIncludeTagFor()
 {
     Assert.AreEqual("Product: Draft 151cm Product: Element 155cm ", Template.Parse("{% include 'product' for products %}").Render(Hash.FromAnonymousObject(new { products = new[] { Hash.FromAnonymousObject(new { title = "Draft 151cm" }), Hash.FromAnonymousObject(new { title = "Element 155cm" }) } })));
 }
Beispiel #9
0
        public void TestFor()
        {
            Helper.AssertTemplateResult(" yo  yo  yo  yo ", "{%for item in array%} yo {%endfor%}",
                                        Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3, 4 } }));
            Helper.AssertTemplateResult("yoyo", "{%for item in array%}yo{%endfor%}", Hash.FromAnonymousObject(new { array = new[] { 1, 2 } }));
            Helper.AssertTemplateResult(" yo ", "{%for item in array%} yo {%endfor%}", Hash.FromAnonymousObject(new { array = new[] { 1 } }));
            Helper.AssertTemplateResult("", "{%for item in array%}{%endfor%}", Hash.FromAnonymousObject(new { array = new[] { 1, 2 } }));
            const string expected = @"
  yo

  yo

  yo
";
            const string template = @"{%for item in array%}
  yo
{%endfor%}";

            Helper.AssertTemplateResult(expected, template, Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3 } }));
        }
Beispiel #10
0
 public void TestIncludeTagLooksForFileSystemInRegistersFirst()
 {
     Assert.AreEqual("from OtherFileSystem", Template.Parse("{% include 'pick_a_source' %}").Render(new RenderParameters {
         Registers = Hash.FromAnonymousObject(new { file_system = new OtherFileSystem() })
     }));
 }
Beispiel #11
0
 public void TestIncludeTagWithDefaultName()
 {
     Assert.AreEqual("Product: Draft 151cm ", Template.Parse("{% include 'product' %}").Render(Hash.FromAnonymousObject(new { product = Hash.FromAnonymousObject(new { title = "Draft 151cm" }) })));
 }
Beispiel #12
0
 public void TestUnlessElseInLoop()
 {
     Helper.AssertTemplateResult(" TRUE  2  3 ", "{% for i in choices %}{% unless i %} {{ forloop.index }} {% else %} TRUE {% endunless %}{% endfor %}",
                                 Hash.FromAnonymousObject(new { choices = new object[] { 1, null, false } }));
 }
Beispiel #13
0
        public async Task TestIfFromVariable()
        {
            const object nullValue = null;

            await Helper.AssertTemplateResultAsync("", "{% if var %} NO {% endif %}", Hash.FromAnonymousObject(new { var = false }));

            await Helper.AssertTemplateResultAsync("", "{% if var %} NO {% endif %}", Hash.FromAnonymousObject(new { var = nullValue }));

            await Helper.AssertTemplateResultAsync("", "{% if foo.bar %} NO {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = Hash.FromAnonymousObject(new { bar = false }) }));

            await Helper.AssertTemplateResultAsync("", "{% if foo.bar %} NO {% endif %}", Hash.FromAnonymousObject(new { foo = new Hash() }));

            await Helper.AssertTemplateResultAsync("", "{% if foo.bar %} NO {% endif %}", Hash.FromAnonymousObject(new { foo = nullValue }));

            await Helper.AssertTemplateResultAsync("", "{% if foo.bar %} NO {% endif %}", Hash.FromAnonymousObject(new { foo = true }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if var %} YES {% endif %}", Hash.FromAnonymousObject(new { var = "text" }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if var %} YES {% endif %}", Hash.FromAnonymousObject(new { var = true }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if var %} YES {% endif %}", Hash.FromAnonymousObject(new { var = 1 }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if var %} YES {% endif %}", Hash.FromAnonymousObject(new { var = new Hash() }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if var %} YES {% endif %}", Hash.FromAnonymousObject(new { var = new object[] { } }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if 'foo' %} YES {% endif %}");

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = Hash.FromAnonymousObject(new { bar = true }) }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = Hash.FromAnonymousObject(new { bar = "text" }) }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = Hash.FromAnonymousObject(new { bar = 1 }) }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = Hash.FromAnonymousObject(new { bar = new Hash() }) }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = Hash.FromAnonymousObject(new { bar = new object[] { } }) }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if var %} NO {% else %} YES {% endif %}", Hash.FromAnonymousObject(new { var = false }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if var %} NO {% else %} YES {% endif %}", Hash.FromAnonymousObject(new { var = nullValue }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if var %} YES {% else %} NO {% endif %}", Hash.FromAnonymousObject(new { var = true }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if 'foo' %} YES {% else %} NO {% endif %}", Hash.FromAnonymousObject(new { var = "text" }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} NO {% else %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = Hash.FromAnonymousObject(new { bar = false }) }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} YES {% else %} NO {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = Hash.FromAnonymousObject(new { bar = true }) }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} YES {% else %} NO {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = Hash.FromAnonymousObject(new { bar = "text" }) }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} NO {% else %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = Hash.FromAnonymousObject(new { notbar = true }) }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} NO {% else %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { foo = new Hash() }));

            await Helper.AssertTemplateResultAsync(" YES ", "{% if foo.bar %} NO {% else %} YES {% endif %}",
                                                   Hash.FromAnonymousObject(new { notfoo = Hash.FromAnonymousObject(new { bar = true }) }));
        }
Beispiel #14
0
 public async Task TestHashMissGeneratesFalse()
 {
     await Helper.AssertTemplateResultAsync("", "{% if foo.bar %} NO {% endif %}", Hash.FromAnonymousObject(new { foo = new Hash() }));
 }
Beispiel #15
0
        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);
        }
Beispiel #16
0
 public void TestForAndIf()
 {
     Helper.AssertTemplateResult("+--", "{%for item in array%}{% if forloop.first %}+{% else %}-{% endif %}{%endfor%}",
                                 Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3 } }));
 }
Beispiel #17
0
        public void TestForReversed()
        {
            Hash assigns = Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3 } });

            Helper.AssertTemplateResult("321", "{%for item in array reversed %}{{item}}{%endfor%}", assigns);
        }
Beispiel #18
0
 public void TestForElse()
 {
     // parity tests with https://github.com/Shopify/liquid/blob/master/test/integration/tags/for_tag_test.rb
     Helper.AssertTemplateResult("+++", "{%for item in array%}+{%else%}-{%endfor%}", Hash.FromAnonymousObject(new { array = new[] { 1, 2, 3 } }));
     Helper.AssertTemplateResult("-", "{%for item in array%}+{%else%}-{%endfor%}", Hash.FromAnonymousObject(new { array = new int[0] }));
     Helper.AssertTemplateResult("-", "{%for item in array%}+{%else%}-{%endfor%}", Hash.FromAnonymousObject(new { array = (int[])null }));
 }
Beispiel #19
0
 public void TestAssignWithFilter()
 {
     Helper.AssertTemplateResult(".bar.", "{% assign foo = values | split: ',' %}.{{ foo[1] }}.",
                                 Hash.FromAnonymousObject(new { values = "foo,bar,baz" }));
 }
Beispiel #20
0
        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 TestIncludeTagWithMultipleLocalVariablesFromContext()
 {
     Assert.AreEqual("Locale: test123 test321",
                     Template.Parse("{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}").Render(Hash.FromAnonymousObject(new { echo1 = "test123", more_echos = Hash.FromAnonymousObject(new { echo2 = "test321" }) })));
 }
Beispiel #22
0
        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 TestDynamicallyChosenTemplate()
        {
            Assert.AreEqual("Test123", Template.Parse("{% include template %}").Render(Hash.FromAnonymousObject(new { template = "Test123" })));
            Assert.AreEqual("Test321", Template.Parse("{% include template %}").Render(Hash.FromAnonymousObject(new { template = "Test321" })));

            Assert.AreEqual("Product: Draft 151cm ", Template.Parse("{% include template for product %}").Render(Hash.FromAnonymousObject(new { template = "product", product = Hash.FromAnonymousObject(new { title = "Draft 151cm" }) })));
        }
Beispiel #24
0
 public async Task TestIfBoolean()
 {
     await Helper.AssertTemplateResultAsync(" YES ", "{% if var %} YES {% endif %}", Hash.FromAnonymousObject(new { var = true }));
 }