Skip to content

Commit 1119960

Browse files
committed
.
1 parent 56e783c commit 1119960

10 files changed

Lines changed: 30 additions & 50 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"Array": null
3-
}
3+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"Array": null
3-
}
3+
}

src/Verify.ExceptionParsing.Tests/ExceptionMessageFormatSamples.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public Task AllCategories()
1414
};
1515
var notEquals = new List<NotEqualResult>
1616
{
17-
new(new("txt", Dir("MyTests.Test2.received.txt"), Dir("MyTests.Test2.verified.txt")), null, new("received text"), new("verified text"))
17+
new(new("txt", Dir("MyTests.Test2.received.txt"), Dir("MyTests.Test2.verified.txt")), null, new("received text"), "verified text")
1818
};
1919
var delete = new List<string>
2020
{
@@ -33,7 +33,7 @@ public Task NotEqualWithMessage()
3333
{
3434
var notEquals = new List<NotEqualResult>
3535
{
36-
new(new("txt", Dir("MyTests.Test1.received.txt"), Dir("MyTests.Test1.verified.txt")), "The comparer reported a difference", new("received text"), new("verified text"))
36+
new(new("txt", Dir("MyTests.Test1.received.txt"), Dir("MyTests.Test1.verified.txt")), "The comparer reported a difference", new("received text"), "verified text")
3737
};
3838

3939
return BuildVerify([], notEquals, [], []);

src/Verify.ExceptionParsing.Tests/ExceptionParsingTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Task WithMessage()
3131
{
3232
var notEquals = new List<NotEqualResult>
3333
{
34-
new(new("txt", receivedTxt, verifiedTxt), "TheMessage", new("receivedText"), new("verifiedText")),
34+
new(new("txt", receivedTxt, verifiedTxt), "TheMessage", new("receivedText"), "verifiedText"),
3535
new(new("bin", receivedBin, verifiedBin), "TheMessage", null, null)
3636
};
3737

@@ -132,7 +132,7 @@ public Task SingleNotEqual()
132132
{
133133
var notEquals = new List<NotEqualResult>
134134
{
135-
new(new("txt", receivedTxt, verifiedTxt), null, new("receivedText"), new("verifiedText"))
135+
new(new("txt", receivedTxt, verifiedTxt), null, new("receivedText"), "verifiedText")
136136
};
137137

138138
return ParseVerify([], notEquals, [], []);
@@ -153,7 +153,7 @@ public Task MultipleItem()
153153
};
154154
var notEquals = new List<NotEqualResult>
155155
{
156-
new(new("txt", receivedTxt, verifiedTxt), null, new("receivedText"), new("verifiedText")),
156+
new(new("txt", receivedTxt, verifiedTxt), null, new("receivedText"), "verifiedText"),
157157
new(new("bin", receivedBin, verifiedBin), null, null, null)
158158
};
159159
var delete = new List<string>
@@ -178,7 +178,7 @@ public Task SingleItem()
178178
};
179179
var notEquals = new List<NotEqualResult>
180180
{
181-
new(new("txt", receivedTxt, verifiedTxt), null, new("receivedText"), new("verifiedText"))
181+
new(new("txt", receivedTxt, verifiedTxt), null, new("receivedText"), "verifiedText")
182182
};
183183
var delete = new List<string>
184184
{
@@ -242,4 +242,4 @@ static Task ParseVerify(
242242
result
243243
});
244244
}
245-
}
245+
}

