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
Esempio 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);
            }
Esempio 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);
            }
Esempio 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);
            }
Esempio 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);
            }
Esempio 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);
            }
Esempio 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);
            }