예제 #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 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);
        }