// ReSharper disable StringLiteralTypo 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" } } }; await Assert.That(line.Format()).IsEqualTo(@"@id=\\\s\:\r\n PRIVMSG #channel hello"); } [Test] public async Task MissingTag() { var line = new Line("PRIVMSG", "#channel", "hello"); await Assert.That(line.Format()).IsEqualTo("PRIVMSG #channel hello"); } [Test] public async Task NullTag() { var line = new Line("PRIVMSG", "#channel", "hello") { Tags = new Dictionary { { "a", null } } }; await Assert.That(line.Format()).IsEqualTo("@a PRIVMSG #channel hello"); } [Test] public async Task EmptyTag() { var line = new Line("PRIVMSG", "#channel", "hello") { Tags = new Dictionary { { "a", "" } } }; await Assert.That(line.Format()).IsEqualTo("@a PRIVMSG #channel hello"); } [Test] public async Task Source() { var line = new Line("PRIVMSG", "#channel", "hello") { Source = "nick!user@host" }; await Assert.That(line.Format()).IsEqualTo(":nick!user@host PRIVMSG #channel hello"); } [Test] public async Task CommandLowercase() { var line = new Line { Command = "privmsg" }; await Assert.That(line.Format()).IsEqualTo("privmsg"); } [Test] public async Task CommandUppercase() { var line = new Line { Command = "PRIVMSG" }; await Assert.That(line.Format()).IsEqualTo("PRIVMSG"); } [Test] public async Task TrailingSpace() { var line = new Line("PRIVMSG", "#channel", "hello world"); await Assert.That(line.Format()).IsEqualTo("PRIVMSG #channel :hello world"); } [Test] public async Task TrailingNoSpace() { var line = new Line("PRIVMSG", "#channel", "helloworld"); await Assert.That(line.Format()).IsEqualTo("PRIVMSG #channel helloworld"); } [Test] public async Task TrailingDoubleColon() { var line = new Line("PRIVMSG", "#channel", ":helloworld"); await Assert.That(line.Format()).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(); } }