|
| 1 | +using System.Diagnostics.CodeAnalysis; |
| 2 | +using Xunit; |
| 3 | + |
| 4 | +namespace Open.Text.Analyzers.Tests; |
| 5 | + |
| 6 | +/// <summary> |
| 7 | +/// <para>MANUAL VERIFICATION TESTS for StringComparablePatternMatchingSuppressor</para> |
| 8 | +/// <para>To verify the suppressor works:</para> |
| 9 | +/// <para> |
| 10 | +/// 1. Create a new test console app: |
| 11 | +/// dotnet new console -n SuppressorTest |
| 12 | +/// cd SuppressorTest |
| 13 | +/// </para> |
| 14 | +/// <para> |
| 15 | +/// 2. Add Open.Text package: |
| 16 | +/// dotnet add package Open.Text |
| 17 | +/// </para> |
| 18 | +/// <para>3. Add this code to Program.cs:</para> |
| 19 | +/// <para> using Open.Text;</para> |
| 20 | +/// <para> string text = "HELLO";</para> |
| 21 | +/// <para> |
| 22 | +/// // TEST 1: Regular string - SHOULD show IDE0078 suggestion |
| 23 | +/// bool test1 = text == "hello" || text == "world"; |
| 24 | +/// // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 25 | +/// // You SHOULD see: "Use pattern matching" suggestion |
| 26 | +/// </para> |
| 27 | +/// <para> |
| 28 | +/// // TEST 2: StringComparable - should NOT show suggestion (initially) |
| 29 | +/// var comparable = text.AsCaseInsensitive(); |
| 30 | +/// bool test2 = comparable == "hello" || comparable == "world"; |
| 31 | +/// // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 32 | +/// // You WILL see: "Use pattern matching" suggestion (without analyzer) |
| 33 | +/// </para> |
| 34 | +/// <para>4. Verify the IDE shows suggestion for BOTH (this is the problem!)</para> |
| 35 | +/// <para> |
| 36 | +/// 5. Now install the analyzer: |
| 37 | +/// dotnet add package Open.Text.Analyzers |
| 38 | +/// </para> |
| 39 | +/// <para> |
| 40 | +/// 6. Rebuild and check: |
| 41 | +/// - TEST 1: Still shows suggestion ? (correct) |
| 42 | +/// - TEST 2: NO suggestion anymore ? (suppressed!) |
| 43 | +/// </para> |
| 44 | +/// <para> |
| 45 | +/// 7. Try to apply the suggestion on TEST 2 (it won't compile): |
| 46 | +/// bool test2 = comparable is "hello" or "world"; |
| 47 | +/// // Error CS0029: Cannot implicitly convert type 'string' to 'Open.Text.StringComparable' |
| 48 | +/// </para> |
| 49 | +/// <para> |
| 50 | +/// EXPECTED RESULTS: |
| 51 | +/// - Without analyzer: Both show IDE0078 |
| 52 | +/// - With analyzer: Only test1 shows IDE0078, test2 is suppressed |
| 53 | +/// </para> |
| 54 | +/// </summary> |
| 55 | +[ExcludeFromCodeCoverage] |
| 56 | +[SuppressMessage("Usage", "xUnit1004:Test methods should not be skipped")] |
| 57 | +public class StringComparablePatternMatchingSuppressorManualTests |
| 58 | +{ |
| 59 | + [Fact(Skip = "Manual verification required - see class documentation")] |
| 60 | + public void ManualVerification_Instructions() |
| 61 | + { |
| 62 | + // This test is skipped - it documents how to manually verify the suppressor works |
| 63 | + // Follow the instructions in the class XML documentation above |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Automated test to verify the suppressor is properly configured. |
| 68 | + /// This doesn't test if it WORKS, but verifies it's set up correctly. |
| 69 | + /// </summary> |
| 70 | + [Fact] |
| 71 | + public void Suppressor_IsProperlyConfigured() |
| 72 | + { |
| 73 | + var suppressor = new StringComparablePatternMatchingSuppressor(); |
| 74 | + |
| 75 | + // Verify it has the expected suppressions |
| 76 | + var suppressions = suppressor.SupportedSuppressions; |
| 77 | + Assert.Equal(4, suppressions.Length); |
| 78 | + |
| 79 | + // Verify it suppresses IDE0078 |
| 80 | + Assert.Contains(suppressions, s => s.SuppressedDiagnosticId == "IDE0078"); |
| 81 | + Assert.Contains(suppressions, s => s.SuppressedDiagnosticId == "IDE0083"); |
| 82 | + Assert.Contains(suppressions, s => s.SuppressedDiagnosticId == "IDE0260"); |
| 83 | + Assert.Contains(suppressions, s => s.SuppressedDiagnosticId == "RCS1246"); |
| 84 | + } |
| 85 | +} |
0 commit comments