src/Verify.ExceptionParsing.Tests/VerifyExceptionMessageBuilderTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public Task SingleNotEqual_Text() =>
4242
@new: [],
4343
notEquals:
4444
[
45-
new(new("txt", receivedTxt, verifiedTxt), null, new("received content"), new("verified content"))
45+
new(new("txt", receivedTxt, verifiedTxt), null, new("received content"), "verified content")
4646
],
4747
delete: [],
4848
equal: []);
@@ -53,7 +53,7 @@ public Task SingleNotEqual_WithMessage() =>
5353
@new: [],
5454
notEquals:
5555
[
56-
new(new("txt", receivedTxt, verifiedTxt), "Comparer reported difference", new("received content"), new("verified content"))
56+
new(new("txt", receivedTxt, verifiedTxt), "Comparer reported difference", new("received content"), "verified content")
5757
],
5858
delete: [],
5959
equal: []);
@@ -108,7 +108,7 @@ public Task AllCategories()
108108
};
109109
var notEquals = new List<NotEqualResult>
110110
{
111-
new(new("txt", receivedTxt, verifiedTxt), null, new("received"), new("verified"))
111+
new(new("txt", receivedTxt, verifiedTxt), null, new("received"), "verified")
112112
};
113113
var delete = new List<string>
114114
{
@@ -139,8 +139,8 @@ public Task MultipleNotEqual_MixedMessageAndNoMessage()
139139
{
140140
var notEquals = new List<NotEqualResult>
141141
{
142-
new(new("txt", receivedTxt, verifiedTxt), null, new("received text"), new("verified text")),
143-
new(new("txt", receivedTxt, verifiedTxt), "Custom comparison message", new("received2"), new("verified2"))
142+
new(new("txt", receivedTxt, verifiedTxt), null, new("received text"), "verified text"),
143+
new(new("txt", receivedTxt, verifiedTxt), "Custom comparison message", new("received2"), "verified2")
144144
};
145145

146146
return BuildVerify([], notEquals, [], []);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{}

src/Verify.Tests/NewLineTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ public async Task TrailingNewlinesRaw()
7878
var exception = await Assert.ThrowsAnyAsync<Exception>(() => Verify("a\n", settings));
7979
Assert.Contains("carriage return", exception.ToString());
8080

81-
// Trailing \n tolerance still applies for \n-only verified files
81+
// Trailing newlines are now compared exactly, with no tolerance
8282
await File.WriteAllTextAsync(file, "a\n");
8383
await Verify("a\n", settings);
84-
await Verify("a", settings);
84+
await Assert.ThrowsAsync<VerifyException>(() => Verify("a", settings));
8585

8686
await File.WriteAllTextAsync(file, "a\n\n");
8787
await Verify("a\n\n", settings);
88-
await Verify("a\n", settings);
88+
await Assert.ThrowsAsync<VerifyException>(() => Verify("a\n", settings));
8989
File.Delete(file);
9090
}
9191

src/Verify/Compare/Comparer.cs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ public static async Task<EqualityResult> Text(FilePair filePair, StringBuilder r
99
return new(Equality.New, null, received, null);
1010
}
1111

12-
var verifiedText = await File.ReadAllTextAsync(filePair.VerifiedPath);
13-
if (verifiedText.Contains('\r'))
12+
var verified = await File.ReadAllTextAsync(filePair.VerifiedPath);
13+
if (verified.Contains('\r'))
1414
{
1515
throw new($@"Verified file must use \n line endings, but it contains a \r (carriage return). Path: {filePair.VerifiedPath}. See https://github.com/verifytests/verify#text-file-settings");
1616
}
1717

18-
var verified = new StringBuilder(verifiedText);
1918
var result = await CompareStrings(filePair.Extension, received, verified, settings, bypassComparer);
2019
if (result.IsEqual)
2120
{
@@ -26,35 +25,16 @@ public static async Task<EqualityResult> Text(FilePair filePair, StringBuilder r
2625
return new(Equality.NotEqual, result.Message, received, verified);
2726
}
2827

29-
static Task<CompareResult> CompareStrings(string extension, StringBuilder received, StringBuilder verified, VerifySettings settings, bool bypassComparer)
28+
static Task<CompareResult> CompareStrings(string extension, StringBuilder received, string verified, VerifySettings settings, bool bypassComparer)
3029
{
31-
if (verified.Length > 0 &&
32-
verified.Length - 1 == received.Length &&
33-
verified.LastChar() == '\n')
34-
{
35-
verified.Length -= 1;
36-
}
37-
38-
// StringBuilder is broken on older .net https://github.com/dotnet/runtime/issues/27684
39-
#if NET6_0_OR_GREATER
40-
var isEqual = verified.Equals(received);
41-
if (!isEqual &&
42-
!bypassComparer &&
43-
settings.TryFindStringComparer(extension, out var compare))
44-
{
45-
return compare(received.ToString(), verified.ToString(), settings.Context);
46-
}
47-
#else
48-
var receivedString = received.ToString();
49-
var verifiedString = verified.ToString();
50-
var isEqual = receivedString.Equals(verifiedString);
30+
// StringBuilder.Equals(ReadOnlySpan<char>) is native on net6+ and provided by Polyfill on net framework
31+
var isEqual = received.Equals(verified.AsSpan());
5132
if (!isEqual &&
5233
!bypassComparer &&
5334
settings.TryFindStringComparer(extension, out var compare))
5435
{
55-
return compare(receivedString, verifiedString, settings.Context);
36+
return compare(received.ToString(), verified, settings.Context);
5637
}
57-
#endif
5838

5939
return Task.FromResult(new CompareResult(isEqual));
6040
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
readonly struct EqualityResult(Equality equality, string? message, StringBuilder? receivedText, StringBuilder? verifiedText)
1+
readonly struct EqualityResult(Equality equality, string? message, StringBuilder? receivedText, string? verifiedText)
22
{
33
public Equality Equality { get; } = equality;
44
public string? Message { get; } = message;
55
public StringBuilder? ReceivedText { get; } = receivedText;
6-
public StringBuilder? VerifiedText { get; } = verifiedText;
7-
}
6+
public string? VerifiedText { get; } = verifiedText;
7+
}

src/Verify/Verifier/NotEqualResult.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
FilePair file,
33
string? message,
44
StringBuilder? receivedText,
5-
StringBuilder? verifiedText)
5+
string? verifiedText)
66
{
77
public FilePair File { get; } = file;
88
public string? Message { get; } = message;
99
public StringBuilder? ReceivedText { get; } = receivedText;
10-
public StringBuilder? VerifiedText { get; } = verifiedText;
11-
}
10+
public string? VerifiedText { get; } = verifiedText;
11+
}

0 commit comments

Comments
 (0)