예제 #1
0
 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);
 }
예제 #2
0
 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);
 }
예제 #3
0
 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);
 }
예제 #4
0
        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");
        }
예제 #5
0
        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");
        }
예제 #6
0
 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
     ");
 }
예제 #7
0
 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);
 }
예제 #8
0
        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");
        }
예제 #9
0
        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");
        }
예제 #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");
        }
예제 #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.
        }
예제 #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");
        }
예제 #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");
        }
예제 #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");
        }