コード例 #1
0
        public void CanParseScriptWriteBlock()
        {
            var template = new RubyTemplate("<%= \"Hello World\" %>");
            var result   = template.ToScript();

            Assert.Equal("response.Write(\"Hello World\")", result);
        }
コード例 #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);
        }
コード例 #3
0
        public void CanAddRequires()
        {
            var template = new RubyTemplate(string.Empty);

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

            Assert.Throws <InvalidOperationException>("Started a '<%=' block without ending it.",
                                                      () => template.ToScript());
        }
コード例 #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);
        }
コード例 #6
0
        public void TemplateWithBackslashDoesNotCauseException()
        {
            var template = new RubyTemplate(@"<html>\</html>");
            var result   = template.ToScript();

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

            Assert.Equal(expected, result);
        }
コード例 #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);
        }
コード例 #8
0
        public void TestTemplate()
        {
            var tem = new RubyTemplate();
            tem.ModuleName = "Zxd.Script";
            tem.AliasName = "�ű�";
            tem.ScriptName = "Zxd";
            //tem.Content = "1 + 1";

            //tem.ToScript();
        }
コード例 #9
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);
        }
コード例 #10
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);
        }
コード例 #11
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);
        }
コード例 #12
0
        public void TestSave()
        {
            var tem = new RubyTemplate();

            tem.ModuleName = "Zxd.Script";
            tem.AliasName = "�ű�";
            tem.ScriptName = "Zxd";
            tem.Content = "1 + 1";
            tem.Requires.Add("sdfsadfasf");
            tem.Requires.Add("sdfaaaaaa");
            tem.Footnode.Add("----------------");
            tem.Footnode.Add("--------------------");
            tem.Roles.Add("role");
            tem.Users.Add("user");
            var item = "RubyTemplateRespository".GetInstance<IRubyTemplateRepository>();
            item.Add(tem);
        }
コード例 #13
0
        public void CanParseScriptBlock()
        {
            var template = new RubyTemplate("<% puts 'hello world' %>");

            Assert.Equal("puts 'hello world'", template.ToScript());
        }
コード例 #14
0
        public void CanParseEmptyTemplate()
        {
            var template = new RubyTemplate(string.Empty);

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