Skip to content

Commit

Permalink
Merge pull request #404 from Vannevelj/issue403
Browse files Browse the repository at this point in the history
fixes #403
  • Loading branch information
Vannevelj committed Feb 21, 2016
2 parents 91d1b43 + f9232f1 commit a70dbdb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,5 +315,29 @@ internal class Cookie
VerifyDiagnostic(original, ReplaceEmptyStringWithStringDotEmptyAnalyzer.Rule.MessageFormat.ToString());
VerifyFix(original, result);
}

[TestMethod]
public void ReplaceEmptyStringsWithStringDotEmpty_SwitchLabel()
{
var original = @"
using System;
using System.Text;
namespace ConsoleApplication1
{
class MyClass
{
void Method()
{
switch(""test"")
{
case """": break;
}
}
}
}";

VerifyDiagnostic(original);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
}
}

// A switch label in the scenario of
// switch(var)
// {
// case "": break;
// }
// Cannot be changed since it has to be a constant
if (stringLiteral.AncestorsAndSelf().OfType<SwitchLabelSyntax>().Any())
{
return;
}

context.ReportDiagnostic(Diagnostic.Create(Rule, stringLiteral.GetLocation()));
}
}
Expand Down

0 comments on commit a70dbdb

Please sign in to comment.