-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWildcardMatchAnalyzerTests.cs
More file actions
220 lines (181 loc) · 6.99 KB
/
Copy pathWildcardMatchAnalyzerTests.cs
File metadata and controls
220 lines (181 loc) · 6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace IntelliTect.TestTools.Console.Tests;
[TestClass]
public class WildcardMatchAnalyzerTests
{
/// <summary>
/// Calls <see cref="WildcardMatchAnalyzer.AnalyzeMatch"/> then
/// <see cref="WildcardMatchAnalyzer.GenerateDetailedDiff"/> and asserts the result is non-empty.
/// </summary>
private static string GetDiff(string expected, string actual)
{
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
string diff = WildcardMatchAnalyzer.GenerateDetailedDiff(results);
Assert.IsFalse(string.IsNullOrEmpty(diff));
return diff;
}
[TestMethod]
public void AnalyzeMatch_SingleLineMatch_IdentifiesWildcardMatches()
{
// Arrange
string expected = "Hello * world";
string actual = "Hello beautiful world";
// Act
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
// Assert
Assert.AreEqual(1, results.Count);
Assert.IsTrue(results[0].IsMatch);
Assert.AreEqual(1, results[0].WildcardMatches.Count);
// The * matches "beautiful" (without trailing space because "world" comes next)
Assert.AreEqual("beautiful", results[0].WildcardMatches[0].MatchedText);
}
[TestMethod]
public void AnalyzeMatch_MultipleWildcards_TracksAllMatches()
{
// Arrange
string expected = "PING *(* (::1)) * data bytes";
string actual = "PING localhost(localhost (::1)) 56 data bytes";
// Act
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
// Assert
Assert.AreEqual(1, results.Count);
Assert.IsTrue(results[0].IsMatch);
Assert.IsTrue(results[0].WildcardMatches.Count >= 2);
}
[TestMethod]
public void AnalyzeMatch_Mismatch_IdentifiesFailure()
{
// Arrange
string expected = "Hello world";
string actual = "Hello universe";
// Act
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
// Assert
Assert.AreEqual(1, results.Count);
Assert.IsFalse(results[0].IsMatch);
}
[TestMethod]
public void AnalyzeMatch_ExtraLinesInActual_MarkedAsUnexpected()
{
// Arrange
string expected = "Line 1\nLine 2";
string actual = "Line 1\nLine 2\nLine 3";
// Act
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
// Assert
Assert.AreEqual(3, results.Count);
Assert.IsTrue(results[0].IsMatch);
Assert.IsTrue(results[1].IsMatch);
Assert.IsFalse(results[2].IsMatch); // Extra line
Assert.IsNull(results[2].ExpectedLine);
Assert.IsNotNull(results[2].ActualLine);
}
[TestMethod]
public void AnalyzeMatch_MissingLinesInActual_MarkedAsMissing()
{
// Arrange
string expected = "Line 1\nLine 2\nLine 3";
string actual = "Line 1\nLine 2";
// Act
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
// Assert
Assert.AreEqual(3, results.Count);
Assert.IsTrue(results[0].IsMatch);
Assert.IsTrue(results[1].IsMatch);
Assert.IsFalse(results[2].IsMatch); // Missing line
Assert.IsNotNull(results[2].ExpectedLine);
Assert.IsNull(results[2].ActualLine);
}
[TestMethod]
public void GenerateDetailedDiff_CreatesReadableOutput()
{
string diff = GetDiff("Hello * world\nLine *", "Hello beautiful world\nLine 2");
StringAssert.Contains(diff, "Line-by-line comparison");
StringAssert.Contains(diff, "✅");
StringAssert.Contains(diff, "Wildcard matches");
}
[TestMethod]
public void GenerateDetailedDiff_WithMismatch_ShowsFailure()
{
string diff = GetDiff("Expected text", "Actual text");
StringAssert.Contains(diff, "❌");
}
[TestMethod]
public void AnalyzeMatch_EmptyStrings_HandlesGracefully()
{
// Arrange & Act
var results = WildcardMatchAnalyzer.AnalyzeMatch("", "");
// Assert - Empty strings result in no lines to compare
Assert.AreEqual(0, results.Count);
}
[TestMethod]
public void AnalyzeMatch_QuestionMarkWildcard_TracksMatch()
{
// Arrange
string expected = "test?";
string actual = "test1";
// Act
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
// Assert
Assert.AreEqual(1, results.Count);
Assert.IsTrue(results[0].IsMatch);
Assert.AreEqual(1, results[0].WildcardMatches.Count);
Assert.AreEqual("?", results[0].WildcardMatches[0].Pattern);
Assert.AreEqual("1", results[0].WildcardMatches[0].MatchedText);
}
[TestMethod]
public void AnalyzeMatch_QuestionMarkWildcard_FailsOnTooManyChars()
{
// '?' matches exactly one character — "test12" has two chars after "test"
var results = WildcardMatchAnalyzer.AnalyzeMatch("test?", "test12");
Assert.AreEqual(1, results.Count);
Assert.IsFalse(results[0].IsMatch);
}
[TestMethod]
public void AnalyzeMatch_CharacterClass_TracksMatch()
{
string expected = "value[0-9]";
string actual = "value5";
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
Assert.AreEqual(1, results.Count);
Assert.IsTrue(results[0].IsMatch);
Assert.AreEqual(1, results[0].WildcardMatches.Count);
Assert.AreEqual("value5"[5].ToString(), results[0].WildcardMatches[0].MatchedText);
}
[TestMethod]
public void AnalyzeMatch_StarAtStart_MatchesLeadingText()
{
var results = WildcardMatchAnalyzer.AnalyzeMatch("* end", "long prefix end");
Assert.AreEqual(1, results.Count);
Assert.IsTrue(results[0].IsMatch);
Assert.AreEqual(1, results[0].WildcardMatches.Count);
Assert.AreEqual("long prefix", results[0].WildcardMatches[0].MatchedText);
}
[TestMethod]
public void AnalyzeMatch_MultipleConsecutiveWildcards_HandlesCorrectly()
{
string expected = "a***b";
string actual = "aXXXb";
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
Assert.AreEqual(1, results.Count);
Assert.IsTrue(results[0].IsMatch);
// Consecutive '*' wildcards collapse to a single WildcardMatch entry
Assert.AreEqual(1, results[0].WildcardMatches.Count);
Assert.AreEqual("*", results[0].WildcardMatches[0].Pattern);
Assert.AreEqual("XXX", results[0].WildcardMatches[0].MatchedText);
}
[TestMethod]
public void AnalyzeMatch_MixedLineEndings_HandlesCorrectly()
{
// Arrange
string expected = "Line 1\r\nLine 2";
string actual = "Line 1\nLine 2";
// Act
var results = WildcardMatchAnalyzer.AnalyzeMatch(expected, actual);
// Assert
Assert.AreEqual(2, results.Count);
Assert.IsTrue(results[0].IsMatch);
Assert.IsTrue(results[1].IsMatch);
}
}