예제 #1
0
        public void ShouldAddOperator()
        {
            var parser = new CustomParser();

            parser.RegisteredOperators["startsWith"] = (a, b) => new StartsWithBinaryExpression(a, b);

            parser.TryParse("{% if 'abc' startsWith 'ab' %}true{% endif %}", out var template, out var error);

            Assert.Equal("true", template.Render());
        }
예제 #2
0
        public void ShouldAddOperator()
        {
            var parser = new CustomParser();

            parser.RegisteredOperators["xor"] = (a, b) => new XorBinaryExpression(a, b);

            parser.TryParse("{% if true xor false %}true{% endif %}", out var template, out var error);

            Assert.Equal("true", template.Render());
        }
예제 #3
0
        public void ShouldReportAndErrorOnEmptyTags()
        {
            var parser = new CustomParser();

            parser.RegisterEmptyTag("hello", (w, e, c) =>
            {
                w.Write("Hello World");

                return(Statement.Normal());
            });

            Assert.Throws <ParseException>(() => parser.Parse("{% hello foo %}"));
        }
예제 #4
0
        public void CustomBlockShouldReturnErrorMessage()
        {
            var parser = new CustomParser();

            parser.RegisterEmptyBlock("hello", static (s, w, e, c) =>
            {
                w.Write("Hello World");
                return(s.RenderStatementsAsync(w, e, c));
            });

            parser.TryParse("{% hello %} hi {%- endhello %} {% endhello %}", out var template, out var error);

            Assert.Null(template);
            Assert.Contains("Unexpected tag 'endhello'", error);
        }
예제 #5
0
        public void ShouldRenderEmptyBlocks()
        {
            var parser = new CustomParser();

            parser.RegisterEmptyBlock("hello", static (s, w, e, c) =>
            {
                w.Write("Hello World");
                return(s.RenderStatementsAsync(w, e, c));
            });

            var template = parser.Parse("{% hello %} hi {%- endhello %}");
            var result   = template.Render();

            Assert.Equal("Hello World hi", result);
        }
예제 #6
0
        public void ShouldRenderEmptyTags()
        {
            var parser = new CustomParser();

            parser.RegisterEmptyTag("hello", (w, e, c) =>
            {
                w.Write("Hello World");

                return(Statement.Normal());
            });

            var template = parser.Parse("{% hello %}");
            var result   = template.Render();

            Assert.Equal("Hello World", result);
        }
예제 #7
0
        public void ShouldRenderIdentifierBlocks()
        {
            var parser = new CustomParser();

            parser.RegisterIdentifierBlock("hello", (i, s, w, e, c) =>
            {
                w.Write("Hello ");
                w.Write(i);
                return(s.RenderStatementsAsync(w, e, c));
            });

            var template = parser.Parse("{% hello test %} hi {%- endhello %}");
            var result   = template.Render();

            Assert.Equal("Hello test hi", result);
        }
예제 #8
0
        public void ShouldRenderIdentifierTags()
        {
            var parser = new CustomParser();

            parser.RegisterIdentifierTag("hello", (s, w, e, c) =>
            {
                w.Write("Hello ");
                w.Write(s);

                return(Statement.Normal());
            });

            var template = parser.Parse("{% hello test %}");
            var result   = template.Render();

            Assert.Equal("Hello test", result);
        }