コード例 #1
0
            public void It_will_write_the_footer_using_the_plain_text_colors()
            {
                HtmlFormatter formatter = new HtmlFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet { Name__getValue = "fnord", Styles__getValue = new StyleDictionary { new Style(ScopeName.PlainText) { Background = Color.White, Foreground = Color.Black } } };
                StubTextWriter stubTextWriter = new StubTextWriter();

                formatter.WriteFooter(stubStyleSheet, new StubLanguage(), stubTextWriter);

                Assert.Equal("</pre></div>", stubTextWriter.Write__buffer);
            }
コード例 #2
0
            public void It_will_write_the_footer()
            {
                HtmlClassFormatter formatter = new HtmlClassFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet { Name__getValue = "fnord", Styles__getValue = new StyleDictionary { } };
                StubLanguage stubLanguage = new StubLanguage { CssClassName_getValue = "fnord" };
                StubTextWriter stubTextWriter = new StubTextWriter();

                formatter.WriteFooter(stubStyleSheet, stubLanguage, stubTextWriter);

                Assert.Equal("</pre></div>", stubTextWriter.Write__buffer);
            }
コード例 #3
0
            public void It_will_write_parsed_source_code_with_nested_scopes()
            {
                HtmlFormatter formatter = new HtmlFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet
                {
                    Name__getValue = "fnord",
                    Styles__getValue = new StyleDictionary
                                       {
                                           new Style(ScopeName.String) { Foreground = DullRed },
                                           new Style(ScopeName.HtmlEntity) { Foreground = Color.Red }
                                       }
                };
                StubTextWriter stubTextWriter = new StubTextWriter();
                List<Scope> scopes = new List<Scope>
                                     {
                                         new Scope(ScopeName.String, 0, 20)
                                     };
                scopes[0].AddChild(new Scope(ScopeName.HtmlEntity, 0,6));
                scopes[0].AddChild(new Scope(ScopeName.HtmlEntity, 14, 6));

                formatter.Write("&quot;a string&quot;", scopes, stubStyleSheet, stubTextWriter);

                Assert.Equal("<span style=\"color:#A31515;\"><span style=\"color:Red;\">&amp;quot;</span>a string<span style=\"color:Red;\">&amp;quot;</span></span>", stubTextWriter.Write__buffer);
            }
コード例 #4
0
            public void It_will_write_parsed_source_code_with_multiple_scopes()
            {
                HtmlFormatter formatter = new HtmlFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet
                {
                    Name__getValue = "fnord",
                    Styles__getValue = new StyleDictionary
                                       {
                                           new Style(ScopeName.Keyword) { Foreground = Color.Blue },
                                           new Style(ScopeName.String) { Foreground = DullRed }
                                       }
                };
                StubTextWriter stubTextWriter = new StubTextWriter();
                List<Scope> scopes = new List<Scope>
                                     {
                                         new Scope(ScopeName.Keyword, 0, 4),
                                         new Scope(ScopeName.Keyword, 13, 5)
                                     };

                formatter.Write("bool fnord = false;", scopes, stubStyleSheet, stubTextWriter);

                Assert.Equal("<span style=\"color:Blue;\">bool</span> fnord = <span style=\"color:Blue;\">false</span>;", stubTextWriter.Write__buffer);
            }
コード例 #5
0
            public void It_will_write_parsed_source_code_with_a_single_scope()
            {
                HtmlFormatter formatter = new HtmlFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet
                                                {
                                                    Name__getValue = "fnord",
                                                    Styles__getValue = new StyleDictionary { new Style(ScopeName.Keyword) { Foreground = Color.Blue } }
                                                };
                StubTextWriter stubTextWriter = new StubTextWriter();
                List<Scope> scopes = new List<Scope> { new Scope(ScopeName.Keyword, 0, 5) };

                formatter.Write("false", scopes, stubStyleSheet, stubTextWriter);

                Assert.Equal("<span style=\"color:Blue;\">false</span>", stubTextWriter.Write__buffer);
            }
コード例 #6
0
            public void It_will_write_encoded_HTML()
            {
                HtmlFormatter formatter = new HtmlFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet
                {
                    Name__getValue = "fnord",
                    Styles__getValue = new StyleDictionary { new Style(ScopeName.String) { Foreground = DullRed } }
                };
                StubTextWriter stubTextWriter = new StubTextWriter();
                List<Scope> scopes = new List<Scope> { new Scope(ScopeName.String, 0, 10) };

                formatter.Write("\"a string\"", scopes, stubStyleSheet, stubTextWriter);

                Assert.Equal("<span style=\"color:#A31515;\">&quot;a string&quot;</span>", stubTextWriter.Write__buffer);
            }
