Skip to content

Commit a8b2f87

Browse files
Address code review feedback from Opus 4.6 and GPT 5.5: fix character comparison, improve error messages, add tests
Agent-Logs-Url: https://github.com/IntelliTect/TestTools.Console/sessions/943fe6ed-ccf1-44d1-84c7-c731a06c2830 Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
1 parent e78314a commit a8b2f87

4 files changed

Lines changed: 92 additions & 12 deletions

File tree

:GITHUB_ENV

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COPILOT_SETUP_COMPLETE=true

IntelliTect.TestTools.Console.Tests/WildcardMatchAnalyzerTests.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,63 @@ public void GenerateDetailedDiff_WithMismatch_ShowsFailure()
128128
Assert.IsFalse(string.IsNullOrEmpty(diff));
129129
StringAssert.Contains(diff, "❌"); // Should contain failure marker
130130
}
131+
132+
[TestMethod]
133+
public void AnalyzeMatch_EmptyStrings_HandlesGracefully()
134+
{
135+
// Arrange & Act
136+
var results = WildcardMatchAnalyzer.AnalyzeMatch("", "");
137+
138+
// Assert - Empty strings result in no lines to compare
139+
Assert.AreEqual(0, results.Count);
140+
}
141+
142+
[TestMethod]
143+
public void AnalyzeMatch_QuestionMarkWildcard_TracksMatch()
144+
{
145+
// Arrange
146+
string expected = "test?";
147+
string actual = "test1";
148+
149+
// Act
150+
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
151+
152+
// Assert
153+
Assert.AreEqual(1, results.Count);
154+
Assert.IsTrue(results[0].IsMatch);
155+
Assert.AreEqual(1, results[0].WildcardMatches.Count);
156+
Assert.AreEqual("?", results[0].WildcardMatches[0].Pattern);
157+
Assert.AreEqual("1", results[0].WildcardMatches[0].MatchedText);
158+
}
159+
160+
[TestMethod]
161+
public void AnalyzeMatch_MultipleConsecutiveWildcards_HandlesCorrectly()
162+
{
163+
// Arrange
164+
string expected = "a***b";
165+
string actual = "aXXXb";
166+
167+
// Act
168+
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
169+
170+
// Assert
171+
Assert.AreEqual(1, results.Count);
172+
Assert.IsTrue(results[0].IsMatch);
173+
}
174+
175+
[TestMethod]
176+
public void AnalyzeMatch_MixedLineEndings_HandlesCorrectly()
177+
{
178+
// Arrange
179+
string expected = "Line 1\r\nLine 2";
180+
string actual = "Line 1\nLine 2";
181+
182+
// Act
183+
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
184+
185+
// Assert
186+
Assert.AreEqual(2, results.Count);
187+
Assert.IsTrue(results[0].IsMatch);
188+
Assert.IsTrue(results[1].IsMatch);
189+
}
131190
}

IntelliTect.TestTools.Console/ConsoleAssert.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -585,15 +585,19 @@ private static string GetMessageText(string expectedOutput, string output, strin
585585
else
586586
{
587587
// Write the output that shows the difference.
588-
for (int counter = 0; counter < Math.Min(expectedOutput.Length, output.Length); counter++)
588+
// Skip character-by-character comparison for wildcard matching as it's not meaningful
589+
if (!isWildcardMatching)
589590
{
590-
if (expectedOutput[counter] != output[counter]) // TODO: The message is invalid when using wild cards.
591+
for (int counter = 0; counter < Math.Min(expectedOutput.Length, output.Length); counter++)
591592
{
592-
result += Environment.NewLine
593-
+ $"Character {counter} did not match: "
594-
+ $"'{CSharpStringEncode(expectedOutput[counter])}' != '{CSharpStringEncode(output[counter])})'";
595-
596-
break;
593+
if (expectedOutput[counter] != output[counter])
594+
{
595+
result += Environment.NewLine
596+
+ $"Character {counter} did not match: "
597+
+ $"'{CSharpStringEncode(expectedOutput[counter])}' != '{CSharpStringEncode(output[counter])})'";
598+
599+
break;
600+
}
597601
}
598602
}
599603
}
@@ -606,13 +610,17 @@ private static string GetMessageText(string expectedOutput, string output, strin
606610
var matchResults = WildcardMatchAnalyzer.AnalyzeMatch(expectedOutput, output);
607611
result += WildcardMatchAnalyzer.GenerateDetailedDiff(matchResults);
608612
}
609-
catch (ArgumentException)
613+
catch (ArgumentException ex)
610614
{
611-
// Pattern analysis failed - skip detailed diff
615+
// Pattern analysis failed - inform user but don't crash
616+
result += Environment.NewLine +
617+
$"⚠️ Note: Could not generate detailed wildcard analysis: {ex.Message}";
612618
}
613-
catch (InvalidOperationException)
619+
catch (InvalidOperationException ex)
614620
{
615-
// Analysis encountered an unexpected state - skip detailed diff
621+
// Analysis encountered an unexpected state - inform user but don't crash
622+
result += Environment.NewLine +
623+
$"⚠️ Note: Wildcard analysis encountered an error: {ex.Message}";
616624
}
617625
}
618626

IntelliTect.TestTools.Console/WildcardMatchAnalyzer.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Text;
2+
13
namespace IntelliTect.TestTools.Console;
24

35
/// <summary>
@@ -172,7 +174,17 @@ private static bool MatchLineWithWildcards(string pattern, string text, List<Wil
172174

173175
/// <summary>
174176
/// Extracts what each wildcard in the pattern matched in the text.
175-
/// This uses a greedy approach to match wildcards.
177+
///
178+
/// Algorithm:
179+
/// 1. For '*': Greedily matches text until the next literal character in pattern
180+
/// 2. For '?': Matches exactly one character
181+
/// 3. For '[...]': Matches one character from the set
182+
///
183+
/// Note: This is a simplified extraction that uses a greedy approach and may not
184+
/// perfectly represent the actual backtracking behavior of WildcardPattern.IsMatch().
185+
/// It's designed to give users helpful debugging information rather than to be a
186+
/// perfect replica of the matching engine. In complex patterns with multiple wildcards,
187+
/// the actual match may differ from what this heuristic reports.
176188
/// </summary>
177189
private static void ExtractWildcardMatches(string pattern, string text, List<WildcardMatch> wildcardMatches)
178190
{

0 commit comments

Comments
 (0)