From b037967ed067d3766b79ba49ce03dec2d8060752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 25 Oct 2019 14:13:30 +0200 Subject: [PATCH] Add unit test. --- source/taggedalgebraic/taggedunion.d | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/taggedalgebraic/taggedunion.d b/source/taggedalgebraic/taggedunion.d index dc1a6ac..7fe07e7 100644 --- a/source/taggedalgebraic/taggedunion.d +++ b/source/taggedalgebraic/taggedunion.d @@ -479,6 +479,23 @@ unittest { // alignment else assert((cast(ubyte*)&s3.vValue() - cast(ubyte*)&s3) % 4 == 0); } +unittest { // toString + import std.conv : to; + + static struct NoCopy { + @disable this(this); + string toString() const { return "foo"; } + } + + union U { Void empty; int i; NoCopy noCopy; } + TaggedUnion!U val; + assert(val.to!string == "empty"); + val.setI(42); + assert(val.to!string == "(i: 42)"); + val.setNoCopy(NoCopy.init); + assert(val.to!string == "(noCopy: foo)"); +} + /** Dispatches the value contained on a `TaggedUnion` to a set of visitors.