コード例 #7
0
            public void It_will_write_a_background_color_when_a_style_specifies_one()
            {
                HtmlFormatter formatter = new HtmlFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet
                {
                    Name__getValue = "fnord",
                    Styles__getValue = new StyleDictionary
                                       {
                                           new Style(ScopeName.Comment) { Foreground = Color.Green },
                                           new Style(ScopeName.HtmlServerSideScript) { Background = Color.Yellow }
                                       }
                };
                StubTextWriter stubTextWriter = new StubTextWriter();
                List<Scope> scopes = new List<Scope>
                                     {
                                         new Scope(ScopeName.HtmlServerSideScript, 0, 2),
                                         new Scope(ScopeName.Comment, 2, 15),
                                         new Scope(ScopeName.HtmlServerSideScript, 17, 2)
                                     };

                formatter.Write("<%-- a comment --%>", scopes, stubStyleSheet, stubTextWriter);

                Assert.Equal("<span style=\"background-color:Yellow;\">&lt;%</span><span style=\"color:Green;\">-- a comment --</span><span style=\"background-color:Yellow;\">%&gt;</span>", stubTextWriter.Write__buffer);
            }
コード例 #8
0
            public void It_will_write_the_header_with_just_the_foreground_color_if_that_is_all_that_is_in_the_style_sheet()
            {
                HtmlFormatter formatter = new HtmlFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet { Name__getValue = "fnord", Styles__getValue = new StyleDictionary { new Style(ScopeName.PlainText) { Foreground = Color.Black } } };
                StubTextWriter stubTextWriter = new StubTextWriter();

                formatter.WriteHeader(stubStyleSheet, new StubLanguage(), stubTextWriter);

                Assert.Equal("<div style=\"color:Black;\"><pre>", stubTextWriter.Write__buffer);
            }
コード例 #9
0
            public void It_will_write_the_language_name_into_the_header()
            {
                HtmlClassFormatter formatter = new HtmlClassFormatter();

                StubStyleSheet stubStyleSheet = new StubStyleSheet { Name__getValue = "fnord", Styles__getValue = new StyleDictionary { } };
                StubLanguage language = new StubLanguage { CssClassName_getValue = "fnord" };
                StubTextWriter stubTextWriter = new StubTextWriter();

                formatter.WriteHeader(stubStyleSheet, language, stubTextWriter);

                Assert.Equal("<div class=\"fnord\"><pre>", stubTextWriter.Write__buffer);
            }
コード例 #10
0
            public void Will_write_the_header()
            {
                StubLanguageParser stubLanguageParser = new StubLanguageParser();
                CodeColorizer codeColorizer = new CodeColorizer(stubLanguageParser);
                const string sourceCode = "fnord";
                StubFormatter stubFormatter = new StubFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet();
                StubTextWriter stubTextWriter = new StubTextWriter();

                codeColorizer.Colorize(sourceCode, new StubLanguage(), stubFormatter, stubStyleSheet, stubTextWriter);

                Assert.Equal(stubTextWriter, stubFormatter.WriteHeader__textWriter);
                Assert.Equal(stubStyleSheet, stubFormatter.WriteHeader__styleSheet);
            }
コード例 #11
0
            public void Will_write_the_footer()
            {
                StubLanguageParser languageParser = new StubLanguageParser();
                CodeColorizer codeColorizer = new CodeColorizer(languageParser);
                const string sourceCode = "fnord";
                StubFormatter formatter = new StubFormatter();
                StubStyleSheet styleSheet = new StubStyleSheet();
                StubTextWriter writer = new StubTextWriter();

                codeColorizer.Colorize(sourceCode, new StubLanguage(), formatter, styleSheet, writer);

                Assert.Equal(writer, formatter.WriteFooter__writer);
                Assert.Equal(styleSheet, formatter.WriteFooter__styleSheet);
            }
