Example #1
0
        /// <summary>
        /// The code for launchng and displaying the source code submitted to the table
        /// </summary>
        public void ColourCodeCSharp()
        {
            string sourceCode = new CodeColorizer().Colorize(SourceCodeBox.Text, Languages.CSharp);
            string html       = ("<!doctype html><head><meta charset=\"utf-8\" <title> Code Snippet </title> </head> <body>" + sourceCode + "</body></html>");

            System.IO.File.WriteAllText(@"F:\WindowsFormsApplication1\WindowsFormsApplication1\SourceCode.html", html);
        }
Example #2
0
            public void WillStyleSuserSidFunction()
            {
                string sourceText =
                    @"USE AdventureWorks;
GO
CREATE TABLE sid_example
(
login_sid   varbinary(85) DEFAULT SUSER_SID(),
login_name  varchar(30) DEFAULT SYSTEM_USER,
login_dept  varchar(10) DEFAULT 'SALES',
login_date  datetime DEFAULT GETDATE()
) 
GO
INSERT sid_example DEFAULT VALUES
GO";
                string expected =
                    @"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">USE</span> AdventureWorks;
GO
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> sid_example
(
login_sid   <span style=""color:Blue;"">varbinary</span>(85) <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Blue;"">SUSER_SID</span>(),
login_name  <span style=""color:Blue;"">varchar</span>(30) <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Magenta;"">SYSTEM_USER</span>,
login_dept  <span style=""color:Blue;"">varchar</span>(10) <span style=""color:Blue;"">DEFAULT</span> <span style=""color:#A31515;"">'SALES'</span>,
login_date  <span style=""color:Blue;"">datetime</span> <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Magenta;"">GETDATE</span>()
) 
GO
<span style=""color:Blue;"">INSERT</span> sid_example <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Blue;"">VALUES</span>
GO
</pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
Example #3
0
        private static string ColorizeCode(string html)
        {
            var colorizer = new CodeColorizer();
            var sb        = new StringBuilder();
            var pos       = html.IndexOf("<pre><code>", StringComparison.Ordinal);

            if (pos > -1)
            {
                var lastPos = 0;
                sb.Append(html.Substring(0, pos));
                while (pos > -1)
                {
                    lastPos = html.IndexOf("</code></pre>", pos, StringComparison.Ordinal);

                    var snippet          = html.Substring(pos + 11, lastPos - pos - 11);
                    var colorizedSnippet = colorizer.Colorize(snippet, Languages.CSharp);
                    sb.Append(colorizedSnippet);

                    pos = html.IndexOf("<pre><code>", lastPos, StringComparison.Ordinal);
                }

                sb.Append(html.Substring(lastPos + 13));
                html = sb.ToString();
            }

            return(html);
        }
Example #4
0
            public void WillStyleAMethodWithoutArguments()
            {
                string source =
                @"using System;

                namespace TheNamespace
                {
                /* This is a comment */
                public class TheClass
                : TheBaseClass, Implements
                {
                public string AMethod()
                {
                return ""Hello World!"";
                }
                }
                }";

                string expected =
                    "<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"color:Blue;\">using</span> System;\r\n\r\n<span style=\"color:Blue;\">namespace</span> TheNamespace\r\n{\r\n    <span style=\"color:Green;\">/* This is a comment */</span>\r\n    <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">class</span> TheClass\r\n        : TheBaseClass, Implements\r\n    {\r\n        <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">string</span> AMethod()\r\n        {\r\n            <span style=\"color:Blue;\">return</span> <span style=\"color:#A31515;\">&quot;Hello World!&quot;</span>;\r\n        }\r\n    }\r\n}\r\n</pre></div>";

                string actual = new CodeColorizer().Colorize(source, Languages.CSharp);

                Assert.Equal(expected, actual);
            }
        private void SaveColorizedStep(string file)
        {
            var content = File.ReadAllText(file);
            var html    = file + ".htm";
            var css     = (StyleSheets.Default as DefaultStyleSheet).GetCssFile();;

            using (var w = File.CreateText(html))
            {
                w.WriteLine(@"<!DOCTYPE html>
                    <html lang=""en"">
                      <head>
                        <meta charset = ""utf-8"">
                        <title>" + Path.GetFileNameWithoutExtension(file) + @"</title>
                        <style>" + css + @"

                        .step .number {
                            color: red;
                        }
                        .type {
                            color: blue;
                        }
                        </style>
                      </head>
                      <body>");

                var cc = new CodeColorizer();
                cc.Colorize(content, Languages.Step, new HtmlClassFormatter(), StyleSheets.Default, w);

                w.WriteLine(@"</body></html>");
                w.Close();
            }
        }
            public void WillStyleColLengthFunction()
            {
                string sourceText =
                @"USE AdventureWorks;
                GO
                CREATE TABLE t1
                (c1 varchar(40),
                c2 nvarchar(40)
                );
                GO
                SELECT COL_LENGTH('t1','c1')AS 'VarChar',
                COL_LENGTH('t1','c2')AS 'NVarChar';
                GO
                DROP TABLE t1;";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> t1
                (c1 <span style=""color:Blue;"">varchar</span>(40),
                c2 <span style=""color:Blue;"">nvarchar</span>(40)
                );
                GO
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">COL_LENGTH</span>(<span style=""color:#A31515;"">'t1'</span>,<span style=""color:#A31515;"">'c1'</span>)<span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'VarChar'</span>,
                <span style=""color:Blue;"">COL_LENGTH</span>(<span style=""color:#A31515;"">'t1'</span>,<span style=""color:#A31515;"">'c2'</span>)<span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'NVarChar'</span>;
                GO
                <span style=""color:Blue;"">DROP</span> <span style=""color:Blue;"">TABLE</span> t1;
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleElementsWithNamespace()
            {
                string source =
                @"<asp:DropDownList ID=""StateList"" runat=""server"">
                <asp:ListItem>CA</asp:ListItem>
                <asp:ListItem>IN</asp:ListItem>
                <asp:ListItem>KS</asp:ListItem>
                <asp:ListItem>MD</asp:ListItem>
                <asp:ListItem>MI</asp:ListItem>
                <asp:ListItem>OR</asp:ListItem>
                <asp:ListItem>TN</asp:ListItem>
                <asp:ListItem>UT</asp:ListItem>
                </asp:DropDownList>";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DropDownList</span> <span style=""color:Red;"">ID</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">&quot;StateList&quot;</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">&quot;server&quot;</span><span style=""color:Blue;"">&gt;</span>
                <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>CA<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
                <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>IN<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
                <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>KS<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
                <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>MD<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
                <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>MI<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
                <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>OR<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
                <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>TN<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
                <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>UT<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
                <span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DropDownList</span><span style=""color:Blue;"">&gt;</span>
                </pre></div>";

                string actual = new CodeColorizer().Colorize(source, GetGrammar());

                Assert.Equal(expected, actual);
            }
            public void WillStyleKnownAttributeTargets()
            {
                string source =
                    @"[assembly: SomeAttribute]
[module: SomeAttribute]
[type: SomeAttribute]
[return: SomeAttribute]
[param: SomeAttribute]
[method: SomeAttribute]
[field: SomeAttribute]
[property: SomeAttribute]
[event: SomeAttribute]";
                string expected =
                    @"<div style=""color:Black;background-color:White;""><pre>
[<span style=""color:Blue;"">assembly</span>: SomeAttribute]
[<span style=""color:Blue;"">module</span>: SomeAttribute]
[<span style=""color:Blue;"">type</span>: SomeAttribute]
[<span style=""color:Blue;"">return</span>: SomeAttribute]
[<span style=""color:Blue;"">param</span>: SomeAttribute]
[<span style=""color:Blue;"">method</span>: SomeAttribute]
[<span style=""color:Blue;"">field</span>: SomeAttribute]
[<span style=""color:Blue;"">property</span>: SomeAttribute]
[<span style=""color:Blue;"">event</span>: SomeAttribute]
</pre></div>";

                string actual = new CodeColorizer().Colorize(source, Languages.CSharp);

                Assert.Equal(expected, actual);
            }
Example #9
0
            public void WillStyleCreateAssembly()
            {
                string sourceText =
                    @"DECLARE @SamplesPath nvarchar(1024)
SELECT @SamplesPath = REPLACE(physical_name, 
    'Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf', 
    'Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\') 
FROM master.sys.database_files 
WHERE name = 'master';
CREATE ASSEMBLY HelloWorld 
FROM @SamplesPath + 'HelloWorld\CS\HelloWorld\bin\debug\HelloWorld.dll'
WITH PERMISSION_SET = SAFE;";
                string expected =
                    @"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">DECLARE</span> @SamplesPath <span style=""color:Blue;"">nvarchar</span>(1024)
<span style=""color:Blue;"">SELECT</span> @SamplesPath = <span style=""color:Magenta;"">REPLACE</span>(physical_name, 
    <span style=""color:#A31515;"">&#39;Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf&#39;</span>, 
    <span style=""color:#A31515;"">&#39;Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\&#39;</span>) 
<span style=""color:Blue;"">FROM</span> master.sys.database_files 
<span style=""color:Blue;"">WHERE</span> <span style=""color:Blue;"">name</span> = <span style=""color:#A31515;"">&#39;master&#39;</span>;
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">ASSEMBLY</span> HelloWorld 
<span style=""color:Blue;"">FROM</span> @SamplesPath + <span style=""color:#A31515;"">&#39;HelloWorld\CS\HelloWorld\bin\debug\HelloWorld.dll&#39;</span>
<span style=""color:Blue;"">WITH</span> PERMISSION_SET = SAFE;
</pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
Example #10
0
            public void WillStyleAMethodWithoutArguments()
            {
                string source =
                    @"using System;

namespace TheNamespace
{
    /* This is a comment */
    public class TheClass
        : TheBaseClass, Implements
    {
        public string AMethod()
        {
            return ""Hello World!"";
        }
    }
}";

                string expected =
                    "<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"color:Blue;\">using</span> System;\r\n\r\n<span style=\"color:Blue;\">namespace</span> TheNamespace\r\n{\r\n    <span style=\"color:Green;\">/* This is a comment */</span>\r\n    <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">class</span> TheClass\r\n        : TheBaseClass, Implements\r\n    {\r\n        <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">string</span> AMethod()\r\n        {\r\n            <span style=\"color:Blue;\">return</span> <span style=\"color:#A31515;\">&quot;Hello World!&quot;</span>;\r\n        }\r\n    }\r\n}\r\n</pre></div>";

                string actual = new CodeColorizer().Colorize(source, Languages.CSharp);

                Assert.Equal(expected, actual);
            }
Example #11
0
        /// <summary>
        ///  Search and return bug information from the table to
        ///  the developer display the information in the corresponding feilds
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            String        sqlCon = (@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\vs\Debugger\BugDatabase.mdf;Integrated Security=True;Connect Timeout=30");
            SqlConnection con    = new SqlConnection(sqlCon);

            con.Open();
            SqlCommand    selcmd          = new SqlCommand("SELECT BugID, ApplicationName, BugSymptoms,BugTrigger,ProjectName,SourceFile,ClassName,LineNumber,Method,CodeBlock, CodeAuthor, SourceCode, Name, Date, Comment FROM BugTable WHERE BugID ='" + txtBugID.Text + "'", con); // select all bug information on the row form bug id
            SqlDataReader mySqlDataReader = selcmd.ExecuteReader();

            while (mySqlDataReader.Read())                                                                                                                                               // While there is data in the row display the data to the user
            {
                lsBug.Items.Clear();

                lsBug.Items.Add(("Bug ID:                   ") + mySqlDataReader["BugID"].ToString());
                lsBug.Items.Add(("ApplicationName:   ") + mySqlDataReader["ApplicationName"].ToString());
                lsBug.Items.Add(("Bug Stmptoms:       ") + mySqlDataReader["BugSymptoms"].ToString());
                lsBug.Items.Add(("Bug Trigger:           ") + mySqlDataReader["BugTrigger"].ToString());
                lsBug.Items.Add(("Project Name:        ") + mySqlDataReader["ProjectName"].ToString());
                lsBug.Items.Add(("Source File:            ") + mySqlDataReader["SourceFile"].ToString());
                lsBug.Items.Add(("Class Name:           ") + mySqlDataReader["ClassName"].ToString());
                lsBug.Items.Add(("Line Number:          ") + mySqlDataReader["LineNumber"].ToString());
                lsBug.Items.Add(("Method:                  ") + mySqlDataReader["Method"].ToString());
                lsBug.Items.Add(("CodeBlock:            ") + mySqlDataReader["CodeBlock"].ToString());
                lsBug.Items.Add(("Code Author:          ") + mySqlDataReader["CodeAuthor"].ToString());

                txtSourceCode.Text = mySqlDataReader["SourceCode"].ToString();
                String sourceCode       = mySqlDataReader["SourceCode"].ToString();
                string colourSourceCode = new CodeColorizer().Colorize(sourceCode, Languages.CSharp);                                                                                   // Format Source code with colour for c# code with the colour code libary
                string html             = ("<!doctype html><head><meta charset=\"utf-8\" <title> Code Snippet </title> </head> <body>" + colourSourceCode + "</body></html>");
                webColourCode.DocumentText = html;
            }
            con.Close();
        }
Example #12
0
        public void TestOperators()
        {
            CodeColorizer colorizer = GetColorizer(LanguageRules);

            colorizer.Options.TokenFormat = "{1}";
            Assert.AreEqual(" a operator b operator c ", colorizer.Transform(" a = b * c "));
        }
            public void WillStyleIndexColFunction()
            {
                string sourceText =
@"USE AdventureWorks;
GO
SELECT 
    INDEX_COL (N'AdventureWorks.Sales.SalesOrderDetail', 1,1) AS
        [CaptureIndex Column 1], 
    INDEX_COL (N'AdventureWorks.Sales.SalesOrderDetail', 1,2) AS
        [CaptureIndex Column 2]
;
GO";
                string expected =
@"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">USE</span> AdventureWorks;
GO
<span style=""color:Blue;"">SELECT</span> 
    <span style=""color:Blue;"">INDEX_COL</span> (N<span style=""color:#A31515;"">&#39;AdventureWorks.Sales.SalesOrderDetail&#39;</span>, 1,1) <span style=""color:Blue;"">AS</span>
        [CaptureIndex Column 1], 
    <span style=""color:Blue;"">INDEX_COL</span> (N<span style=""color:#A31515;"">&#39;AdventureWorks.Sales.SalesOrderDetail&#39;</span>, 1,2) <span style=""color:Blue;"">AS</span>
        [CaptureIndex Column 2]
;
GO
</pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
        private string ApplySyntaxHighlighting(string languageMoniker, string firstLine, string code, bool useDefault)
        {
            var languageTypeAdapter = new LanguageTypeAdapter();
            var language            = languageTypeAdapter.Parse(languageMoniker, firstLine);

            if (language == null)
            { //handle unrecognised language formats, e.g. when using mermaid diagrams
                if (useDefault)
                {
                    language = FakeIt();
                }
                else
                {
                    return(code);
                }
            }

            var codeBuilder = new StringBuilder();
            var codeWriter  = new StringWriter(codeBuilder);
            var styleSheet  = _customCss ?? StyleSheets.Default;
            var colourizer  = new CodeColorizer();

            colourizer.Colorize(code, language, Formatters.Default, styleSheet, codeWriter);
            return(codeBuilder.ToString());
        }
Example #15
0
        public void TestKeywords()
        {
            CodeColorizer colorizer = GetColorizer(LanguageRules);

            colorizer.Options.TokenFormat = "{1}";
            Assert.AreEqual(" keyword i ", colorizer.Transform(" int i "));
        }
            public void WillStyleKnownAttributeTargets()
            {
                string source =
                @"[assembly: SomeAttribute]
                [module: SomeAttribute]
                [type: SomeAttribute]
                [return: SomeAttribute]
                [param: SomeAttribute]
                [method: SomeAttribute]
                [field: SomeAttribute]
                [property: SomeAttribute]
                [event: SomeAttribute]";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                [<span style=""color:Blue;"">assembly</span>: SomeAttribute]
                [<span style=""color:Blue;"">module</span>: SomeAttribute]
                [<span style=""color:Blue;"">type</span>: SomeAttribute]
                [<span style=""color:Blue;"">return</span>: SomeAttribute]
                [<span style=""color:Blue;"">param</span>: SomeAttribute]
                [<span style=""color:Blue;"">method</span>: SomeAttribute]
                [<span style=""color:Blue;"">field</span>: SomeAttribute]
                [<span style=""color:Blue;"">property</span>: SomeAttribute]
                [<span style=""color:Blue;"">event</span>: SomeAttribute]
                </pre></div>";

                string actual = new CodeColorizer().Colorize(source, Languages.CSharp);

                Assert.Equal(expected, actual);
            }
Example #17
0
        /// <summary>
        ///  Display information of the bug the developer when clicked in the corresponding fileds
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            lsBug.Items.Clear();
            if (e.RowIndex != -1)                                                                                                                           // Stop the user form selecting the menu bar.
            {
                dataGridViewDeveloper.ReadOnly = true;                                                                                                      // // Stop  the user entering data to the data grid view.

                String sourceCode       = dataGridViewDeveloper.Rows[e.RowIndex].Cells[11].Value.ToString();
                string colourSourceCode = new CodeColorizer().Colorize(sourceCode, Languages.CSharp);
                string html             = ("<!doctype html><head><meta charset=\"utf-8\" <title> Code Snippet </title> </head> <body>" + colourSourceCode + "</body></html>");
                webColourCode.DocumentText = html;

                txtBugID.Text = dataGridViewDeveloper.Rows[e.RowIndex].Cells[0].Value.ToString();                                                          // Display information about the bug from the clicked cell.

                lsBug.Items.Add(("Bug ID:                 ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[0].Value.ToString());
                lsBug.Items.Add(("ApplicationName: ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[1].Value.ToString());
                lsBug.Items.Add(("Bug Stmptoms:     ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[2].Value.ToString());
                lsBug.Items.Add(("Bug Trigger:         ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[3].Value.ToString());
                lsBug.Items.Add(("Project Name:      ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[4].Value.ToString());
                lsBug.Items.Add(("Source File:         ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[5].Value.ToString());
                lsBug.Items.Add(("Class Name:        ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[6].Value.ToString());
                lsBug.Items.Add(("Line Number:      ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[7].Value.ToString());
                lsBug.Items.Add(("Method:               ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[8].Value.ToString());
                lsBug.Items.Add(("Code Block:        ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[9].Value.ToString());
                lsBug.Items.Add(("Code Author:       ") + dataGridViewDeveloper.Rows[e.RowIndex].Cells[10].Value.ToString());

                txtSourceCode.Text = dataGridViewDeveloper.Rows[e.RowIndex].Cells[11].Value.ToString();
            }
            else
            {
                return;
            }
        }
Example #18
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //String path;
            OpenFileDialog file = new OpenFileDialog();

            if (file.ShowDialog() == DialogResult.OK)
            {
                //path = file.FileName;

                //richTextBox1.LoadFile(file.FileName, RichTextBoxStreamType.PlainText);

                string sourceCode = File.ReadAllText(file.FileName);

                string colorizedSourceCode = new CodeColorizer().Colorize(sourceCode, Languages.CSharp);

                //webBrowser1.Text = colorizedSourceCode;

                webBrowser1.DocumentText = colorizedSourceCode;

                webBrowser1.DocumentText = "<HTML><BODY contentEditable='true'></BODY></HTML>";

                System.IO.StreamReader txtReader;
                txtReader = new System.IO.StreamReader(file.FileName);
                webBrowser1.DocumentText = txtReader.ReadToEnd();
                txtReader.Close();
                txtReader = null;
                HtmlDocument doc = webBrowser1.Document.OpenNew(false);
                doc.ExecCommand("EditMode", false, null);
            }
        }
        /// <summary>
        /// Formats the code with proper syntax colours according to user selection of Programming Language and
        /// outputs it to the SyntaxedCode class which has a Web Browser that can display it.
        /// Furthermore, writes the formatted code to an .html file.
        /// </summary>
        public void ColourizeCode()
        {
            String colourizedSource;
            String path = Application.StartupPath + "\\FormattedCode.html";

            if (radioCSharp.Checked)
            {
                colourizedSource = new CodeColorizer().Colorize(txtSourceCode.Text, Languages.CSharp);
            }
            else if (radioHTML.Checked)
            {
                colourizedSource = new CodeColorizer().Colorize(txtSourceCode.Text, Languages.Html);
            }
            else
            {
                colourizedSource = new CodeColorizer().Colorize(txtSourceCode.Text, Languages.Java);
            }

            // Wrap the code in HTML.
            String html = ("<!doctype html><head><meta charset=\"utf-8\"</head><body>" + colourizedSource + "</body></html>");

            System.IO.File.WriteAllText(@path, html);
            MessageBox.Show("File Written to " + path, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            Uri uri = new Uri(path);

            // Opens up the code in the SyntaxedCode class and displays it formatted.
            SyntaxedCode formattedCode = new SyntaxedCode(uri);

            formattedCode.Show();
        }
Example #20
0
        public void TestCaseSensitivity()
        {
            LanguageRules.Symbols = new List <string>()
            {
                "abc"
            };

            CodeColorizer colorizer = GetColorizer(LanguageRules);

            colorizer.Options.TokenFormat = "{1}";
            Assert.AreEqual(" INT i ", colorizer.Transform(" INT i "));
            Assert.AreEqual(" ABC def ", colorizer.Transform(" ABC def "));

            LanguageRules.CaseSensitive = false;
            LanguageRules.Symbols       = new List <string>()
            {
                "abc"
            };
            colorizer = GetColorizer(LanguageRules);
            colorizer.Options.TokenFormat = "{1}";
            Assert.AreEqual(" keyword i ", colorizer.Transform(" INT i "));
            Assert.AreEqual(" symbol def ", colorizer.Transform(" ABC def "));

            LanguageRules.Symbols       = null;
            LanguageRules.CaseSensitive = true;
        }
            public void WillStyleIndexkeyPropertyFunction()
            {
                string sourceText =
@"USE AdventureWorks;
GO
SELECT 
    INDEXKEY_PROPERTY(OBJECT_ID('Production.Location', 'U'),
        1,1,'ColumnId') AS [Column ID],
    INDEXKEY_PROPERTY(OBJECT_ID('Production.Location', 'U'),
        1,1,'IsDescending') AS [Asc or Desc order];";
                string expected =
@"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">USE</span> AdventureWorks;
GO
<span style=""color:Blue;"">SELECT</span> 
    <span style=""color:Blue;"">INDEXKEY_PROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">&#39;Production.Location&#39;</span>, <span style=""color:#A31515;"">&#39;U&#39;</span>),
        1,1,<span style=""color:#A31515;"">&#39;ColumnId&#39;</span>) <span style=""color:Blue;"">AS</span> [Column ID],
    <span style=""color:Blue;"">INDEXKEY_PROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">&#39;Production.Location&#39;</span>, <span style=""color:#A31515;"">&#39;U&#39;</span>),
        1,1,<span style=""color:#A31515;"">&#39;IsDescending&#39;</span>) <span style=""color:Blue;"">AS</span> [Asc or Desc order];
</pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleTextPtrFunction()
            {
                string sourceText =
                @"USE pubs
                GO
                DECLARE @ptrval varbinary(16)
                SELECT @ptrval = TEXTPTR(logo)
                FROM pub_info pr, publishers p
                WHERE p.pub_id = pr.pub_id
                AND p.pub_name = 'New Moon Books'
                GO";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> pubs
                GO
                <span style=""color:Blue;"">DECLARE</span> @ptrval <span style=""color:Blue;"">varbinary</span>(16)
                <span style=""color:Blue;"">SELECT</span> @ptrval = <span style=""color:Blue;"">TEXTPTR</span>(logo)
                <span style=""color:Blue;"">FROM</span> pub_info pr, publishers p
                <span style=""color:Blue;"">WHERE</span> p.pub_id = pr.pub_id
                <span style=""color:Blue;"">AND</span> p.pub_name = <span style=""color:#A31515;"">'New Moon Books'</span>
                GO
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleTextValidFunction()
            {
                string sourceText =
                    @"USE pubs;
GO
SELECT pub_id, 'Valid (if 1) Regex data' 
 = TEXTVALID ('pub_info.logo', TEXTPTR(logo)) 
FROM pub_info
ORDER BY pub_id;
GO";
                string expected =
                    @"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">USE</span> pubs;
GO
<span style=""color:Blue;"">SELECT</span> pub_id, <span style=""color:#A31515;"">'Valid (if 1) Regex data'</span> 
 = <span style=""color:Blue;"">TEXTVALID</span> (<span style=""color:#A31515;"">'pub_info.logo'</span>, <span style=""color:Blue;"">TEXTPTR</span>(logo)) 
<span style=""color:Blue;"">FROM</span> pub_info
<span style=""color:Blue;"">ORDER</span> <span style=""color:Blue;"">BY</span> pub_id;
GO
</pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleTextPtrFunction()
            {
                string sourceText =
                    @"USE pubs
GO
DECLARE @ptrval varbinary(16)
SELECT @ptrval = TEXTPTR(logo) 
FROM pub_info pr, publishers p
WHERE p.pub_id = pr.pub_id
    AND p.pub_name = 'New Moon Books'
GO";
                string expected =
                    @"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">USE</span> pubs
GO
<span style=""color:Blue;"">DECLARE</span> @ptrval <span style=""color:Blue;"">varbinary</span>(16)
<span style=""color:Blue;"">SELECT</span> @ptrval = <span style=""color:Blue;"">TEXTPTR</span>(logo) 
<span style=""color:Blue;"">FROM</span> pub_info pr, publishers p
<span style=""color:Blue;"">WHERE</span> p.pub_id = pr.pub_id
    <span style=""color:Blue;"">AND</span> p.pub_name = <span style=""color:#A31515;"">'New Moon Books'</span>
GO
</pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleSqlVariantPropertyFunction()
            {
                string sourceText =
@"CREATE TABLE tableA(colA sql_variant, colB int)
INSERT INTO tableA values ( cast (46279.1 as decimal(8,2)), 1689)
SELECT SQL_VARIANT_PROPERTY(colA,'BaseType') AS 'Base Type',
       SQL_VARIANT_PROPERTY(colA,'Precision') AS 'Precision',
       SQL_VARIANT_PROPERTY(colA,'Scale') AS 'Scale'
FROM tableA
WHERE colB = 1689";
                string expected =
@"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> tableA(colA <span style=""color:Magenta;"">sql_variant</span>, colB <span style=""color:Blue;"">int</span>)
<span style=""color:Blue;"">INSERT</span> <span style=""color:Blue;"">INTO</span> tableA <span style=""color:Blue;"">values</span> ( <span style=""color:Magenta;"">cast</span> (46279.1 <span style=""color:Blue;"">as</span> <span style=""color:Blue;"">decimal</span>(8,2)), 1689)
<span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">SQL_VARIANT_PROPERTY</span>(colA,<span style=""color:#A31515;"">&#39;BaseType&#39;</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">&#39;Base Type&#39;</span>,
       <span style=""color:Magenta;"">SQL_VARIANT_PROPERTY</span>(colA,<span style=""color:#A31515;"">&#39;Precision&#39;</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">&#39;Precision&#39;</span>,
       <span style=""color:Magenta;"">SQL_VARIANT_PROPERTY</span>(colA,<span style=""color:#A31515;"">&#39;Scale&#39;</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">&#39;Scale&#39;</span>
<span style=""color:Blue;"">FROM</span> tableA
<span style=""color:Blue;"">WHERE</span> colB = 1689
</pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleColLengthFunction()
            {
                string sourceText =
@"USE AdventureWorks;
GO
CREATE TABLE t1
    (c1 varchar(40),
    c2 nvarchar(40)
    );
GO
SELECT COL_LENGTH('t1','c1')AS 'VarChar',
    COL_LENGTH('t1','c2')AS 'NVarChar';
GO
DROP TABLE t1;";
                string expected =
@"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">USE</span> AdventureWorks;
GO
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> t1
    (c1 <span style=""color:Blue;"">varchar</span>(40),
    c2 <span style=""color:Blue;"">nvarchar</span>(40)
    );
GO
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">COL_LENGTH</span>(<span style=""color:#A31515;"">&#39;t1&#39;</span>,<span style=""color:#A31515;"">&#39;c1&#39;</span>)<span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">&#39;VarChar&#39;</span>,
    <span style=""color:Blue;"">COL_LENGTH</span>(<span style=""color:#A31515;"">&#39;t1&#39;</span>,<span style=""color:#A31515;"">&#39;c2&#39;</span>)<span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">&#39;NVarChar&#39;</span>;
GO
<span style=""color:Blue;"">DROP</span> <span style=""color:Blue;"">TABLE</span> t1;
</pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleIndexpropertyFunction()
            {
                string sourceText =
@"USE AdventureWorks;
GO
SELECT 
    INDEXPROPERTY(OBJECT_ID('HumanResources.Employee'),
        'PK_Employee_EmployeeID','IsClustered')AS [Is Clustered],
    INDEXPROPERTY(OBJECT_ID('HumanResources.Employee'),
        'PK_Employee_EmployeeID','IndexDepth') AS [CaptureIndex Depth],
    INDEXPROPERTY(OBJECT_ID('HumanResources.Employee'),
        'PK_Employee_EmployeeID','IndexFillFactor') AS [Fill Factor];
GO";
                string expected =
@"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">USE</span> AdventureWorks;
GO
<span style=""color:Blue;"">SELECT</span> 
    <span style=""color:Blue;"">INDEXPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">&#39;HumanResources.Employee&#39;</span>),
        <span style=""color:#A31515;"">&#39;PK_Employee_EmployeeID&#39;</span>,<span style=""color:#A31515;"">&#39;IsClustered&#39;</span>)<span style=""color:Blue;"">AS</span> [Is Clustered],
    <span style=""color:Blue;"">INDEXPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">&#39;HumanResources.Employee&#39;</span>),
        <span style=""color:#A31515;"">&#39;PK_Employee_EmployeeID&#39;</span>,<span style=""color:#A31515;"">&#39;IndexDepth&#39;</span>) <span style=""color:Blue;"">AS</span> [CaptureIndex Depth],
    <span style=""color:Blue;"">INDEXPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">&#39;HumanResources.Employee&#39;</span>),
        <span style=""color:#A31515;"">&#39;PK_Employee_EmployeeID&#39;</span>,<span style=""color:#A31515;"">&#39;IndexFillFactor&#39;</span>) <span style=""color:Blue;"">AS</span> [Fill Factor];
GO
</pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
Example #28
0
            public void WillStyleClass()
            {
                string source =
                    @"<%@ Webhandler Language=""C#"" CodeBehind=""Global.asax.cs"" Inherits=""Microsoft.Foundation.Web.Global"" %>
<script runat=""server"">
using System.IO;
using System.Text;
using System.Web;
using CodePlex.Common;
using CodePlex.Presentation.Compression;
using CodePlex.Presentation.Css.Presenter;
using CodePlex.Presentation.Navigation;

namespace CodePlex.WebSite.Css
{
    /// <summary>
    /// StyleSheet.ashx parses and delivers css files submitted through the QueryString
    /// It replaces constants described by the css file in the form 
    /// 
    ///     /*{css:ConstantName}*/
    /// 
    /// with the correspondingly named AppSetting Key from the containing directory's .config file
    /// </summary>
    public class StyleSheet : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = ""text/css"";
            if (context.Request.QueryString[""i""] == null)
                return;

            string[] cssFiles;
            cssFiles = css.ToString().Split(',');
            for (int i = 0; i < cssFiles.Length; i++)
            {
                cssFiles[i] = Path.GetFileName(cssFiles[i].Trim());
                if (!Path.HasExtension(cssFiles[i]))
                    cssFiles[i] = Path.ChangeExtension(cssFiles[i], "".css"");
            }

            //Cache settings handled in AddHeaderItemsToRequestModule
            //bool alreadyCached;
            //CompressionUtility.SetCaching(context, cssFiles, out alreadyCached);
            //if (alreadyCached)
            //    return;
        }

        public bool IsReusable
        {
            get { return false; }
        }
    }
}
</script>";
                string expected =
                    "<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"background-color:Yellow;\">&lt;%</span><span style=\"color:Blue;\">@</span> <span style=\"color:#A31515;\">Webhandler</span> <span style=\"color:Red;\">Language</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">&quot;C#&quot;</span> <span style=\"color:Red;\">CodeBehind</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">&quot;Global.asax.cs&quot;</span> <span style=\"color:Red;\">Inherits</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">&quot;Microsoft.Foundation.Web.Global&quot;</span> <span style=\"background-color:Yellow;\">%&gt;</span>\r\n&lt;script runat=<span style=\"color:#A31515;\">&quot;server&quot;</span>&gt;\r\n<span style=\"color:Blue;\">using</span> System.IO;\r\n<span style=\"color:Blue;\">using</span> System.Text;\r\n<span style=\"color:Blue;\">using</span> System.Web;\r\n<span style=\"color:Blue;\">using</span> CodePlex.Common;\r\n<span style=\"color:Blue;\">using</span> CodePlex.Presentation.Compression;\r\n<span style=\"color:Blue;\">using</span> CodePlex.Presentation.Css.Presenter;\r\n<span style=\"color:Blue;\">using</span> CodePlex.Presentation.Navigation;\r\n\r\n<span style=\"color:Blue;\">namespace</span> CodePlex.WebSite.Css\r\n{\r\n    <span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\">&lt;summary&gt;</span>\r\n    <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> StyleSheet.ashx parses and delivers css files submitted through the QueryString</span>\r\n    <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> It replaces constants described by the css file in the form </span>\r\n    <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> </span>\r\n    <span style=\"color:Gray;\">///</span><span style=\"color:Green;\">     /*{css:ConstantName}*/</span>\r\n    <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> </span>\r\n    <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> with the correspondingly named AppSetting Key from the containing directory's .config file</span>\r\n    <span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\">&lt;/summary&gt;</span>\r\n    <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">class</span> StyleSheet : IHttpHandler\r\n    {\r\n        <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">void</span> ProcessRequest(HttpContext context)\r\n        {\r\n            context.Response.ContentType = <span style=\"color:#A31515;\">&quot;text/css&quot;</span>;\r\n            <span style=\"color:Blue;\">if</span> (context.Request.QueryString[<span style=\"color:#A31515;\">&quot;i&quot;</span>] == <span style=\"color:Blue;\">null</span>)\r\n                <span style=\"color:Blue;\">return</span>;\r\n\r\n            <span style=\"color:Blue;\">string</span>[] cssFiles;\r\n            cssFiles = css.ToString().Split(<span style=\"color:#A31515;\">','</span>);\r\n            <span style=\"color:Blue;\">for</span> (<span style=\"color:Blue;\">int</span> i = 0; i &lt; cssFiles.Length; i++)\r\n            {\r\n                cssFiles[i] = Path.GetFileName(cssFiles[i].Trim());\r\n                <span style=\"color:Blue;\">if</span> (!Path.HasExtension(cssFiles[i]))\r\n                    cssFiles[i] = Path.ChangeExtension(cssFiles[i], <span style=\"color:#A31515;\">&quot;.css&quot;</span>);\r\n            }\r\n\r\n            <span style=\"color:Green;\">//Cache settings handled in AddHeaderItemsToRequestModule</span>\r\n            <span style=\"color:Green;\">//bool alreadyCached;</span>\r\n            <span style=\"color:Green;\">//CompressionUtility.SetCaching(context, cssFiles, out alreadyCached);</span>\r\n            <span style=\"color:Green;\">//if (alreadyCached)</span>\r\n            <span style=\"color:Green;\">//    return;</span>\r\n        }\r\n\r\n        <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">bool</span> IsReusable\r\n        {\r\n            <span style=\"color:Blue;\">get</span> { <span style=\"color:Blue;\">return</span> <span style=\"color:Blue;\">false</span>; }\r\n        }\r\n    }\r\n}\r\n&lt;/script&gt;\r\n</pre></div>";
                string actual = new CodeColorizer().Colorize(source, GetGrammar());

                Assert.Equal(expected, actual);
            }
Example #29
0
            public void WillStyleElementsWithNamespace()
            {
                string source =
                    @"<asp:DropDownList ID=""StateList"" runat=""server"">
    <asp:ListItem>CA</asp:ListItem>
    <asp:ListItem>IN</asp:ListItem>
    <asp:ListItem>KS</asp:ListItem>
    <asp:ListItem>MD</asp:ListItem>
    <asp:ListItem>MI</asp:ListItem>
    <asp:ListItem>OR</asp:ListItem>
    <asp:ListItem>TN</asp:ListItem>
    <asp:ListItem>UT</asp:ListItem>
</asp:DropDownList>";
                string expected =
                    @"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DropDownList</span> <span style=""color:Red;"">ID</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">&quot;StateList&quot;</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">&quot;server&quot;</span><span style=""color:Blue;"">&gt;</span>
    <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>CA<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
    <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>IN<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
    <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>KS<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
    <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>MD<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
    <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>MI<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
    <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>OR<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
    <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>TN<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
    <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>UT<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">&gt;</span>
<span style=""color:Blue;"">&lt;/</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DropDownList</span><span style=""color:Blue;"">&gt;</span>
</pre></div>";

                string actual = new CodeColorizer().Colorize(source, GetGrammar());

                Assert.Equal(expected, actual);
            }
            public void WillStyleDbNameFunction()
            {
                string sourceText =
@"SELECT DB_NAME() AS [Current Database];
GO

USE master;
GO
SELECT DB_NAME(3)AS [Database StyleName];
GO";
                string expected =
@"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">DB_NAME</span>() <span style=""color:Blue;"">AS</span> [Current Database];
GO

<span style=""color:Blue;"">USE</span> master;
GO
<span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">DB_NAME</span>(3)<span style=""color:Blue;"">AS</span> [Database StyleName];
GO
</pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
        public void WillStyleHeaderWithKeywords()
        {
            string source = @"<%@ Application Language=""C#"" CodeBehind=""Global.asax.cs"" Inherits=""Microsoft.Foundation.Web.Global"" %><script runat=""server"">bool public false</script>";
            string expected = "<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"background-color:Yellow;\">&lt;%</span><span style=\"color:Blue;\">@</span> <span style=\"color:#A31515;\">Application</span> <span style=\"color:Red;\">Language</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">&quot;C#&quot;</span> <span style=\"color:Red;\">CodeBehind</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">&quot;Global.asax.cs&quot;</span> <span style=\"color:Red;\">Inherits</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">&quot;Microsoft.Foundation.Web.Global&quot;</span> <span style=\"background-color:Yellow;\">%&gt;</span><span style=\"color:Blue;\">&lt;</span><span style=\"color:#A31515;\">script</span> <span style=\"color:Red;\">runat</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">&quot;server&quot;</span><span style=\"color:Blue;\">&gt;</span><span style=\"color:Blue;\">bool</span> <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">false</span><span style=\"color:Blue;\">&lt;/</span><span style=\"color:#A31515;\">script</span><span style=\"color:Blue;\">&gt;</span>\r\n</pre></div>";

            string actual = new CodeColorizer().Colorize(source, GetGrammar());
            Assert.Equal(expected, actual);
        }
Example #32
0
        /// <summary>
        ///  Display the users editable source code
        ///  formatted and colour coded in a web browser
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEditSourceCode_Click(object sender, EventArgs e)
        {
            String editedSourceCode = txtSourceCode.Text;
            string colourSourceCode = new CodeColorizer().Colorize(editedSourceCode, Languages.CSharp);          // Format source code with colour for c# code with the colour code libary
            string html             = ("<!doctype html><head><meta charset=\"utf-8\" <title> Code Snippet </title> </head> <body>" + colourSourceCode + "</body></html>");

            webColourCode.DocumentText = html;
        }
Example #33
0
        /// <summary>
        /// Colour codes the source code in the style of Java and shows this in a web broswer
        /// </summary>
        public void ColourCodeJava()
        {
            string colourizedSourceCode = new CodeColorizer().Colorize(txtSourceCodeView.Text, Languages.Java);

            string html = ("<!doctype html><head><meta charset=\"utf-8\" <title> Coloured Code </title> </head> <body>" + colourizedSourceCode + "</body></html>");

            sourceCodeWebView.DocumentText = html;
        }
Example #34
0
        public void TestComments()
        {
            CodeColorizer colorizer = GetColorizer(LanguageRules);

            colorizer.Options.TokenFormat = "{1}";
            Assert.AreEqual(" comment", colorizer.Transform(" // Comment "));
            Assert.AreEqual(" comment ", colorizer.Transform(" /* Comment */ "));
        }
Example #35
0
        public void TestStrings()
        {
            CodeColorizer colorizer = GetColorizer(LanguageRules);

            colorizer.Options.TokenFormat = "{1}";
            Assert.AreEqual(" string ", colorizer.Transform(" \"abc\" "));
            Assert.AreEqual(" string ", colorizer.Transform(" 'a' "));
        }
            public void WillNotStyleKeyword()
            {
                string source = "get bool false";
                string expected = "<div style=\"color:Black;background-color:White;\"><pre>\r\nget bool false\r\n</pre></div>";

                string actual = new CodeColorizer().Colorize(source, GetGrammar());
                Assert.Equal(expected, actual);
            }
        /// <summary>
        /// Displays the source code formatted correctly to the developer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void displaySourceCode_Click(object sender, EventArgs e)
        {
            string colourizedSourceCode = new CodeColorizer().Colorize(editSourceCodeTextBox.Text, Languages.CSharp);

            string html = ("<!doctype html><head><meta charset=\"utf-8\" <title> Code Snippet </title> </head> <body>" + colourizedSourceCode + "</body></html>"); // String to store colour coded code

            sourceCodeWebBrowser.DocumentText = html;
        }
Example #38
0
            public void TransformWillStyleAttributeTarget()
            {
                string source =
                @"[assembly: SomeAttribute]";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                [<span style=""color:Blue;"">assembly</span>: SomeAttribute]
                </pre></div>";

                string actual = new CodeColorizer().Colorize(source, Languages.CSharp);

                Assert.Equal(expected, actual);
            }
Example #39
0
            public void WillNotStyleKeywordInsideStraightBracesWithSpaceBeforeAndAfter()
            {
                string source =
                @"[ SELECT ]";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                [ SELECT ]
                </pre></div>";

                string actual = new CodeColorizer().Colorize(source, Languages.Sql);

                Assert.Equal(expected, actual);
            }
Example #40
0
            public void WillNotStyleKeywordsPrecededByAtSign()
            {
                string source =
                @"@size";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                @size
                </pre></div>";

                string actual = new CodeColorizer().Colorize(source, Languages.Sql);

                Assert.Equal(expected, actual);
            }
Example #41
0
            public void WillStyleASolitaryUsingStatement()
            {
                string source =
                @"using System;";

                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">using</span> System;
                </pre></div>";

                string actual = new CodeColorizer().Colorize(source, Languages.CSharp);

                Assert.Equal(expected, actual);
            }
        public CodeColorizer GetColorizer( string key )
        {
            if (SyntaxEngine == null)
            {
                lock(SyntaxEngine)
                {
                    SyntaxEngine = config.Configure();
                    if (SyntaxEngine == null)
                        throw (new Exception("Could not create colorizer engine"));
                }
            }

            return SyntaxEngine;
        }
Example #43
0
            public void WillStyleAlterAssembly()
            {
                string sourceText =
                    @"ALTER ASSEMBLY MyClass
                ADD FILE FROM 'C:\MyClassProject\Class1.cs';";
                string expected =
                    @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">ALTER</span> <span style=""color:Blue;"">ASSEMBLY</span> MyClass
                <span style=""color:Blue;"">ADD</span> <span style=""color:Blue;"">FILE</span> <span style=""color:Blue;"">FROM</span> <span style=""color:#A31515;"">'C:\MyClassProject\Class1.cs'</span>;
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
Example #44
0
            public void TransformWillStyleClassName()
            {
                string source =
                @"public class ClassName
                {";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">public</span> <span style=""color:Blue;"">class</span> ClassName
                {
                </pre></div>";

                string actual = new CodeColorizer().Colorize(source, Languages.CSharp);

                Assert.Equal(expected, actual);
            }
Example #45
0
            public void WillStyleAlterTableStatement()
            {
                string source =
                @"ALTER TABLE [TableName]
                ADD [NewColumnName] VARCHAR(20) NOT NULL CONSTRAINT [ConstraintName] DEFAULT('DefaultValue');";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">ALTER</span> <span style=""color:Blue;"">TABLE</span> [TableName]
                <span style=""color:Blue;"">ADD</span> [NewColumnName] <span style=""color:Blue;"">VARCHAR</span>(20) <span style=""color:Blue;"">NOT</span> <span style=""color:Blue;"">NULL</span> <span style=""color:Blue;"">CONSTRAINT</span> [ConstraintName] <span style=""color:Blue;"">DEFAULT</span>(<span style=""color:#A31515;"">'DefaultValue'</span>);
                </pre></div>";

                string actual = new CodeColorizer().Colorize(source, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleDoctypeWithLineBreakInDoubleQuotedString()
            {
                string source =
                @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML
                1.1//EN"" ""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">&lt;!</span><span style=""color:#A31515;"">DOCTYPE</span> <span style=""color:Red;"">html</span> <span style=""color:Red;"">PUBLIC</span> <span style=""color:Blue;"">&quot;-//W3C//DTD XHTML
                1.1//EN&quot;</span> <span style=""color:Blue;"">&quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&quot;</span><span style=""color:Blue;"">&gt;</span>
                </pre></div>";

                string actual = new CodeColorizer().Colorize(source, GetGrammar());

                Assert.Equal(expected, actual);
            }
            public void WillStyleTextsizeFunction()
            {
                string sourceText =
                @"SELECT @@TEXTSIZE AS 'Regex Size'
                SET TEXTSIZE 2048
                SELECT @@TEXTSIZE AS 'Regex Size'";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">SELECT</span> @@TEXTSIZE <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Regex Size'</span>
                <span style=""color:Blue;"">SET</span> <span style=""color:Blue;"">TEXTSIZE</span> 2048
                <span style=""color:Blue;"">SELECT</span> @@TEXTSIZE <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Regex Size'</span>
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
Example #48
0
            public void WillStyleCreateAggregate()
            {
                string sourceText =
                    @"USE AdventureWorks;
                GO
                DECLARE @SamplesPath nvarchar(1024)
                -- You may have to modify the value of the this variable if you have
                --installed the sample some location other than the default location.
                SELECT @SamplesPath = REPLACE(physical_name, 'Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf', 'Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\')
                FROM master.sys.database_files
                WHERE name = 'master';
                CREATE ASSEMBLY StringUtilities FROM @SamplesPath + 'StringUtilities\CS\StringUtilities\bin\debug\StringUtilities.dll'
                WITH PERMISSION_SET=SAFE;
                GO

                CREATE AGGREGATE Concatenate(@input nvarchar(4000))
                RETURNS nvarchar(4000)
                EXTERNAL NAME [StringUtilities].[Microsoft.Samples.SqlServer.Concatenate];
                GO";
                string expected =
                    @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">DECLARE</span> @SamplesPath <span style=""color:Blue;"">nvarchar</span>(1024)
                <span style=""color:Green;"">-- You may have to modify the value of the this variable if you have</span>
                <span style=""color:Green;"">--installed the sample some location other than the default location.</span>
                <span style=""color:Blue;"">SELECT</span> @SamplesPath = <span style=""color:Magenta;"">REPLACE</span>(physical_name, <span style=""color:#A31515;"">'Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf'</span>, <span style=""color:#A31515;"">'Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\'</span>)
                <span style=""color:Blue;"">FROM</span> master.sys.database_files
                <span style=""color:Blue;"">WHERE</span> <span style=""color:Blue;"">name</span> = <span style=""color:#A31515;"">'master'</span>;
                <span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">ASSEMBLY</span> StringUtilities <span style=""color:Blue;"">FROM</span> @SamplesPath + <span style=""color:#A31515;"">'StringUtilities\CS\StringUtilities\bin\debug\StringUtilities.dll'</span>
                <span style=""color:Blue;"">WITH</span> PERMISSION_SET=SAFE;
                GO

                <span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">AGGREGATE</span> Concatenate(@input <span style=""color:Blue;"">nvarchar</span>(4000))
                <span style=""color:Blue;"">RETURNS</span> <span style=""color:Blue;"">nvarchar</span>(4000)
                <span style=""color:Blue;"">EXTERNAL</span> <span style=""color:Blue;"">NAME</span> [StringUtilities].[Microsoft.Samples.SqlServer.Concatenate];
                GO
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStylePatIndexFunction()
            {
                string sourceText =
                @"USE AdventureWorks;
                GO
                SELECT PATINDEX('%ensure%',DocumentSummary)
                FROM Production.Document
                WHERE DocumentID = 3;
                GO";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">PATINDEX</span>(<span style=""color:#A31515;"">'%ensure%'</span>,DocumentSummary)
                <span style=""color:Blue;"">FROM</span> Production.Document
                <span style=""color:Blue;"">WHERE</span> DocumentID = 3;
                GO
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleColNameFunction()
            {
                string sourceText =
                @"USE AdventureWorks;
                GO
                SET NOCOUNT OFF;
                GO
                SELECT COL_NAME(OBJECT_ID('HumanResources.Employee'), 1) AS 'Column StyleName';
                GO";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">SET</span> <span style=""color:Blue;"">NOCOUNT</span> <span style=""color:Blue;"">OFF</span>;
                GO
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">COL_NAME</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'HumanResources.Employee'</span>), 1) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Column StyleName'</span>;
                GO
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleIsSrvrolememberFunction()
            {
                string sourceText =
                @"IF IS_SRVROLEMEMBER ('sysadmin') = 1
                print 'Current user''s login is a member of the sysadmin role'
                ELSE IF IS_SRVROLEMEMBER ('sysadmin') = 0
                print 'Current user''s login is NOT a member of the sysadmin role'
                ELSE IF IS_SRVROLEMEMBER ('sysadmin') IS NULL
                print 'ERROR: The server role specified is not valid.'";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_SRVROLEMEMBER</span> (<span style=""color:#A31515;"">&#39;sysadmin&#39;</span>) = 1
                <span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">&#39;Current user&#39;</span><span style=""color:#A31515;"">&#39;s login is a member of the sysadmin role&#39;</span>
                <span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_SRVROLEMEMBER</span> (<span style=""color:#A31515;"">&#39;sysadmin&#39;</span>) = 0
                <span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">&#39;Current user&#39;</span><span style=""color:#A31515;"">&#39;s login is NOT a member of the sysadmin role&#39;</span>
                <span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_SRVROLEMEMBER</span> (<span style=""color:#A31515;"">&#39;sysadmin&#39;</span>) <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
                <span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">&#39;ERROR: The server role specified is not valid.&#39;</span>
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleIsMemberFunction()
            {
                string sourceText =
                @"-- Test membership in db_owner and print appropriate message.
                IF IS_MEMBER ('db_owner') = 1
                print 'Current user is a member of the db_owner role'
                ELSE IF IS_MEMBER ('db_owner') = 0
                print 'Current user is NOT a member of the db_owner role'
                ELSE IF IS_MEMBER ('db_owner') IS NULL
                print 'ERROR: Invalid group / role specified'
                go

                -- Execute SELECT if user is a member of ADVWORKS\Shipping.
                IF IS_MEMBER ('ADVWORKS\Shipping') = 1
                SELECT 'User ' + USER + ' is a member of ADVWORKS\Shipping.'
                go";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Green;"">-- Test membership in db_owner and print appropriate message.</span>
                <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_MEMBER</span> (<span style=""color:#A31515;"">&#39;db_owner&#39;</span>) = 1
                <span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">&#39;Current user is a member of the db_owner role&#39;</span>
                <span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_MEMBER</span> (<span style=""color:#A31515;"">&#39;db_owner&#39;</span>) = 0
                <span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">&#39;Current user is NOT a member of the db_owner role&#39;</span>
                <span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_MEMBER</span> (<span style=""color:#A31515;"">&#39;db_owner&#39;</span>) <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
                <span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">&#39;ERROR: Invalid group / role specified&#39;</span>
                go

                <span style=""color:Green;"">-- Execute SELECT if user is a member of ADVWORKS\Shipping.</span>
                <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_MEMBER</span> (<span style=""color:#A31515;"">&#39;ADVWORKS\Shipping&#39;</span>) = 1
                <span style=""color:Blue;"">SELECT</span> <span style=""color:#A31515;"">&#39;User &#39;</span> + <span style=""color:Magenta;"">USER</span> + <span style=""color:#A31515;"">&#39; is a member of ADVWORKS\Shipping.&#39;</span>
                go
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleObjectIdFunction()
            {
                string sourceText =
                @"USE master;
                GO
                SELECT OBJECT_ID(N'AdventureWorks.Production.WorkOrder') AS 'Object ID';
                GO

                USE AdventureWorks;
                GO
                IF OBJECT_ID (N'dbo.AWBuildVersion', N'U') IS NOT NULL
                DROP TABLE dbo.AWBuildVersion;
                GO

                DECLARE @db_id smallint;
                DECLARE @object_id int;
                SET @db_id = DB_ID(N'AdventureWorks');
                SET @object_id = OBJECT_ID(N'AdventureWorks.Person.Address');
                IF @db_id IS NULL
                BEGIN;
                PRINT N'Invalid database';
                END;
                ELSE IF @object_id IS NULL
                BEGIN;
                PRINT N'Invalid object';
                END;
                ELSE
                BEGIN;
                SELECT * FROM sys.dm_db_index_operational_stats(@db_id, @object_id, NULL, NULL);
                END;
                GO";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> master;
                GO
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'AdventureWorks.Production.WorkOrder'</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Object ID'</span>;
                GO

                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">OBJECT_ID</span> (N<span style=""color:#A31515;"">'dbo.AWBuildVersion'</span>, N<span style=""color:#A31515;"">'U'</span>) <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NOT</span> <span style=""color:Blue;"">NULL</span>
                <span style=""color:Blue;"">DROP</span> <span style=""color:Blue;"">TABLE</span> dbo.AWBuildVersion;
                GO

                <span style=""color:Blue;"">DECLARE</span> @db_id <span style=""color:Blue;"">smallint</span>;
                <span style=""color:Blue;"">DECLARE</span> @object_id <span style=""color:Blue;"">int</span>;
                <span style=""color:Blue;"">SET</span> @db_id = <span style=""color:Magenta;"">DB_ID</span>(N<span style=""color:#A31515;"">'AdventureWorks'</span>);
                <span style=""color:Blue;"">SET</span> @object_id = <span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'AdventureWorks.Person.Address'</span>);
                <span style=""color:Blue;"">IF</span> @db_id <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
                <span style=""color:Blue;"">BEGIN</span>;
                <span style=""color:Blue;"">PRINT</span> N<span style=""color:#A31515;"">'Invalid database'</span>;
                <span style=""color:Blue;"">END</span>;
                <span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> @object_id <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
                <span style=""color:Blue;"">BEGIN</span>;
                <span style=""color:Blue;"">PRINT</span> N<span style=""color:#A31515;"">'Invalid object'</span>;
                <span style=""color:Blue;"">END</span>;
                <span style=""color:Blue;"">ELSE</span>
                <span style=""color:Blue;"">BEGIN</span>;
                <span style=""color:Blue;"">SELECT</span> * <span style=""color:Blue;"">FROM</span> sys.dm_db_index_operational_stats(@db_id, @object_id, <span style=""color:Blue;"">NULL</span>, <span style=""color:Blue;"">NULL</span>);
                <span style=""color:Blue;"">END</span>;
                GO
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleDatabasePropertyFunction()
            {
                string sourceText =
                @"USE master;
                GO
                SELECT DATABASEPROPERTY('master', 'IsTruncLog');";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> master;
                GO
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">DATABASEPROPERTY</span>(<span style=""color:#A31515;"">'master'</span>, <span style=""color:#A31515;"">'IsTruncLog'</span>);
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleColumnPropertyFunction()
            {
                string sourceText =
                @"USE AdventureWorks;
                GO
                SELECT COLUMNPROPERTY( OBJECT_ID('Person.Contact'),'LastName','PRECISION')AS 'Column Length';
                GO";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">COLUMNPROPERTY</span>( <span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'Person.Contact'</span>),<span style=""color:#A31515;"">'LastName'</span>,<span style=""color:#A31515;"">'PRECISION'</span>)<span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Column Length'</span>;
                GO
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleTypepropertyFunction()
            {
                string sourceText =
                @"SELECT TYPEPROPERTY(SCHEMA_NAME(schema_id) + '.' + name, 'OwnerId') AS owner_id, name, system_type_id, user_type_id, schema_id
                FROM sys.types;

                SELECT TYPEPROPERTY( 'tinyint', 'PRECISION');";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">TYPEPROPERTY</span>(SCHEMA_NAME(schema_id) + <span style=""color:#A31515;"">'.'</span> + <span style=""color:Blue;"">name</span>, <span style=""color:#A31515;"">'OwnerId'</span>) <span style=""color:Blue;"">AS</span> owner_id, <span style=""color:Blue;"">name</span>, system_type_id, user_type_id, schema_id
                <span style=""color:Blue;"">FROM</span> sys.types;

                <span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">TYPEPROPERTY</span>( <span style=""color:#A31515;"">'tinyint'</span>, <span style=""color:#A31515;"">'PRECISION'</span>);
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleSqlVariantPropertyFunction()
            {
                string sourceText =
                @"CREATE TABLE tableA(colA sql_variant, colB int)
                INSERT INTO tableA values ( cast (46279.1 as decimal(8,2)), 1689)
                SELECT SQL_VARIANT_PROPERTY(colA,'BaseType') AS 'Base Type',
                   SQL_VARIANT_PROPERTY(colA,'Precision') AS 'Precision',
                   SQL_VARIANT_PROPERTY(colA,'Scale') AS 'Scale'
                FROM tableA
                WHERE colB = 1689";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> tableA(colA <span style=""color:Magenta;"">sql_variant</span>, colB <span style=""color:Blue;"">int</span>)
                <span style=""color:Blue;"">INSERT</span> <span style=""color:Blue;"">INTO</span> tableA <span style=""color:Blue;"">values</span> ( <span style=""color:Magenta;"">cast</span> (46279.1 <span style=""color:Blue;"">as</span> <span style=""color:Blue;"">decimal</span>(8,2)), 1689)
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">SQL_VARIANT_PROPERTY</span>(colA,<span style=""color:#A31515;"">'BaseType'</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Base Type'</span>,
                   <span style=""color:Magenta;"">SQL_VARIANT_PROPERTY</span>(colA,<span style=""color:#A31515;"">'Precision'</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Precision'</span>,
                   <span style=""color:Magenta;"">SQL_VARIANT_PROPERTY</span>(colA,<span style=""color:#A31515;"">'Scale'</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Scale'</span>
                <span style=""color:Blue;"">FROM</span> tableA
                <span style=""color:Blue;"">WHERE</span> colB = 1689
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleObjectpropertyFunction()
            {
                string sourceText =
                @"USE AdventureWorks;
                GO
                IF OBJECTPROPERTY (OBJECT_ID(N'Production.UnitMeasure'),'ISTABLE') = 1
                PRINT 'UnitMeasure is a table.'
                ELSE IF OBJECTPROPERTY (OBJECT_ID(N'Production.UnitMeasure'),'ISTABLE') = 0
                PRINT 'UnitMeasure is not a table.'
                ELSE IF OBJECTPROPERTY (OBJECT_ID(N'Production.UnitMeasure'),'ISTABLE') IS NULL
                PRINT 'ERROR: UnitMeasure is not a valid object.';
                GO

                USE AdventureWorks;
                GO
                SELECT OBJECTPROPERTY(OBJECT_ID('dbo.ufnGetProductDealerPrice'), 'IsDeterministic');
                GO

                USE AdventureWorks;
                GO
                SELECT name, object_id, type_desc
                FROM sys.objects
                WHERE OBJECTPROPERTY(object_id, N'SchemaId') = SCHEMA_ID(N'Production')
                ORDER BY type_desc, name;
                GO";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">OBJECTPROPERTY</span> (<span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'Production.UnitMeasure'</span>),<span style=""color:#A31515;"">'ISTABLE'</span>) = 1
                <span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'UnitMeasure is a table.'</span>
                <span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">OBJECTPROPERTY</span> (<span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'Production.UnitMeasure'</span>),<span style=""color:#A31515;"">'ISTABLE'</span>) = 0
                <span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'UnitMeasure is not a table.'</span>
                <span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">OBJECTPROPERTY</span> (<span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'Production.UnitMeasure'</span>),<span style=""color:#A31515;"">'ISTABLE'</span>) <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
                <span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'ERROR: UnitMeasure is not a valid object.'</span>;
                GO

                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">OBJECTPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'dbo.ufnGetProductDealerPrice'</span>), <span style=""color:#A31515;"">'IsDeterministic'</span>);
                GO

                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">name</span>, <span style=""color:Blue;"">object_id</span>, type_desc
                <span style=""color:Blue;"">FROM</span> sys.objects
                <span style=""color:Blue;"">WHERE</span> <span style=""color:Blue;"">OBJECTPROPERTY</span>(<span style=""color:Blue;"">object_id</span>, N<span style=""color:#A31515;"">'SchemaId'</span>) = SCHEMA_ID(N<span style=""color:#A31515;"">'Production'</span>)
                <span style=""color:Blue;"">ORDER</span> <span style=""color:Blue;"">BY</span> type_desc, <span style=""color:Blue;"">name</span>;
                GO
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleObjectNameFunction()
            {
                string sourceText =
                @"USE AdventureWorks;
                GO
                SELECT DISTINCT OBJECT_NAME(object_id)
                FROM master.sys.objects;
                GO";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">DISTINCT</span> <span style=""color:Blue;"">OBJECT_NAME</span>(<span style=""color:Blue;"">object_id</span>)
                <span style=""color:Blue;"">FROM</span> master.sys.objects;
                GO
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }
            public void WillStyleIndexpropertyFunction()
            {
                string sourceText =
                @"USE AdventureWorks;
                GO
                SELECT
                INDEXPROPERTY(OBJECT_ID('HumanResources.Employee'),
                'PK_Employee_EmployeeID','IsClustered')AS [Is Clustered],
                INDEXPROPERTY(OBJECT_ID('HumanResources.Employee'),
                'PK_Employee_EmployeeID','IndexDepth') AS [CaptureIndex Depth],
                INDEXPROPERTY(OBJECT_ID('HumanResources.Employee'),
                'PK_Employee_EmployeeID','IndexFillFactor') AS [Fill Factor];
                GO";
                string expected =
                @"<div style=""color:Black;background-color:White;""><pre>
                <span style=""color:Blue;"">USE</span> AdventureWorks;
                GO
                <span style=""color:Blue;"">SELECT</span>
                <span style=""color:Blue;"">INDEXPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'HumanResources.Employee'</span>),
                <span style=""color:#A31515;"">'PK_Employee_EmployeeID'</span>,<span style=""color:#A31515;"">'IsClustered'</span>)<span style=""color:Blue;"">AS</span> [Is Clustered],
                <span style=""color:Blue;"">INDEXPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'HumanResources.Employee'</span>),
                <span style=""color:#A31515;"">'PK_Employee_EmployeeID'</span>,<span style=""color:#A31515;"">'IndexDepth'</span>) <span style=""color:Blue;"">AS</span> [CaptureIndex Depth],
                <span style=""color:Blue;"">INDEXPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'HumanResources.Employee'</span>),
                <span style=""color:#A31515;"">'PK_Employee_EmployeeID'</span>,<span style=""color:#A31515;"">'IndexFillFactor'</span>) <span style=""color:Blue;"">AS</span> [Fill Factor];
                GO
                </pre></div>";

                string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);

                Assert.Equal(expected, actual);
            }