namespace BizHawk.Tests.Analyzers; using Verify = Microsoft.CodeAnalysis.CSharp.Testing.CSharpAnalyzerVerifier< BizHawk.Analyzers.UseSpanIsEmptyAnalyzer, Microsoft.CodeAnalysis.Testing.DefaultVerifier>; [TestClass] public sealed class UseSpanIsEmptyAnalyzerTests { [TestMethod] public Task CheckMisuseOfUseSpanLength() => Verify.VerifyAnalyzerAsync(""" using System; public static class Cases { private const int ZERO = 0; private static bool YZ(SpanPair pair) => pair is { First.Length: 0, Second: [ .., true ] }; // allowed as part of a larger pattern matching exprssion (`IsEmpty: true` works, but is longer and IMO worse) private static bool ZX(ReadOnlySpan span) => span.Length is 3; private static bool ZY(Span span) => span.Length is >= 2; private static bool ZZ(ReadOnlySpan span) => span.Length > 1; private static bool AA(Span span) => {|BHI3103:span.Length is 0|}; private static bool AB(ReadOnlySpan span) => {|BHI3103:span.Length == 0|}; private static bool AC(Span span) => {|BHI3103:0 == span.Length|}; private static bool AD(ReadOnlySpan span) => {|BHI3103:span.Length is ZERO|}; private static bool AE(Span span) => {|BHI3103:span.Length == ZERO|}; private static bool AF(ReadOnlySpan span) => {|BHI3103:ZERO == span.Length|}; private static bool BA(Span span) => {|BHI3103:span.Length is not 0|}; private static bool BB(ReadOnlySpan span) => {|BHI3103:span.Length != 0|}; private static bool BC(Span span) => {|BHI3103:0 != span.Length|}; private static bool CA(ReadOnlySpan span) => {|BHI3103:span.Length is > 0|}; private static bool CB(Span span) => {|BHI3103:span.Length > 0|}; private static bool CC(ReadOnlySpan span) => {|BHI3103:0 < span.Length|}; private static bool CZ(Span span) => {|BHI3103:span.Length is not <= 0|}; // not going to check every variation of this; another Analyzer can flag this dumb construction private static bool DA(ReadOnlySpan span) => {|BHI3103:span.Length is >= 1|}; private static bool DB(Span span) => {|BHI3103:span.Length >= 1|}; private static bool DC(ReadOnlySpan span) => {|BHI3103:1 <= span.Length|}; private static bool EA(Span span) => {|BHI3103:span.Length is <= 0|}; private static bool EB(ReadOnlySpan span) => {|BHI3103:span.Length <= 0|}; private static bool EC(Span span) => {|BHI3103:0 >= span.Length|}; private static bool FA(ReadOnlySpan span) => {|BHI3103:span.Length is < 1|}; private static bool FB(Span span) => {|BHI3103:span.Length < 1|}; private static bool FC(ReadOnlySpan span) => {|BHI3103:1 > span.Length|}; } public ref struct SpanPair { public readonly Span First; public readonly Span Second; public SpanPair(Span first, Span second) { First = first; Second = second; } } """); }