Ejemplo n.º 1
0
        public void It_Should_Skip_Part_Of_A_Loop()
        {
            // Arrange
            var tmpl = GetForLoop("{% continue %}");

            // Act
            var result = RenderingHelper.RenderTemplate(tmpl);

            // Assert
            Assert.That(result, Is.EqualTo("Result : loop1loop2looploop"));
        }
Ejemplo n.º 2
0
        public void It_Should_Have_A_Default()
        {
            // Arrange
            const String tmpl = @"{{ ""The"" | truncatewords }}";

            // Act
            var result = RenderingHelper.RenderTemplate(tmpl);

            // Assert
            Assert.Equal("The", result);
        }
Ejemplo n.º 3
0
        public void It_Should_Return_Zero_When_Null()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("input", Option <ILiquidValue> .None());
            var result = RenderingHelper.RenderTemplate("Result : {{ input | default: 0 }} {{ input | pluralize: 'thing', 'things' }}", ctx);

            // Assert
            Assert.Equal("Result : 0 things", result);
        }
Ejemplo n.º 4
0
        public void It_Should_Allow_Multiple_Cases_Separated_By_Commas()
        {
            // Arrange
            var result = RenderingHelper.RenderTemplate("{% case 1%}{% when 1,2,3 %}One{%else%}Not One{%endcase%}");

            // Act
            Logger.Log(result);

            // Assert
            Assert.That(result.Trim(), Is.EqualTo("One"));
        }
Ejemplo n.º 5
0
        public void It_Should_Return_The_String_When_Insufficient_Args()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("input", LiquidString.Create("1"));
            var result = RenderingHelper.RenderTemplate("Result : {{ input | pluralize }}", ctx);

            // Assert
            Assert.Equal("Result : 1", result);
        }
Ejemplo n.º 6
0
        public void It_Should_Ignore_Missing_Plural()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("input", LiquidString.Create("1"));
            var result = RenderingHelper.RenderTemplate("Result : {{input}} {{ input | pluralize: 'thing' }}", ctx);

            // Assert
            Assert.Equal("Result : 1 thing", result);
        }
Ejemplo n.º 7
0
        public void It_Should_Pluralize_An_Integerr(int input, String expected)
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("input", LiquidNumeric.Create(input));
            var result = RenderingHelper.RenderTemplate("Result : {{ input | pluralize: 'thing', 'things' }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : " + expected));
        }
Ejemplo n.º 8
0
        public void It_Should_Group_Expressions_With_Parentheses()
        {
            // Arrange
            const string str = @"{% if (false and true) or true %}Result #1 is true{% endif %}"
                               + @"{% if false and (true or true) %}Result #2 is true{% endif %}";
            // Act
            var result = RenderingHelper.RenderTemplate(str);

            // Assert
            Assert.That(result, Is.EqualTo("Result #1 is true"));
        }
Ejemplo n.º 9
0
        public void It_Should_Remove_Tags_And_Filters()
        {
            // Arrange
            const string tmpl = "Result : {% comment %} test {{ item }} test  {% if done %}test {% endcomment %}";

            Logger.Log(tmpl);
            String result = RenderingHelper.RenderTemplate(tmpl);

            // Assert
            Assert.Equal("Result : ", result);
        }
Ejemplo n.º 10
0
        public void It_Should_Remove_The_Commented_Text()
        {
            // Arrange
            const string tmpl = "Result : {% comment %} This is a comment {% endcomment %}";

            Logger.Log(tmpl);
            String result = RenderingHelper.RenderTemplate(tmpl);

            // Assert
            Assert.Equal("Result : ", result);
        }
Ejemplo n.º 11
0
        public void It_Should_Return_Default_If_Array_Has_No_Elements()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            // Act
            var result = RenderingHelper.RenderTemplate("Result : {% assign arr=\"\" | split: \"|\"%}{{ arr | default: \"DEFAULT\" }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : DEFAULT"));
        }
Ejemplo n.º 12
0
        public void It_Should_Return_Default_If_Empty_String()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            // Act
            var result = RenderingHelper.RenderTemplate("Result : {{ \"\" | default: \"Hello\" }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : Hello"));
        }
Ejemplo n.º 13
0
        public void It_Should_Ignore_A_Missing_DateValue()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();
            //ctx.Define("mydate", null);
            // Act
            var result = RenderingHelper.RenderTemplate("Result : {{ mydate | date: \"%y\" }}", ctx);

            // Assert
            Assert.Equal("Result : ", result);
        }
Ejemplo n.º 14
0
        public void It_Should_Render_The_Fields()
        {
            // Arrange
            var array            = CreateArray();
            ITemplateContext ctx = new TemplateContext()
                                   .WithAllFilters().DefineLocalVariable("arr", array);
            var result = RenderingHelper.RenderTemplate("Result : {{ arr | map: \"field1\" }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : Value 1 AValue 2 AValue 3 AValue 4 A"));
        }
Ejemplo n.º 15
0
        [InlineData("z", "things")] // I  think this is what should happen...?
        public void It_Should_Pluralize_A_String(String input, String expected)
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("input", LiquidString.Create(input));
            var result = RenderingHelper.RenderTemplate("Result : {{ input | pluralize: 'thing', 'things' }}", ctx);

            // Assert
            Assert.Equal("Result : " + expected, result);
        }
