formatEventAssertBlock

Constructs assert statement blocks for each changed field of an IRCEvent.

version(AssertGeneration)
private pure @safe
void
formatEventAssertBlock
(
Sink
)
(
auto ref Sink sink
,)
if (
isOutputRange!(Sink, char[])
)

Parameters

sink Sink

Output buffer to write to.

event IRCEvent

IRCEvent to construct assert statements for.

Examples

IRCEvent event;
Appender!(char[]) sink;
sink.formatEventAssertBlock(event);
    import lu.deltastrings : formatDeltaInto;
    import lu.string : tabs;
    import std.array : Appender;
    import std.format : formattedWrite;

    Appender!(char[]) sink;
    sink.reserve(1024);

    IRCClient client;
    IRCServer server;
    auto parser = IRCParser(client, server);

    immutable event = parser.toIRCEvent(":zorael!~NaN@2001:41d0:2:80b4:: PRIVMSG #flerrp :kameloso: 8ball");

    // copy/paste the above
    sink.put("{\n");
    sink.formattedWrite("%simmutable event = parser.toIRCEvent(\"%s\");\n", 1.tabs, event.raw);
    sink.formattedWrite("%swith (event)\n", 1.tabs);
    sink.formattedWrite("%s{\n", 1.tabs);
    sink.formatDeltaInto!(Yes.asserts)(IRCEvent.init, event, 2);
    sink.formattedWrite("%s}\n", 1.tabs);
    sink.put("}");

    assert(sink.data ==
`{
    immutable event = parser.toIRCEvent(":zorael!~NaN@2001:41d0:2:80b4:: PRIVMSG #flerrp :kameloso: 8ball");
    with (event)
    {
        assert((type == IRCEvent.Type.CHAN), Enum!(IRCEvent.Type).toString(type));
        assert((sender.nickname == "zorael"), sender.nickname);
        assert((sender.ident == "~NaN"), sender.ident);
        assert((sender.address == "2001:41d0:2:80b4::"), sender.address);
        assert((channel == "#flerrp"), channel);
        assert((content == "kameloso: 8ball"), content);
    }
}`, '\n' ~ sink.data);