public void CommentParser_GroupsMultipleAdjacentCommentsInOneSpan() { const string code = @"namespace TestNamespace { public class TestClass { private readonly ILog _logger = new Log(); public void TestMethod() { // apple // banana } } }"; var options = new ParserTestOptions(loggingIdentifiers: new[] { "logger." }); var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(code); var spans = _parser .Parse(syntaxTree, options); Assert.AreEqual(1, spans.Count()); var span = spans.Single(); var expected = @" // apple // banana"; var actual = code.Substring(span.Start, span.Length); Assert.AreEqual(expected, actual); }
public void LoggingParser_DoesNotParseWhenNotSupposedTo() { const string code = @"namespace TestNamespace { public class TestClass { private readonly ILog _logger = new Log(); public void TestMethod() { var apple = ""green""; var banana = ""yellow""; _logger .Info($""the banana is {banana}""); _logger .Info($""the apple is {apple}""); } } }"; var options = new ParserTestOptions(isLoggingDimmingEnabled: false, isLoggingOutliningEnabled: false, loggingIdentifiers: new[] { "logger." }); var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(code); var spans = _parser .Parse(syntaxTree, options); Assert.AreEqual(0, spans.Count()); }
public void CommentParser_EndOfLineComment_DocComment() { const string code = @"namespace TestNamespace { public class TestClass { public void TestMethod() { var apple = ""green""; /// <summary> apple should be green </summary> var orange = ""orange2""; } } }"; var options = new ParserTestOptions(); var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(code); var spans = _parser .Parse(syntaxTree, options); Assert.AreEqual(1, spans.Count()); var span = spans.Single(); var expected = @"/// <summary> apple should be green </summary> "; var actual = code.Substring(span.Start, span.Length); Assert.AreEqual(expected, actual); }
public void ObtrusiveCodeSpanNormalizer_ConcatenatesAdjacentOutliningSpans() { const string code = @"namespace TestNamespace { public class TestClass { private readonly ILog _logger = new Log(); public void TestMethod() { var apple = ""green""; var banana = ""yellow""; // banana _logger .Info($""the banana is {banana}""); // apple _logger .Info($""the apple is {apple}""); } } }"; var options = new ParserTestOptions(loggingIdentifiers: new[] { "logger." }); var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(code); var spans = _parser .Parse(syntaxTree, options) .ToList(); Assert.AreEqual(4, spans.Count); var normalizedOutliningSpans = _normalizer .Normalize(spans, options, code) .Where(x => x.AllowsOutlining) .ToList(); Assert.AreEqual(1, normalizedOutliningSpans.Count); var firstSpan = spans .OrderBy(x => x.Start) .First(); var lastSpan = spans .OrderByDescending(x => x.End) .First(); var normalizedSpan = normalizedOutliningSpans.Single(); Assert.AreEqual(firstSpan.Start, normalizedSpan.Start); Assert.AreEqual(lastSpan.End, normalizedSpan.End); }
public void LoggingParser_EatsUpLeadingAndTrailingWhiteSpaceExceptFirstLeadingNewLine() { const string code = @"namespace TestNamespace { public class TestClass { private readonly ILog _logger = new Log(); public void TestMethod() { var banana = ""yellow""; _logger .Info($""the banana is {banana}""); } } }"; var options = new ParserTestOptions(loggingIdentifiers: new[] { "logger." }); var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(code); var spans = _parser .Parse(syntaxTree, options); Assert.AreEqual(1, spans.Count()); var span = spans.Single(); var expected = @" _logger .Info($""the banana is {banana}""); "; var actual = code.Substring(span.Start, span.Length); Assert.AreEqual(expected, actual); }
public void CommentParser_EatsUpLeadingWhiteSpaceExceptFirstLeadingNewLine_MultiLineComment() { const string code = @"namespace TestNamespace { public class TestClass { private readonly ILog _logger = new Log(); public void TestMethod() { /* * apple */ } } }"; var options = new ParserTestOptions(); var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(code); var spans = _parser .Parse(syntaxTree, options); Assert.AreEqual(1, spans.Count()); var span = spans.Single(); var expected = @" /* * apple */ "; var actual = code.Substring(span.Start, span.Length); Assert.AreEqual(expected, actual); }
public void LoggingParser_DoesNotGroupMultipleNonAdjacentLoggingStatementsInOneSpan() { const string code = @"namespace TestNamespace { public class TestClass { private readonly ILog _logger = new Log(); public void TestMethod() { var banana = ""yellow""; _logger .Info($""the banana is {banana}""); var apple = ""green""; _logger .Info($""the apple is {apple}""); } } }"; var options = new ParserTestOptions(loggingIdentifiers: new[] { "logger." }); var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(code); var spans = _parser .Parse(syntaxTree, options); Assert.AreEqual(2, spans.Count()); var span1 = spans.ElementAt(0); var span2 = spans.ElementAt(1); var expected1 = @" _logger .Info($""the banana is {banana}""); "; var expected2 = @" _logger .Info($""the apple is {apple}""); "; var actual1 = code.Substring(span1.Start, span1.Length); var actual2 = code.Substring(span2.Start, span2.Length); Assert.AreEqual(expected1, actual1); Assert.AreEqual(expected2, actual2); }
public void ObtrusiveCodeSpanNormalizer_DoesNotConcatenateNonAdjacentOutliningSpans() { const string code = @"namespace TestNamespace { public class TestClass { private readonly ILog _logger = new Log(); public void TestMethod() { { // banana var banana = ""yellow""; _logger .Info($""the banana is {banana}""); } { // apple var apple = ""green""; _logger .Info($""the apple is {apple}""); } } } }"; var options = new ParserTestOptions(loggingIdentifiers: new[] { "logger." }); var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(code); var spans = _parser .Parse(syntaxTree, options) .ToList(); Assert.AreEqual(4, spans.Count); var normalizedOutliningSpans = _normalizer .Normalize(spans, options, code) .Where(x => x.AllowsOutlining) .ToList(); Assert.AreEqual(4, normalizedOutliningSpans.Count); }
public void CommentParser_DoesNotParseWhenNotSupposedTo() { const string code = @"namespace TestNamespace { public class TestClass { private readonly ILog _logger = new Log(); public void TestMethod() { // apple // banana } } }"; var options = new ParserTestOptions(isCommentDimmingEnabled: false, isCommentOutliningEnabled: false); var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(code); var spans = _parser .Parse(syntaxTree, options); Assert.AreEqual(0, spans.Count()); }