// ReSharper disable StringLiteralTypo using TUnit.Assertions.AssertConditions.Throws; namespace IRCSharp.Tests.Tokenization; public class Format { [Test] public async Task Tags() { var line = new Line("PRIVMSG", "#channel", "hello") { Tags = new Dictionary {{"id", "\\ ;\r\n"}} }.Format(); await Assert.That(line).IsEqualTo(@"@id=\\\s\:\r\n PRIVMSG #channel hello"); } [Test] public async Task MissingTag() { var line = new Line("PRIVMSG", "#channel", "hello").Format(); await Assert.That(line).IsEqualTo("PRIVMSG #channel hello"); } [Test] public async Task NullTag() { var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new Dictionary {{"a", null}}} .Format(); await Assert.That(line).IsEqualTo("@a PRIVMSG #channel hello"); } [Test] public async Task EmptyTag() { var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new Dictionary {{"a", ""}}} .Format(); await Assert.That(line).IsEqualTo("@a PRIVMSG #channel hello"); } [Test] public async Task Source() { var line = new Line("PRIVMSG", "#channel", "hello") {Source = "nick!user@host"}.Format(); await Assert.That(line).IsEqualTo(":nick!user@host PRIVMSG #channel hello"); } [Test] public async Task CommandLowercase() { var line = new Line {Command = "privmsg"}.Format(); await Assert.That(line).IsEqualTo("privmsg"); } [Test] public async Task CommandUppercase() { var line = new Line {Command = "PRIVMSG"}.Format(); await Assert.That(line).IsEqualTo("PRIVMSG"); } [Test] public async Task TrailingSpace() { var line = new Line("PRIVMSG", "#channel", "hello world").Format(); await Assert.That(line).IsEqualTo("PRIVMSG #channel :hello world"); } [Test] public async Task TrailingNoSpace() { var line = new Line("PRIVMSG", "#channel", "helloworld").Format(); await Assert.That(line).IsEqualTo("PRIVMSG #channel helloworld"); } [Test] public async Task TrailingDoubleColon() { var line = new Line("PRIVMSG", "#channel", ":helloworld").Format(); await Assert.That(line).IsEqualTo("PRIVMSG #channel ::helloworld"); } [Test] public async Task InvalidNonLastSpace() { await Assert.That(() => new Line("USER", "user", "0 *", "real name").Format()).Throws(); } [Test] public async Task InvalidNonLastColon() { await Assert.That(() => new Line("PRIVMSG", ":#channel", "hello").Format()).Throws(); } }