Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: add tests for extension methods for CollectionBuilder{byte} structure #39

Merged
merged 3 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Yuh.Collections.Tests/CollectionBuilderExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ public void ToListTest(int[][] items)

[Theory]
[ClassData(typeof(StringArrayData))]
public void ToSystemStringFromUtf8StringBuilder(string[] data)
public void ToStringFromUtf8StringTest(string[] data)
{
CollectionBuilder<byte> builder = [];
DefaultInterpolatedStringHandler handler = new(data.Select(x => x.Length).Sum(), 0);
DefaultInterpolatedStringHandler handler = new(0, data.Length);

try
{
foreach (var s in data)
foreach (var str in data)
{
builder.AppendLiteral(s);
handler.AppendLiteral(s);
builder.AppendLiteral(str);
handler.AppendFormatted(str);
}

Assert.Equal(handler.ToStringAndClear(), builder.ToSystemString());
Expand Down
2 changes: 1 addition & 1 deletion src/Yuh.Collections/CollectionBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public static string ToSystemString(in this CollectionBuilder<byte> builder)
try
{
builder.CopyTo(bytes.AsSpan());
return Encoding.UTF8.GetString(bytes[..builder.Count]);
return Encoding.UTF8.GetString(bytes.AsSpan()[..length]);
}
finally
{
Expand Down
Loading