dialect.assertgen

Interactive assert statement generation from raw IRC strings, for use in source code unittest blocks.

Members

Functions

callGetopt
auto callGetopt(string[] args)

Parses command-line arguments into a Configuration struct.

createParser
auto createParser(IRCParser parser, Configuration configuration)

Creates an IRCParser with values taken from the passed Configuration.

inputLoop
void inputLoop(IRCParser parser, Configuration configuration)

Main input loop for the assertgen tool.

inputServerInformation
void inputServerInformation(IRCParser parser, Configuration configuration)

Asks the user to enter server information via standard input.

parseServerInformation
void parseServerInformation(IRCParser parser, Configuration configuration)

Parses server information from a Configuration struct and populates an IRCParser with it.

putClientServerDelta
void putClientServerDelta(Sink sink, IRCClient client, IRCServer server, uint indents)

Constructs assignment block deltastrings for an IRCClient and an IRCServer, as if they were members of an IRCParser instance, and writes them to an output range.

putEventAssertBlock
void putEventAssertBlock(Sink sink, IRCEvent event, uint indents)

Constructs assert block deltastrings for an IRCEvent and writes them to an output range.

Structs

Configuration
struct Configuration

Configuration struct for the assertgen tool. An aggregate of the options that were passed on the command line.

Examples

$ dub run :assertgen
(...)

// Paste a raw event string and hit Enter to generate an assert block. Ctrl+C to exit.

:silver.libera.chat 338 zorael livemarshal 2625:6400:11:5bf:6f57:829d:f62e:2d8c :actually using host

{ enum input = :silver.libera.chat 338 zorael livemarshal 2625:6400:11:5bf:6f57:829d:f62e:2d8c :actually using host; immutable event = parser.toIRCEvent(input);

with (event) { assert((type == IRCEvent.Type.RPL_WHOISACTUALLY), type.toString()); assert((sender.address == "silver.libera.chat"), sender.address); assert((target.nickname == "livemarshal"), target.nickname); assert((content == "actually using host"), content); assert((aux[0] == "2625:6400:11:5bf:6f57:829d:f62e:2d8c"), aux[0]); assert((num == 338), num.to!string); } }

These can be directly copy/pasted into the appropriate files in /tests. They carry state from the events pasted before it, and the delta between them are also expressed as separate asserts.

$ dub run :assertgen
(...)

// Paste a raw event string and hit Enter to generate an assert block. Ctrl+C to exit.

@badge-info=;badges=;color=#5F9EA0;display-name=Zorael;emote-sets=0,185411,771823,1511983;user-id=22216721;user-type= :tmi.twitch.tv GLOBALUSERSTATE

{ enum input = @badge-info=;badges=;color=#5F9EA0;display-name=Zorael;emote-sets=0,185411,771823,1511983;user-id=22216721;user-type= :tmi.twitch.tv GLOBALUSERSTATE; immutable event = parser.toIRCEvent(input);

with (event) { assert((type == IRCEvent.Type.GLOBALUSERSTATE), type.toString()); assert((sender.address == "tmi.twitch.tv"), sender.address); assert((sender.id == 22216721), sender.id.to!string); assert((target.nickname == "dialect"), target.nickname); assert((target.account == "dialect"), target.account); assert((target.displayName == "Zorael"), target.displayName); assert((target.badges == "*"), target.badges); assert((target.colour == "5F9EA0"), target.colour); assert((tags == "badge-info=;badges=;color=#5F9EA0;display-name=Zorael;emote-sets=0,185411,771823,1511983;user-id=22216721;user-type="), tags); } }

with (parser) { assert((client.displayName == "Zorael"), client.displayName); }

This makes it easy to generate tests that verify wanted side-effects incurred by events, and to catch unwanted ones.

There is a shorthand --twitch flag that sets up the parser for Twitch. This requires version TwitchSupport.

$ dub run :assertgen -- --twitch
(...)

Server set to Twitch as per command-line argument.

// Paste a raw event string and hit Enter to generate an assert block. Ctrl+C to exit.

