public void TestExpressionListyToLiteral()
 {
     string templateScript = @"Literal content @{ (if true @{back to literal content@}) @} end of literal content.";
     RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
     string result = template.Execute(null);
     Assert.AreEqual(@"Literal content back to literal content end of literal content.", result);
 }
 public void LiteralReplaceOpShouldWork()
 {
     string templateScript = @"1 + 1 = @{ (if true @{{sum 1,1} @}) @}";
     RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
     string result = template.Execute(null);
     Assert.AreEqual(@"1 + 1 = 2 ", result);
 }
 public void TestEscapeAtSymbol()
 {
     string templateScript = @"a single @ sign is output as @; two @ signs are output as a single @@ sign so that in literal we can output @@{{ and @@}.";
     RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
     string result = template.Execute(null);
     Assert.AreEqual("a single @ sign is output as @; two @ signs are output as a single @ sign so that in literal we can output @{ and @}.", result);
 }
        public void TestDefFunction()
        {
            string templateScript = @"@{
            (:: x 2)
            (:: y 1)
            (if false x y)
            @}";

            RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
            string result = template.Execute(null);
            Assert.AreEqual(result, "1");
        }
        public void TestAccumulation()
        {
            string templateScript = @"@{
            (:: x 0)
            (for i 1 100
            (:= x (+ x i))
            )
            (+ x)
            @}";

            RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
            string result = template.Execute(null);
            Assert.AreEqual(result, "5050");
        }
 public void TestForFunction()
 {
     string script = @"@{
     (:: myfunc (+ 10 x y))
     (for i 1 3 @{@{(myfunc i 10)@}
     @})
     @}";
     RTTemplate template = new RTTemplate(script, new TemplateOptions());
     string result = template.Execute(null);
     Assert.AreEqual(result,
     @"21
     22
     23
     ");
 }
 public void TestFunctionList()
 {
     string templateScript = @"@{
     (+ 1 1.4)
     (+ 7 7)
     @}";
     RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
     string result = template.Execute(null);
     Assert.AreEqual("2.414", result);
 }
        public void TestSumOddNumbers()
        {
            string templateScript = @"@{
            (:: x 0)
            (for i 1 10
            (:= x   (if (residueIs i 2 1)
                (+ x i)
                x
            )
            )
            )
            (+ x)
            @}";

            RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
            string result = template.Execute(null);
            Assert.AreEqual(result, "25");
        }
        public void TestSetFunction()
        {
            string templateScript = @"@{
            (:: x y)
            (:: y x)
            (::z (if false x y))
            (:= y 55)
            (+ y 1)
            @}";

            RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
            string result = template.Execute(null);
            Assert.AreEqual(result, "56");
        }
Beispiel #10
0
        public void TestRecursionFac5()
        {
            string templateScript = @"@{
            (:: fac (if (= x 1)
            1
            (* (fac (+ x -1)) x)
            )
            )

            (fac 5)
            @}";

            RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
            string result = template.Execute(null);
            Assert.AreEqual(result, "120");
        }
Beispiel #11
0
        public void TestParsingError()
        {
            string templateScript = @"@{
            abc
            @}";
            RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
            string result = template.Execute(null);

            //todo fix this bug, cause is when parsing function, didnt check the current char is start bracket.
        }
Beispiel #12
0
        public void TestItemCountFunction()
        {
            string srcText = "12345";
            string templateScript = @"@{
            (for i (itemCount) 0
            ($i)
            )
            @}";

            RTMatcher matcher = new RTMatcher(@"(\d)+", new MatchOptions() { MatchType = MatchType.Capture });
            var match = matcher.Execute(srcText);

            RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
            string result = template.Execute(match[0]);
            Assert.AreEqual(result, "54321");
        }
Beispiel #13
0
        public void TestIfFunction()
        {
            string templateScript = @"@{
            (if true (* 5 3) 2)
            @}";

            RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
            string result = template.Execute(null);
            Assert.AreEqual(result, "15");
        }
Beispiel #14
0
        public void TestGetFunction()
        {
            string srcText = "1 2 3 4 5";
            string templateScript = @"@{
            (for i 1 5
            (+ ($i) 1)
            )
            @}";

            RTMatcher matcher = new RTMatcher(@"(\d)\s(\d)\s(\d)\s(\d)\s(\d)", new MatchOptions());
            var match = matcher.Execute(srcText);

            RTTemplate template = new RTTemplate(templateScript, new TemplateOptions());
            string result = template.Execute(match[0]);
            Assert.AreEqual(result, "23456");
        }