コード例 #12
0
            public void It_will_write_parsed_source_code_with_nested_scopes()
            {
                HtmlClassFormatter formatter = new HtmlClassFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet
                {
                    Name__getValue = "fnord",
                    Styles__getValue = new StyleDictionary
                                       {
                                           new Style(ScopeName.String) { CssClassName = "string" },
                                           new Style(ScopeName.HtmlEntity) { CssClassName = "htmlEntity" }
                                       }
                };
                StubTextWriter stubTextWriter = new StubTextWriter();
                List<Scope> scopes = new List<Scope>
                                     {
                                         new Scope(ScopeName.String, 0, 20)
                                     };
                scopes[0].AddChild(new Scope(ScopeName.HtmlEntity, 0, 6));
                scopes[0].AddChild(new Scope(ScopeName.HtmlEntity, 14, 6));

                formatter.Write("&quot;a string&quot;", scopes, stubStyleSheet, stubTextWriter);

                Assert.Equal("<span class=\"string\"><span class=\"htmlEntity\">&amp;quot;</span>a string<span class=\"htmlEntity\">&amp;quot;</span></span>", stubTextWriter.Write__buffer);
            }
コード例 #13
0
            public void It_will_write_parsed_source_code_with_multiple_scopes()
            {
                HtmlClassFormatter formatter = new HtmlClassFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet
                {
                    Name__getValue = "fnord",
                    Styles__getValue = new StyleDictionary
                                       {
                                           new Style(ScopeName.Keyword) { CssClassName = "keyword" },
                                           new Style(ScopeName.String) { CssClassName = "string" }
                                       }
                };
                StubTextWriter stubTextWriter = new StubTextWriter();
                List<Scope> scopes = new List<Scope>
                                     {
                                         new Scope(ScopeName.Keyword, 0, 4),
                                         new Scope(ScopeName.Keyword, 13, 5)
                                     };

                formatter.Write("bool fnord = false;", scopes, stubStyleSheet, stubTextWriter);

                Assert.Equal("<span class=\"keyword\">bool</span> fnord = <span class=\"keyword\">false</span>;", stubTextWriter.Write__buffer);
            }
コード例 #14
0
            public void It_will_write_encoded_HTML()
            {
                HtmlClassFormatter formatter = new HtmlClassFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet
                {
                    Name__getValue = "fnord",
                    Styles__getValue = new StyleDictionary { new Style(ScopeName.String) { CssClassName = "string" } }
                };
                StubTextWriter stubTextWriter = new StubTextWriter();
                List<Scope> scopes = new List<Scope> { new Scope(ScopeName.String, 0, 10) };

                formatter.Write("\"a string\"", scopes, stubStyleSheet, stubTextWriter);

                Assert.Equal("<span class=\"string\">&quot;a string&quot;</span>", stubTextWriter.Write__buffer);
            }
コード例 #15
0
            public void It_will_write_parsed_source_code_with_no_scopes()
            {
                HtmlFormatter formatter = new HtmlFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet
                                                {
                                                    Name__getValue = "fnord",
                                                    Styles__getValue = new StyleDictionary { new Style(ScopeName.PlainText) { Background = Color.White, Foreground = Color.Black } }
                                                };
                StubTextWriter stubTextWriter = new StubTextWriter();

                formatter.Write("the source code", new List<Scope>(), stubStyleSheet, stubTextWriter);

                Assert.Equal("the source code", stubTextWriter.Write__buffer);
            }
コード例 #16
0
            public void It_will_write_the_header_without_the_plain_text_colors_if_they_are_not_in_the_style_sheet()
            {
                HtmlFormatter formatter = new HtmlFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet { Name__getValue = "fnord", Styles__getValue = new StyleDictionary() };
                StubTextWriter stubTextWriter = new StubTextWriter();

                formatter.WriteHeader(stubStyleSheet, new StubLanguage(), stubTextWriter);

                Assert.Equal("<div><pre>", stubTextWriter.Write__buffer);
            }
コード例 #17
0
            public void It_will_write_the_header_with_no_class_name_if_language_does_not_specify_one()
            {
                HtmlClassFormatter formatter = new HtmlClassFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet { Name__getValue = "fnord", Styles__getValue = new StyleDictionary() };
                StubLanguage stubLanguage = new StubLanguage { CssClassName_getValue = "" };
                StubTextWriter stubTextWriter = new StubTextWriter();

                formatter.WriteHeader(stubStyleSheet, stubLanguage, stubTextWriter);

                Assert.Equal("<div><pre>", stubTextWriter.Write__buffer);
            }