@badge-info=subscriber/15;badges=subscriber/12;color=;display-name=SomeoneOnTwitch;emotes=;flags=;id=d6229854-2bf3-415d-80ce-a2fe84d00a23;login=someoneontwitch;mod=0;msg-id=submysterygift;msg-param-mass-gift-count=1;msg-param-origin-id=49\s9d\s3e\s68\sca\s26\se9\s2a\s6e\s44\sd4\s60\s9b\s3d\saa\sb9\s4c\sad\s43\s5c;msg-param-sender-count=4;msg-param-sub-plan=1000;room-id=71092938;subscriber=1;system-msg=SomeoneOnTwitch\sis\sgifting\s1\sTier\s1\sSubs\sto\sSome_Streamer's\scommunity!\sThey've\sgifted\sa\stotal\sof\s4\sin\sthe\schannel!;tmi-sent-ts=1569013433362;user-id=22454856921;user-type= :tmi.twitch.tv USERNOTICE #some_streamer

{ enum input = @badge-info=subscriber/15;badges=subscriber/12;color=;display-name=SomeoneOnTwitch;emotes=;flags=;id=d6229854-2bf3-415d-80ce-a2fe84d00a23;login=someoneontwitch;mod=0;msg-id=submysterygift;msg-param-mass-gift-count=1;msg-param-origin-id=49\s9d\s3e\s68\sca\s26\se9\s2a\s6e\s44\sd4\s60\s9b\s3d\saa\sb9\s4c\sad\s43\s5c;msg-param-sender-count=4;msg-param-sub-plan=1000;room-id=71092938;subscriber=1;system-msg=SomeoneOnTwitch\sis\sgifting\s1\sTier\s1\sSubs\sto\sSome_Streamer's\scommunity!\sThey've\sgifted\sa\stotal\sof\s4\sin\sthe\schannel!;tmi-sent-ts=1569013433362;user-id=2245456921;user-type= :tmi.twitch.tv USERNOTICE #some_streamer; immutable event = parser.toIRCEvent(input);

with (event) { assert((type == IRCEvent.Type.TWITCH_BULKGIFT), type.toString()); assert((sender.nickname == "someoneontwitch"), sender.nickname); assert((sender.address == "tmi.twitch.tv"), sender.address); assert((sender.account == "someoneontwitch"), sender.account); assert((sender.displayName == "SomeoneOnTwitch"), sender.displayName); assert((sender.badges == "subscriber/15"), sender.badges); assert((sender.id == 2245456921), sender.id.to!string); assert((channel == "#some_streamer"), channel); assert((content == "SomeoneOnTwitch is gifting 1 Tier 1 Subs to Some_Streamer's community! They've gifted a total of 4 in the channel!"), content); assert((aux[0] == "1000"), aux[0]); assert((count[0] == 1), count[0].to!string); assert((count[1] == 4), count[1].to!string); assert((tags == "badge-info=subscriber/15;badges=subscriber/12;color=;display-name=SomeoneOnTwitch;emotes=;flags=;id=d6229854-2bf3-415d-80ce-a2fe84d00a23;login=someoneontwitch;mod=0;msg-id=submysterygift;msg-param-mass-gift-count=1;msg-param-origin-id=49\\s9d\\s3e\\s68\\sca\\s26\\se9\\s2a\\s6e\\s44\\sd4\\s60\\s9b\\s3d\\saa\\sb9\\s4c\\sad\\s43\\s5c;msg-param-sender-count=4;msg-param-sub-plan=1000;room-id=71092938;subscriber=1;system-msg=SomeoneOnTwitch\\sis\\sgifting\\s1\\sTier\\s1\\sSubs\\sto\\sSome_Streamer's\\scommunity!\\sThey've\\sgifted\\sa\\stotal\\sof\\s4\\sin\\sthe\\schannel!;tmi-sent-ts=1569013433362;user-id=2245456921;user-type="), tags); assert((id == "d6229854-2bf3-415d-80ce-a2fe84d00a23"), id); } }

Meta