Exemplo n.º 1
0
        public void ElseTrue()
        {
            TemplateEngine engine = new TemplateEngine();
            RootTemplate templateItem = engine.BuildTemplate("#if(true) indeed #else no #end");

            EvaluationContext context = new EvaluationContext(new Dictionary<string, object>()
            {
            }, null);

            string result = templateItem.Evaluate(context);
            Assert.AreEqual(" indeed ", result);
        }
Exemplo n.º 2
0
        public void ComplexConditions()
        {
            TemplateEngine engine = new TemplateEngine();
            RootTemplate templateItem = engine.BuildTemplate(@"
            #if(false)
            #elseif(false)
            #elseif(true)
                #if(false)
                #elseif(false)
                    faky
                #elseif(true)
                    #if(false)
                    #elseif(false)
                    #elseif(true)
                        #if(false)
                        #else
                            indeed
                        #end
                    #elseif(false)
                    #else
                    #end
                #elseif(false)
                    test
                #else
                #end
            #elseif(false)
            #else
                some
            #end");

            EvaluationContext context = new EvaluationContext(new Dictionary<string, object>()
            {
            }, null);

            string result = templateItem.Evaluate(context);
            Assert.AreEqual("indeed", result.Trim());
        }
Exemplo n.º 3
0
        public void ForeachWithMultipleElements()
        {
            TemplateEngine engine = new TemplateEngine();
            RootTemplate templateItem = engine.BuildTemplate("#foreach(${person} in ${persons})${person}#end");

            EvaluationContext context = new EvaluationContext(new Dictionary<string, object>() {
                {"persons", new List<string>(){
                    "one",
                    "two",
                    "three"
                }}
            },
            null);

            string result = templateItem.Evaluate(context);
            Assert.AreEqual("onetwothree", result);
        }
Exemplo n.º 4
0
        public void Text()
        {
            TemplateEngine engine = new TemplateEngine();
            RootTemplate templateItem = engine.BuildTemplate("a$toprint}a");

            EvaluationContext context = new EvaluationContext(new Dictionary<string, object>() {
                {"toprint", "this"}
            }, null);

            string result = templateItem.Evaluate(context);
            Assert.AreEqual("a$toprint}a", result);
        }
Exemplo n.º 5
0
        public void SingleLineCommentWithoutLineEnding()
        {
            TemplateEngine engine = new TemplateEngine();
            RootTemplate templateItem = engine.BuildTemplate("test##aaa${test}aaa#end#foreacg#if###");

            EvaluationContext context = new EvaluationContext(new Dictionary<string, object>() { }, null);

            string result = templateItem.Evaluate(context);
            Assert.AreEqual("test", result);
        }
Exemplo n.º 6
0
 public void OneEndTooMany()
 {
     TemplateEngine engine = new TemplateEngine();
     RootTemplate templateItem = engine.BuildTemplate("#comment a #end #end");
 }
Exemplo n.º 7
0
        public void MultiLineCommentInOneLine()
        {
            TemplateEngine engine = new TemplateEngine();
            RootTemplate templateItem = engine.BuildTemplate("#*#foreach(${person} in ${persons})${person}#end*#");

            EvaluationContext context = new EvaluationContext(new Dictionary<string, object>() { }, null);

            string result = templateItem.Evaluate(context);
            Assert.AreEqual(string.Empty, result);
        }
Exemplo n.º 8
0
 public void MultiLineCommentInMultipleLinesWithoutEnding()
 {
     TemplateEngine engine = new TemplateEngine();
     RootTemplate templateItem = engine.BuildTemplate("\n\n\r\tq#*#foreach(\r${person} in ${persons})${pe\nrson}#end\na");
 }
Exemplo n.º 9
0
        public void MultiLineCommentInMultipleLines()
        {
            TemplateEngine engine = new TemplateEngine();
            RootTemplate templateItem = engine.BuildTemplate("\r\tq#*#foreach(\r${person} in ${persons})${pe\nrson}#end*#\na");

            EvaluationContext context = new EvaluationContext(new Dictionary<string, object>() { }, null);

            string result = templateItem.Evaluate(context);
            Assert.AreEqual("\r\tqa", result);
        }
Exemplo n.º 10
0
        public void LongElseElseIfElse()
        {
            TemplateEngine engine = new TemplateEngine();
            RootTemplate templateItem = engine.BuildTemplate(@"
            #if(false)
            #elseif(false)
            #elseif(false)
            #elseif(false)
            #else
                indeed
            #end");

            EvaluationContext context = new EvaluationContext(new Dictionary<string, object>()
            {
            }, null);

            string result = templateItem.Evaluate(context);
            Assert.IsTrue(result.Contains("indeed"));
        }
Exemplo n.º 11
0
        public void LongElseElseIf()
        {
            TemplateEngine engine = new TemplateEngine();
            RootTemplate templateItem = engine.BuildTemplate(@"
            #if(false)
            #elseif(false)
            #elseif(false)
            #elseif(false)
            #else
            #end");

            EvaluationContext context = new EvaluationContext(new Dictionary<string, object>()
            {
            }, null);

            string result = templateItem.Evaluate(context);
            Assert.AreEqual(string.Empty, result.Trim());
        }
Exemplo n.º 12
0
 public void InvalidIfStart()
 {
     TemplateEngine engine = new TemplateEngine();
     RootTemplate templateItem = engine.BuildTemplate("#if (true) #end");
 }
Exemplo n.º 13
0
 public void InvalidIfPrintStatement()
 {
     TemplateEngine engine = new TemplateEngine();
     RootTemplate templateItem = engine.BuildTemplate("test${asddsa\na}");
 }
Exemplo n.º 14
0
 public void InvalidForeachStart()
 {
     TemplateEngine engine = new TemplateEngine();
     RootTemplate templateItem = engine.BuildTemplate("#foreach (${person} in ${persons})${person}#end");
 }
Exemplo n.º 15
0
        public void IfFalse()
        {
            TemplateEngine engine = new TemplateEngine();
            RootTemplate templateItem = engine.BuildTemplate("#if(false)no#end");

            EvaluationContext context = new EvaluationContext(new Dictionary<string, object>()
            {
            }, null);

            string result = templateItem.Evaluate(context);
            Assert.AreEqual(string.Empty, result);
        }