Skip to content

Commit

Permalink
Allow spacing in AssignAll comments (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
anserg256 authored Mar 18, 2023
1 parent 1af3947 commit cb13cc7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
29 changes: 21 additions & 8 deletions AssignAll/AssignAll.Test/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,39 @@ public async Task EmptyCode_AddsNoDiagnostics()
await VerifyCS.VerifyAnalyzerAsync(test);
}

[Fact]
public async Task EnableAndDisableComments_EnablesAndDisablesAnalyzerForTextSpans()
{
var test = @"
[Theory]
[InlineData("// {0}")]
[InlineData("//{0}")]
[InlineData("//{0} ")]
[InlineData("// {0} ")]
[InlineData("//\t{0}")]
[InlineData("//\t{0}\t")]
[InlineData("// {0} ")]
[InlineData("// \t \t {0} \t\t ")]
public async Task EnableAndDisableComments_EnablesAndDisablesAnalyzerForTextSpans(string commentTemplate)
{
string enableComment = string.Format(commentTemplate, "AssignAll enable");
string disableComment = string.Format(commentTemplate, "AssignAll disable");

var code = @"
namespace SampleConsoleApp
{
internal static class Program
{
private static void Main(string[] args)
{
// AssignAll enable
{enableComment}
Foo foo = {|#0:new Foo
{
// PropInt not assigned, diagnostic error
// AssignAll disable
{disableComment}
Bar = new Bar
{
// PropInt not assigned, but analyzer is disabled, no diagnostic error
// Re-enable analyzer for Baz creation
// AssignAll enable
{enableComment}
Baz = {|#1:new Baz
{
// PropInt not assigned, diagnostic error
Expand All @@ -165,8 +176,10 @@ private class Baz
public int PropInt { get; set; }
}
}
}
}
";
var test = code.Replace("{enableComment}", enableComment)
.Replace("{disableComment}", disableComment);

// Bar type has no diagnostic errors
await VerifyCS.VerifyAnalyzerAsync(test,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace AssignAll.AssignAllMembers
{
internal static class RegionsToAnalyzeProvider
{
private static readonly Regex AssignAllDisableRegex = new Regex(@"^// AssignAll disable$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex AssignAllEnableRegex = new Regex(@"^// AssignAll enable$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex AssignAllDisableRegex = new Regex(@"^//\s*AssignAll disable\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex AssignAllEnableRegex = new Regex(@"^//\s*AssignAll enable\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

internal static RegionsToAnalyze GetRegionsToAnalyze(SyntaxNode rootNode)
{
Expand Down

0 comments on commit cb13cc7

Please sign in to comment.