Skip to content

Add additional unit tests for appender string #10763

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
68 changes: 68 additions & 0 deletions std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ if (is(Range == U*, U) && isIterable!U && !isAutodecodableString!Range && !isInf
}
}





Comment on lines +330 to +333
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addition of whitespace here looks unnecessary.

/**
Convert a narrow autodecoding string to an array type that fully supports
random access. This is handled as a special case and always returns an array
Expand Down Expand Up @@ -3774,6 +3778,70 @@ if (isDynamicArray!A)
assert(app2[] == [ 1, 2, 3, 4, 5, 6 ]);
}

//https://github.com/dlang/phobos/pull/8789 issue for InPLaceAppenders
@safe pure nothrow unittest
{
import std.array : appender;

// Append characters one by one
auto a = appender!string();
foreach (c; "Dlang")
a.put(c);
assert(a[] == "Dlang");
}

@safe pure nothrow unittest
{
import std.array : appender;

// Append full strings
auto a = appender!string();
a.put("Hello");
a.put(", ");
a.put("world!");
assert(a[] == "Hello, world!");
}



Comment on lines +3842 to +3844
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please trim this to a single empty line between the two unittests. (No need for three of them.)

@safe pure nothrow unittest
{
import std.array : appender;

// Append special characters
auto a = appender!string();
a.put("€"); // Euro sign (3 bytes in UTF-8)
a.put("✓");
assert(a[] == "€✓");
}

@safe pure nothrow unittest
{
import std.array : appender;

// Append with escape sequences
auto a = appender!string();
a.put("Line1\n");
a.put("Line2\tTabbed");
assert(a[] == "Line1\nLine2\tTabbed");
}

@safe pure nothrow unittest
{
import std.array : appender;

// Append empty strings
auto a = appender!string();
a.put("");
a.put("non-empty");
a.put("");
assert(a[] == "non-empty");
}





Comment on lines +3878 to +3882
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please trim this to a single empty line between the unittest and the struct.

package(std) struct InPlaceAppender(A)
if (isDynamicArray!A)
{
Expand Down