Exemplo n.º 1
0
        public void Render_StringWithCorrectRubySyntax_PrintsCorrectOutput(
            [Values("<%5.times {print '*'}%>",
                    "<%i = 10;%>i=<%print i%>",
                    "<%i = 0; until i == 5 do i += 1; end;%><%i.times{%>+<%}%>",
                    "<%=(13+2)/5-(16/2)%>",
                    "a%#@! #%^% ^&*(",
                    "<%name = 'Jimmi'.reverse; print name%>",
                    "<%nameX5 = 'Max' * 3; print nameX5%>",
                    "<%number = 40.to_s.reverse; print number%>",
                    "<%max = [211,832,91,777].max; print max%>",
                    "<%array = [3,1,2]; print array.sort%>",
                    "<%def call_block; yield; yield; yield; end; call_block{%>F**k!<%}%>")] 
                    String templateString,
            [Values("*****",
                    "i=10",
                    "+++++",
                    "-5",
                    "a%#@! #%^% ^&*(",
                    "immiJ",
                    "MaxMaxMax",
                    "04",
                    "832",
                    "[1, 2, 3]",
                    "F**k!F**k!F**k!")] String result)
        {
            var template = new Template(templateString, null, null, (ILanguage)rubyLanguage);
            var outputStream = new StringWriter();

            template.Render(outputStream, null);
            Assert.That(outputStream.ToString(), Is.EqualTo(result));
        }
Exemplo n.º 2
0
        public void Constructor_StringWithIncorrectJavaSyntax_ExpectAnIncorrectSyntaxException(
            [Values("hellof<%or(int i = 1; i < 3; i++){}%>",
                    "<%int n = int = 3; while(n > 3) { n--; }%>",
                    "<% int n = String\";%>")] String templateString)
        {
            var template = new Template(templateString, null, null, (ILanguage)javaLanguage);

            var outputStream = new StringWriter();

            template.Render(outputStream, null);
        }
Exemplo n.º 3
0
        public void Render_NamespacesParameterPassed_DoesNotThrowAnException(
            [Values("<%Thread.Sleep(100);%>")] String templateString)
        {
            Assert.DoesNotThrow(delegate
            {
                var template = new Template(templateString, new String[] { "System.Threading" }, null, (ILanguage)csharpLanguage);
                var outputStream = new StringWriter();

                template.Render(outputStream, null);
            }
            );
        }
Exemplo n.º 4
0
 public void Render_LongUnicodeStringCSharp_PrintsTheSameString()
 {
     var buffer = new StringBuilder();
     for (int i = Char.MinValue; i <= Char.MaxValue; i++)
     {
         buffer.Append((char)i);
     }
     var test = String.Join("", Enumerable.Repeat(buffer.ToString(), 16));
     var output = new StringWriter();
     var template = new Template(test, null, null, csharpLanguage);
     template.Render(output, null);
     Assert.AreEqual(test, output.ToString());
 }
Exemplo n.º 5
0
        public void Constructor_StringWithIncorrectPythonSyntax_ExpectATemplateCodeRuntimeException(
            [Values("<%print hello'\nif 5 > 3:\n\tprint 'true'\nelse:\n\tprint 'false'\n%>lala",
                    "<%name = 'what is your name'print 'Hi, %s?' % name%>",
                    "<%friends = ['john', 'pat'\nfor i, name in enumerate(friends):\n\t%>*",
                    "<%def greet(name)\n\tprint 'Hello', name\ngreet('Jack')%>")] 
                    String templateString)
        {
            var template = new Template(templateString, null, null, (ILanguage)pythonLanguage);

            var outputStream = new StringWriter();

            template.Render(outputStream, null);
        }
Exemplo n.º 6
0
        public void Render_CShartCodeWithJsonParameters_PrintsCorrectOutput(
          [Values("Hello, my dear <%=input[\"name\"]%>!",
              "<%String password = (String)input[\"password\"];%><%=password%>")] String templateString,
          [Values("{\"name\": \"Sam\"}",
              "{\"password\": \"11111\"}")] String json,
          [Values("Hello, my dear Sam!",
              "11111")] String result)
        {
            var template = new Template(templateString, null, null, (ILanguage)csharpLanguage);
            var outputStream = new StringWriter();

            template.Render(outputStream, json);
            Assert.That(outputStream.ToString(), Is.EqualTo(result));
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            CSharpLanguage csharpLanguage = new CSharpLanguage();
            JavaLanguage java = new JavaLanguage();
            PythonLanguage python = new PythonLanguage();

            var template = new Template("<%print 'hello'\nif 5 > 3:\n\tprint 'true'\nelse:\n\tprint 'false'\n%>lala",
                                        null,
                                        null,
                                        python);

            template.Render(Console.Out, "{\"password\": \"11111\"}");

            Console.ReadLine();
        }
