dialect.assertgen

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

Members

Functions

main
int main(string[] args)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

$ dub run :assertgen
(...)

// 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=tayk47_mom;emotes=;flags=;id=d6729804-2bf3-495d-80ce-a2fe8ed00a26;login=tayk47_mom;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=tayk47_mom\sis\sgifting\s1\sTier\s1\sSubs\sto\sxQcOW's\scommunity!\sThey've\sgifted\sa\stotal\sof\s4\sin\sthe\schannel!;tmi-sent-ts=1569013433362;user-id=224578549;user-type= :tmi.twitch.tv USERNOTICE #xqcow

{ immutable event = parser.toIRCEvent("@badge-info=subscriber/15;badges=subscriber/12;color=;display-name=tayk47_mom;emotes=;flags=;id=d6729804-2bf3-495d-80ce-a2fe8ed00a26;login=tayk47_mom;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=tayk47_mom\\sis\\sgifting\\s1\\sTier\\s1\\sSubs\\sto\\sxQcOW's\\scommunity!\\sThey've\\sgifted\\sa\\stotal\\sof\\s4\\sin\\sthe\\schannel!;tmi-sent-ts=1569013433362;user-id=224578549;user-type= :tmi.twitch.tv USERNOTICE #xqcow"); with (event) { assert((type == IRCEvent.Type.TWITCH_BULKGIFT), Enum!(IRCEvent.Type).toString(type)); assert((sender.nickname == "tayk47_mom"), sender.nickname); assert((sender.displayName == "tayk47_mom"), sender.displayName); assert((sender.account == "tayk47_mom"), sender.account); assert((sender.badges == "subscriber/12"), sender.badges); assert((channel == "#xqcow"), channel); assert((content == "tayk47_mom is gifting 1 Tier 1 Subs to xQcOW's community! They've gifted a total of 4 in the channel!"), content); assert((aux == "1000"), aux); assert((tags == "badge-info=subscriber/15;badges=subscriber/12;color=;display-name=tayk47_mom;emotes=;flags=;id=d6729804-2bf3-495d-80ce-a2fe8ed00a26;login=tayk47_mom;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-cou nt=4;msg-param-sub-plan=1000;room-id=71092938;subscriber=1;system-msg=tayk47_mom\\sis\\sgifting\\s1\\sTier\\s1\\sSubs\\sto\\sxQcOW's\\scommunity!\\sThey've\\sgifted\\sa\\stotal\\sof\\s 4\\sin\\sthe\\schannel!;tmi-sent-ts=1569013433362;user-id=224578549;user-type="), tags); assert((count == 1), count.to!string); assert((altcount == 4), altcount.to!string); assert((id == "d6729804-2bf3-495d-80ce-a2fe8ed00a26"), id); } }

These can be directly copy/pasted into the appropriate files in /tests. They only carry state from the events pasted before it, but the changes made are also expressed as 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

{ immutable event = parser.toIRCEvent("@badge-info=;badges=;color=#5F9EA0;display-name=Zorael;emote-sets=0,185411,771823,1511983;user-id=22216721;user-type= :tmi.twitch.tv GLOBALUSERSTATE"); with (event) { assert((type == IRCEvent.Type.GLOBALUSERSTATE), Enum!(IRCEvent.Type).toString(type)); assert((sender.address == "tmi.twitch.tv"), sender.address); assert((sender.class_ == IRCUser.Class.special), Enum!(IRCUser.Class).toString(sender.class_)); assert((target.nickname == "zorael"), target.nickname); assert((target.displayName == "Zorael"), target.displayName); assert((target.class_ == IRCUser.Class.admin), Enum!(IRCUser.Class).toString(target.class_)); 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.client) { assert((displayName == "Zorael"), displayName); }

This makes it easy to generate tests that verify wanted side-effects incurred by events.

Meta