Skip to content

Commit 74c14e2

Browse files
committed
Add unittests
1 parent 7c51a53 commit 74c14e2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

std/conv.d

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4834,6 +4834,40 @@ if (T.length > 0) { return textImpl!dstring(args); }
48344834
assert(dtext(cs, ' ', ws, " ", ds) == "今日は 여보세요 Здравствуйте"d);
48354835
}
48364836

4837+
// ensure that ranges are still printed properly
4838+
@safe unittest
4839+
{
4840+
static struct Range
4841+
{
4842+
int counter = 0;
4843+
4844+
@safe pure nothrow @nogc:
4845+
bool empty() const => (counter <= 0);
4846+
int front() const => counter;
4847+
void popFront() { --counter; }
4848+
}
4849+
4850+
auto m = Range(2);
4851+
const c = Range(3);
4852+
assert(text(m) == "[2, 1]");
4853+
assert(text(c) == "const(Range)(3)");
4854+
}
4855+
4856+
// ensure that a usage pattern seen in libraries like "unit-threaded" keeps working
4857+
@safe unittest
4858+
{
4859+
static final class Foo
4860+
{
4861+
override string toString() const @safe
4862+
{
4863+
return ":-)";
4864+
}
4865+
}
4866+
4867+
const c = new Foo();
4868+
assert(text(c) == ":-)");
4869+
}
4870+
48374871
private S textImpl(S, U...)(const(U) args)
48384872
{
48394873
static if (U.length == 0)

0 commit comments

Comments
 (0)