Skip to content

Commit

Permalink
Update tests that fail for c# 12
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornhellander committed Nov 25, 2023
1 parent 3f23e6f commit 4141021
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,58 @@

namespace StyleCop.Analyzers.Test.CSharp12.ReadabilityRules
{
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp11.ReadabilityRules;

using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.ReadabilityRules.SA1130UseLambdaSyntax,
StyleCop.Analyzers.ReadabilityRules.SA1130CodeFixProvider>;

public partial class SA1130CSharp12UnitTests : SA1130CSharp11UnitTests
{
protected override DiagnosticResult[] GetExpectedResultCodeFixSpecialCases()
{
return new[]
{
Diagnostic().WithLocation(8, 20),
Diagnostic().WithLocation(9, 20),
Diagnostic().WithLocation(10, 25),
Diagnostic().WithLocation(11, 30),
Diagnostic().WithLocation(12, 30),
DiagnosticResult.CompilerError("CS1065").WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
DiagnosticResult.CompilerError("CS7014").WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
DiagnosticResult.CompilerError("CS1670").WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
DiagnosticResult.CompilerError("CS1669").WithLocation(15, 42),
DiagnosticResult.CompilerError("CS0225").WithLocation(14, 47),
};
}

protected override DiagnosticResult[] GetExpectedResultAfterFixCodeFixSpecialCases()
{
return new DiagnosticResult[]
{
Diagnostic().WithLocation(12, 30),
DiagnosticResult.CompilerError("CS1065").WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
DiagnosticResult.CompilerError("CS7014").WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
DiagnosticResult.CompilerError("CS1670").WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
DiagnosticResult.CompilerError("CS1669").WithLocation(15, 42),
DiagnosticResult.CompilerError("CS0225").WithLocation(14, 47),
};
}

protected override DiagnosticResult[] GetExpectedResultVerifyInvalidCodeConstructions()
{
return new[]
{
Diagnostic().WithSpan(4, 50, 4, 58),
DiagnosticResult.CompilerError("CS1660").WithLocation(4, 50),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@

namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
{
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;

public partial class SA1015CSharp12UnitTests : SA1015CSharp11UnitTests
{
protected override DiagnosticResult[] GetExpectedResultMissingToken()
{
return new[]
{
DiagnosticResult.CompilerError("CS1003").WithLocation(7, 35).WithArguments(","),
DiagnosticResult.CompilerError("CS1003").WithLocation(7, 36).WithArguments(">"),
DiagnosticResult.CompilerError("CS1026").WithLocation(7, 36),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@

namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
{
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;

public partial class SA1018CSharp12UnitTests : SA1018CSharp11UnitTests
{
protected override DiagnosticResult[] GetExpectedResultSyntaxErrorAtEndOfFile()
{
return new[]
{
DiagnosticResult.CompilerError("CS1031").WithLocation(10, 2),
DiagnosticResult.CompilerError("CS8803").WithLocation(11, 1),
DiagnosticResult.CompilerError("CS8805").WithLocation(11, 1),
DiagnosticResult.CompilerError("CS1001").WithLocation(11, 2),
DiagnosticResult.CompilerError("CS1002").WithLocation(11, 2),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,33 +218,10 @@ private void Method(object o)
Action<int> h = delegate (int x, __arglist) { Console.WriteLine(); };
}
}";
var expected = new[]
{
Diagnostic().WithLocation(8, 20),
Diagnostic().WithLocation(9, 20),
Diagnostic().WithLocation(10, 25),
Diagnostic().WithLocation(11, 30),
Diagnostic().WithLocation(12, 30),
Diagnostic(CS1065).WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
Diagnostic(CS7014).WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
Diagnostic(CS1670).WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
Diagnostic(CS1669).WithLocation(15, 42),
};

var expectedAfterFix = new[]
{
Diagnostic().WithLocation(12, 30),
Diagnostic(CS1065).WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
Diagnostic(CS7014).WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
Diagnostic(CS1670).WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
Diagnostic(CS1669).WithLocation(15, 42),
};
var expected = this.GetExpectedResultCodeFixSpecialCases();

var expectedAfterFix = this.GetExpectedResultAfterFixCodeFixSpecialCases();

var test = new CSharpTest
{
Expand Down Expand Up @@ -828,11 +805,7 @@ public class TestClass
}
";

DiagnosticResult[] expected =
{
Diagnostic().WithSpan(4, 50, 4, 58),
DiagnosticResult.CompilerError("CS1660").WithMessage("Cannot convert anonymous method to type 'EventHandler[]' because it is not a delegate type").WithSpan(4, 50, 4, 62),
};
var expected = this.GetExpectedResultVerifyInvalidCodeConstructions();

var test = new CSharpTest
{
Expand Down Expand Up @@ -1010,5 +983,48 @@ public void Test()

await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

protected virtual DiagnosticResult[] GetExpectedResultCodeFixSpecialCases()
{
return new[]
{
Diagnostic().WithLocation(8, 20),
Diagnostic().WithLocation(9, 20),
Diagnostic().WithLocation(10, 25),
Diagnostic().WithLocation(11, 30),
Diagnostic().WithLocation(12, 30),
Diagnostic(CS1065).WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
Diagnostic(CS7014).WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
Diagnostic(CS1670).WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
Diagnostic(CS1669).WithLocation(15, 42),
};
}

protected virtual DiagnosticResult[] GetExpectedResultAfterFixCodeFixSpecialCases()
{
return new[]
{
Diagnostic().WithLocation(12, 30),
Diagnostic(CS1065).WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
Diagnostic(CS7014).WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
Diagnostic(CS1670).WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
Diagnostic(CS1669).WithLocation(15, 42),
};
}

protected virtual DiagnosticResult[] GetExpectedResultVerifyInvalidCodeConstructions()
{
return new[]
{
Diagnostic().WithSpan(4, 50, 4, 58),
DiagnosticResult.CompilerError("CS1660").WithMessage("Cannot convert anonymous method to type 'EventHandler[]' because it is not a delegate type").WithSpan(4, 50, 4, 62),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,7 @@ void Method()
}
";

DiagnosticResult[] expected =
{
DiagnosticResult.CompilerError("CS1003").WithMessage("Syntax error, '>' expected").WithLocation(7, 35),
};
var expected = this.GetExpectedResultMissingToken();

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}
Expand Down Expand Up @@ -432,5 +429,13 @@ public void TestMethod2(object input)

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

protected virtual DiagnosticResult[] GetExpectedResultMissingToken()
{
return new[]
{
DiagnosticResult.CompilerError("CS1003").WithMessage("Syntax error, '>' expected").WithLocation(7, 35),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,17 @@ private void Test()
?
";

DiagnosticResult[] expected =
var expected = this.GetExpectedResultSyntaxErrorAtEndOfFile();

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

protected virtual DiagnosticResult[] GetExpectedResultSyntaxErrorAtEndOfFile()
{
return new[]
{
DiagnosticResult.CompilerError("CS1031").WithMessage("Type expected").WithLocation(10, 2),
};

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}
}
}

0 comments on commit 4141021

Please sign in to comment.