Ejemplo n.º 16
0
        public void It_Should_Not_Format_The_Raw_Text()
        {
            // Arrange
            const string tmpl = "Result : {% raw %}This is a comment{% endraw %}";

            Logger.Log(tmpl);
            String result = RenderingHelper.RenderTemplate(tmpl);

            // Assert
            Assert.Equal("Result : This is a comment", result);
        }
Ejemplo n.º 17
0
        public void It_Should_Truncate_By_Word()
        {
            // Arrange
            const String tmpl = @"{{ ""The cat came back the very next day"" | truncatewords: 4 }}";

            // Act
            var result = RenderingHelper.RenderTemplate(tmpl);

            // Assert
            Assert.Equal("The cat came back...", result);
        }
Ejemplo n.º 18
0
        public void It_Should_Not_Add_Ellipses_With_Fewer_Words()
        {
            // Arrange
            const String tmpl = @"{{ ""The"" | truncatewords: 4 }}";

            // Act
            var result = RenderingHelper.RenderTemplate(tmpl);

            // Assert
            Assert.That(result, Is.EqualTo("The"));
        }
Ejemplo n.º 19
0
        public void It_Should_Render_Missing_Fields_When_ErrorsOff()
        {
            // Arrange
            var array            = CreateArray();
            ITemplateContext ctx = new TemplateContext()
                                   .WithAllFilters().DefineLocalVariable("arr", array);
            var result = RenderingHelper.RenderTemplate("Result : {{ arr | map: \"awefwef\" }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : "));
        }
Ejemplo n.º 20
0
        public void It_Should_Slice_Nil()
        {
            // Arrange
            var ctx = new TemplateContext().WithAllFilters();
            //ctx.DefineLocalVariable("array", CreateArray());
            // Act
            var result = RenderingHelper.RenderTemplate("Result : {{ novar | slice }}", ctx);

            // Assert
            Assert.That(result, Is.StringContaining("Result : "));
        }
Ejemplo n.º 21
0
        public void It_Should_Add_Something_Other_Than_Ellipses()
        {
            // Arrange
            const String tmpl = @"{{ ""The cat came back the very next day"" | truncatewords: 4, ""!!!"" }}";

            // Act
            var result = RenderingHelper.RenderTemplate(tmpl);

            // Assert
            Assert.That(result, Is.EqualTo("The cat came back!!!"));
        }
Ejemplo n.º 22
0
        public void It_Should_Return_Default_If_Null()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            // Act
            var result = RenderingHelper.RenderTemplate("Result : {{ mydate | default: \"Hello\" }}", ctx);

            // Assert
            Assert.Equal("Result : Hello", result);
        }
Ejemplo n.º 23
0
        public void It_Should_Not_Return_Default_If_Array_Has_Elements()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            // Act
            var result = RenderingHelper.RenderTemplate("Result : {% assign arr=\"1|2\" | split: \"|\"%}{{ arr | default: \"DEFAULT\" }}", ctx);

            // Assert
            Assert.Equal("Result : 12", result);
        }
Ejemplo n.º 24
0
        public void It_Should_Return_Default_If_Array_Is_Null()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            // Act
            var result = RenderingHelper.RenderTemplate("Result : {{ arr | default: \"DEFAULT\" }}", ctx);

            // Assert
            Assert.Equal("Result : DEFAULT", result);
        }
Ejemplo n.º 25
0
        public void It_Should_Not_Return_Default_If_Not_Null_And_Not_Empty(String input, String expected)
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            // Act
            var result = RenderingHelper.RenderTemplate("Result : {{ " + input + " | default: \"Hello\" }}", ctx);

            // Assert
            Assert.Equal("Result : " + expected, result);
        }
        public void It_Should_Allow_Multiple_Cases_Separated_By_Or()
        {
            // Arrange
            var result = RenderingHelper.RenderTemplate("{% case 1%}{% when 1 or 2 or 3 %}One{%else%}Not One{%endcase%}");

            // Act
            Logger.Log(result);

            // Assert
            Assert.Equal("One", result.Trim());
        }
        public void It_Should_Parse_A_Case_Tag(String handle, string expected)
        {
            // Arrange
            var result = RenderingHelper.RenderTemplate(GetTestData(handle));

            // Act
            Logger.Log(result);

            // Assert
            Assert.Equal(expected, result.Trim());
        }
Ejemplo n.º 28
0
        public void It_Should_Slice_An_Array(String slice, string expected)
        {
            // Arrange
            var ctx = new TemplateContext().WithAllFilters();

            ctx.DefineLocalVariable("array", CreateArray());
            // Act
            var result = RenderingHelper.RenderTemplate("Result : {{ array | slice : " + slice + " }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : " + expected));
        }
        public void It_Should_Parse_A_Simple_Case_Tag()
        {
            // Arrange
            var result = RenderingHelper.RenderTemplate("Result : {% case 'test' %}{% when 'test' %}TEST{% endcase %}");

            // Act
            Logger.Log(result);
            // Act

            // Assert
            Assert.Equal("Result : TEST", result);
        }
        public void It_Should_Parse_A_Nested_Case_Tag()
        {
            // Arrange
            var result = RenderingHelper.RenderTemplate("Result : {% case 'test' %}{% when 'test' %}{% case 'test' %}{% when 'nottest' %}NOT TEST{% else %}SUCCESS{% endcase %}{% endcase %}");

            // Act
            Logger.Log(result);
            // Act

            // Assert
            Assert.Equal("Result : SUCCESS", result);
        }