Skip to content

Commit

Permalink
Fixed #49
Browse files Browse the repository at this point in the history
  • Loading branch information
Vannevelj committed May 26, 2015
1 parent ed24db6 commit bdd5cf9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,29 @@ void Method()
VerifyCSharpDiagnostic(original);
}

[TestMethod]
public void ConditionalOperatorReturnsDefaultOptionsAnalyzer_WithLiteralsAsString_DoesNotInvokeWarning()
{
var original = @"
using System;
using System.Text;
namespace ConsoleApplication1
{
class MyClass
{
void Method()
{
int legalAge = 18;
int myAge = 22;
string canDrink = myAge >= legalAge ? ""true"" : ""false"";
}
}
}";

VerifyCSharpDiagnostic(original);
}

protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new ConditionalOperatorReturnsDefaultOptionsAnalyzer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ private void AnalyzeSymbol(SyntaxNodeAnalysisContext context)
return;
}

var hasTrueLiteral = trueExpression.Token.ValueText == "true";
var hasFalseLiteral = falseExpression.Token.ValueText == "false";
var hasTrueLiteral = trueExpression.Token.ValueText == "true" && trueExpression.Token.Value is bool;
var hasFalseLiteral = falseExpression.Token.ValueText == "false" && trueExpression.Token.Value is bool;

if (hasTrueLiteral && hasFalseLiteral)
{
Expand Down

0 comments on commit bdd5cf9

Please sign in to comment.