From 74c14e2d9b5d651e83e19ac1d8b9d64ad37a4692 Mon Sep 17 00:00:00 2001 From: Elias Batek Date: Sun, 29 Dec 2024 03:27:48 +0100 Subject: [PATCH] Add unittests --- std/conv.d | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/std/conv.d b/std/conv.d index c35a82ade74..cf496c9a8eb 100644 --- a/std/conv.d +++ b/std/conv.d @@ -4834,6 +4834,40 @@ if (T.length > 0) { return textImpl!dstring(args); } assert(dtext(cs, ' ', ws, " ", ds) == "今日は 여보세요 Здравствуйте"d); } +// ensure that ranges are still printed properly +@safe unittest +{ + static struct Range + { + int counter = 0; + + @safe pure nothrow @nogc: + bool empty() const => (counter <= 0); + int front() const => counter; + void popFront() { --counter; } + } + + auto m = Range(2); + const c = Range(3); + assert(text(m) == "[2, 1]"); + assert(text(c) == "const(Range)(3)"); +} + +// ensure that a usage pattern seen in libraries like "unit-threaded" keeps working +@safe unittest +{ + static final class Foo + { + override string toString() const @safe + { + return ":-)"; + } + } + + const c = new Foo(); + assert(text(c) == ":-)"); +} + private S textImpl(S, U...)(const(U) args) { static if (U.length == 0)