Write() public method

public Write ( string parsedSourceCode, IList scopes, IStyleSheet styleSheet, TextWriter textWriter ) : void
parsedSourceCode string
scopes IList
styleSheet IStyleSheet
textWriter System.IO.TextWriter
return void
Exemplo n.º 1
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);
            }
Exemplo n.º 2
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);
            }
Exemplo n.º 3
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);
            }
Exemplo n.º 4
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);
            }
Exemplo n.º 5
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);
            }
Exemplo n.º 6
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);
            }
            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);
            }
            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);
            }
            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);
            }
            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);
            }
            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);
            }
            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);
            }