Exemplo n.º 8
0
        public void Render_OrdinaryString_PrintsTheString(
            [Values("Hello, world!",
                    "%<while>%",
                    "<=%<>%=>")] String templateString,
            [Values("Hello, world!",
                    "%<while>%",
                    "<=%<>%=>")] String result)
        {
            var template = new Template(templateString, null, null, (ILanguage)csharpLanguage);
            var outputStream = new StringWriter();

            template.Render(outputStream, null);

            Assert.That(outputStream.ToString(), Is.EqualTo(result));
        }
Exemplo n.º 9
0
        public void Render_StringWithCorrectPythonSyntax_PrintsCorrectOutput(
            [Values("<%print 'hello'\nif 5 > 3:\n\tprint 'true'\nelse:\n\tprint 'false'\n%>lala",
                    "<%name = 'what is your name'\nprint 'Hi, %s?' % name%>",
                    "<%friends = ['john', 'pat']\nfor i, name in enumerate(friends):\n\t%>*",
                    "<%def greet(name):\n\tprint 'Hello', name\ngreet('Jack')%>")] 
                    String templateString,
            [Values("hello\ntrue\nlala\n",
                    "Hi, what is your name?\n",
                    "*\n*\n",
                    "Hello Jack\n")] String result)
        {
            var template = new Template(templateString, null, null, (ILanguage)pythonLanguage);
            var outputStream = new StringWriter();

            template.Render(outputStream, null);
            Assert.That(outputStream.ToString(), Is.EqualTo(result));
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            var csharpLanguage = new CSharpCompiler.CSharpLanguage();

            //var buffer = new StringBuilder();
            //for (int i = Char.MinValue; i <= Char.MaxValue; i++)
            //{
            //    buffer.Append((char)i);
            //}
            //var test = String.Join("", Enumerable.Repeat(buffer.ToString(), 32));
            string test = "\0\0\0\0\0\0\0000";
            var output = new StringWriter();
            var template = new Template(test, null, null, csharpLanguage);
            template.Render(output, null);
            var result = output.ToString();
            Console.Write(output.ToString() == test);
            Console.Read();
        }
Exemplo n.º 11
0
        public void Render_StringWithCorrectJavaSyntax_PrintsCorrectOutput(
            [Values("<%for (int i = 0; i < 5; ++i) { %>*<%}%>",
                    "<%int i = 0; while(true){i++; if(i == 10) break;}%>i=<%System.out.print(i);%>",
                    "<%int n = 5; while(n > 3) { n--;%><%System.out.print(n);}%>",
                    "<%String n = \"String\";System.out.print(n);%>",
                    "<%int x%><% =3;%>x=<%%><%System.out.print(x);%>",
                    "<%=15/5+2%>")]
                    String templateString,
            [Values("*****",
                    "i=10",
                    "43",
                    "String",
                    "x=3",
                    "5")] String result)
        {
            var template = new Template(templateString, null, null, (ILanguage)javaLanguage);
            var outputStream = new StringWriter();

            template.Render(outputStream, null);
            Assert.That(outputStream.ToString(), Is.EqualTo(result));
        }
Exemplo n.º 12
0
        public void Render_StringWithCorrectCSharpSyntax_PrintsCorrectOutput(
            [Values("<%for (int i = 0; i < 5; ++i) { output.Write('*');}%>",
                    "<%int i = 0; while(true){i++; if(i == 10) break;}%>i=<%output.Write(i);%>",
                    "<%int n = 5; while(n > 3) { n--;%><%output.Write(n);}%>",
                    "<%String n = \"String\";output.Write(n);%>",
                    "<%int x%><% =3;%>x=<%%><%output.Write(x);%>",
                    "f<%%>%%<%%>k",
                    "<%=15/5+2%><%=0%>Р<%=(3*7)/21%>$",
                    "<%Func<int, int> cube = (x) => x * x * x; int a = cube(2);%>a=<%output.Write(a);%>")] 
                    String templateString,
            [Values("*****",
                    "i=10",
                    "43",
                    "String",
                    "x=3",
                    "f%%k",
                    "50Р1$",
                    "a=8")] String result)
        {
            var template = new Template(templateString, null, null, (ILanguage)csharpLanguage);
            var outputStream = new StringWriter();

            template.Render(outputStream, null);
            Assert.That(outputStream.ToString(), Is.EqualTo(result));
        }
Exemplo n.º 13
0
 public void Render_WrongCSharpCode_ExpectRuntimeErrorException(
     [Values("<% String s = \"hi!\";%><%=s[5]%>")] String templateString)
 {
     var template = new Template(templateString, null, null, (ILanguage)csharpLanguage);
     var outputStream = new StringWriter();
     template.Render(outputStream, null);
 }