Esempio n. 1
0
        public void CanParseScriptWriteBlock()
        {
            var template = new RubyTemplate("<%= \"Hello World\" %>");
            var result   = template.ToScript();

            Assert.Equal("response.Write(\"Hello World\")", result);
        }
Esempio n. 2
0
        public void CanParseMultiLineBlock()
        {
            var template = new RubyTemplate("<% puts \"Hello World\"\r\nputs 'IronRuby is fun!' %>");
            var result   = template.ToScript();

            Assert.Equal("puts \"Hello World\"\r\nputs 'IronRuby is fun!'", result);
        }
Esempio n. 3
0
        public void CanAddRequires()
        {
            var template = new RubyTemplate(string.Empty);

            template.AddRequire("mscorlib.dll");
            Assert.Equal(@"require 'mscorlib.dll'", template.ToScript());
        }
Esempio n. 4
0
        public void ParsingAScriptBlockThatStartsButDoesNotEndThrowsInvalidOperationException()
        {
            var template = new RubyTemplate("<%=");

            Assert.Throws <InvalidOperationException>("Started a '<%=' block without ending it.",
                                                      () => template.ToScript());
        }
Esempio n. 5
0
        public void CanParseHtmlContainingDoubleQuotes()
        {
            var template = new RubyTemplate("<html><span title=\"blah\" /></html>");
            var result   = template.ToScript();

            var expected = @"response.Write(""<html><span title=\""blah\"" /></html>"")";

            Assert.Equal(expected, result);
        }
Esempio n. 6
0
        public void TemplateWithBackslashDoesNotCauseException()
        {
            var template = new RubyTemplate(@"<html>\</html>");
            var result   = template.ToScript();

            var expected = ExpectedWrite(@"""<html>\\</html>""");

            Assert.Equal(expected, result);
        }
Esempio n. 7
0
        public void CanParseHtmlBeginningInScriptBlock()
        {
            var template = new RubyTemplate("<% puts 'test' %></html>");
            var result   = template.ToScript();

            var expected = "puts 'test'" + Environment.NewLine
                           + ExpectedWrite("\"</html>\"");

            Assert.Equal(expected, result);
        }
Esempio n. 8
0
        public void LeavesHtmlAlone()
        {
            var template =
                new RubyTemplate("<html>\r\n<head><title></title></head>\r\n<body>\r\nHello World</body>\r\n</html>");
            var result = template.ToScript();

            Assert.Equal(
                ExpectedWrite(
                    "\"<html>\\r\\n<head><title></title></head>\\r\\n<body>\\r\\nHello World</body>\\r\\n</html>\""),
                result);
        }
Esempio n. 9
0
        public void CanConverToScript()
        {
            var template = new RubyTemplate("<% puts 'test' %></html>");
            var result   = template.ToScript("puts_test");

            var expected = "def puts_test" + Environment.NewLine
                           + "puts 'test'" + Environment.NewLine
                           + ExpectedWrite("\"</html>\"") + Environment.NewLine
                           + "end";

            Assert.Equal(expected, result);
        }
Esempio n. 10
0
        public void CanRemoveNewlineAtEnd()
        {
            var original = "<% [1..10].each do |i| %>" + Environment.NewLine
                           + "	<%= i -%>"+ Environment.NewLine
                           + "<% end %>";

            var template = new RubyTemplate(original);
            var result   = template.ToScript();

            var expected = "[1..10].each do |i|" + Environment.NewLine
                           + ExpectedWrite(@"""\r\n	""") + Environment.NewLine
                           + ExpectedWrite("i") + Environment.NewLine
                           + "end";

            Assert.Equal(expected, result);
        }
Esempio n. 11
0
        public void CanParseScriptBlock()
        {
            var template = new RubyTemplate("<% puts 'hello world' %>");

            Assert.Equal("puts 'hello world'", template.ToScript());
        }
Esempio n. 12
0
        public void CanParseEmptyTemplate()
        {
            var template = new RubyTemplate(string.Empty);

            Assert.Equal(string.Empty, template.ToScript());
        }