public CSharpExampleFileTests(ITestOutputHelper output)
 {
     _output = output;
     var subject = new CSharpLexer();
     _results = subject.GetTokens(SampleFile.Load("csharp-sample.txt"))
         .ToArray();
 }
        public void StrippedHtmlIsSameAsInput()
        {
            var input = SampleFile.Load("csharp-sample.txt");
            var tokens = new CSharpLexer()
                .GetTokens(input)
                .ToArray();

            var subject = new HtmlFormatter(new HtmlFormatterOptions()
            {
                NoWrap = true
            });

            var htmlOut = new StringWriter();
            subject.Format(tokens, htmlOut);

            File.WriteAllText("output.html", htmlOut.ToString());

            var txtOut = new StringWriter();
            new NullFormatter().Format(tokens, txtOut);

            var strippedHtml = Regex.Replace(htmlOut.ToString(),
                @"<.*?>", "")
                .Trim();
            var escapedText = HtmlFormatter.EscapeHtml(txtOut.ToString()).Trim();

            Check.That(strippedHtml).IsEqualTo(escapedText);
        }
예제 #3
0
        public void GetsCorrectTokensWhenSourceContainsChar()
        {
            const string code = "using System; namespace Foo { class Bar { private char _baz = 'c'; } }";
            var subject = new CSharpLexer();

            var tokens = subject.GetTokens(code).ToArray();

            Check.That(tokens[0]).IsEqualTo(new Token(0, TokenTypes.Keyword, "using"));
        }
        public void TestLineNumbers()
        {
            var options = new HtmlFormatterOptions()
            {
                LineNumbers = LineNumberStyle.Table
            };
            var input = SampleFile.Load("csharp-sample.txt");
            var tokens = new CSharpLexer()
                .GetTokens(input);

            var subject = new HtmlFormatter(options);
            var output = new StringWriter();
            subject.Format(tokens, output);

            var html = output.ToString();

            Check.That(Regex.IsMatch(html, @"<pre>\s+1\s+2\s+3"))
                .IsTrue();
        }
예제 #5
0
        public void MethodDeclaration()
        {
            const string code = "public override void Foo()";
            var subject = new CSharpLexer();

            var tokens = subject.GetTokens(code).ToArray();

            Check.That(tokens).ContainsExactly(
                new Token(0, TokenTypes.Keyword, "public"),
                new Token(6, TokenTypes.Text, " "),
                new Token(7, TokenTypes.Keyword, "override"),
                new Token(15, TokenTypes.Text, " "),
                new Token(16, TokenTypes.Keyword, "void"),
                new Token(20, TokenTypes.Text, " "),
                new Token(21, TokenTypes.Name.Function, "Foo"),
                new Token(24, TokenTypes.Text, ""),
                new Token(24, TokenTypes.Punctuation, "("),
                new Token(25, TokenTypes.Punctuation, ")"));
        }
        public void TestLineAnchors()
        {
            var options = new HtmlFormatterOptions()
            {
                LineAnchors = "foo",
                AnchorLineNumbers = true
            };
            var input = SampleFile.Load("csharp-sample.txt");
            var tokens = new CSharpLexer()
                .GetTokens(input);

            var subject = new HtmlFormatter(options);
            var output = new StringWriter();
            subject.Format(tokens, output);

            var html = output.ToString();

            Check.That(Regex.IsMatch(html, "<a name=\"foo-1\">"))
                .IsTrue();
        }
        public void Full()
        {
            var options = new HtmlFormatterOptions()
            {
                Full = true,
                Title = "My Source Code"
            };
            var input = SampleFile.Load("csharp-sample.txt");
            var tokens = new CSharpLexer()
                .GetTokens(input);

            var subject = new HtmlFormatter(options);
            var output = new StringWriter();
            subject.Format(tokens, output);

            var html = output.ToString();
            File.WriteAllText("output.html", html);

            Check.That(html).Contains("<html>", "<head>", "<title>My Source Code</title>");
        }
 public void IndexOutOfRange_8(string fixture)
 {
     var content = SampleFile.Load(fixture);
     var lexer = new CSharpLexer();
     Check.ThatCode(() => lexer.GetTokens(content)).DoesNotThrow();
 }