using System; using System.Collections.Generic; using IRCTokens; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace IRCSharp.Tests.Tokenization { [TestClass] public class Format { [TestMethod] public void Tags() { var line = new Line("PRIVMSG", "#channel", "hello") { Tags = new Dictionary {{"id", "\\" + " " + ";" + "\r\n"}} }.Format(); Assert.AreEqual("@id=\\\\\\s\\:\\r\\n PRIVMSG #channel hello", line); } [TestMethod] public void MissingTag() { var line = new Line("PRIVMSG", "#channel", "hello").Format(); Assert.AreEqual("PRIVMSG #channel hello", line); } [TestMethod] public void NullTag() { var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new Dictionary {{"a", null}}} .Format(); Assert.AreEqual("@a PRIVMSG #channel hello", line); } [TestMethod] public void EmptyTag() { var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new Dictionary {{"a", ""}}} .Format(); Assert.AreEqual("@a PRIVMSG #channel hello", line); } [TestMethod] public void Source() { var line = new Line("PRIVMSG", "#channel", "hello") {Source = "nick!user@host"}.Format(); Assert.AreEqual(":nick!user@host PRIVMSG #channel hello", line); } [TestMethod] public void CommandLowercase() { var line = new Line {Command = "privmsg"}.Format(); Assert.AreEqual("privmsg", line); } [TestMethod] public void CommandUppercase() { var line = new Line {Command = "PRIVMSG"}.Format(); Assert.AreEqual("PRIVMSG", line); } [TestMethod] public void TrailingSpace() { var line = new Line("PRIVMSG", "#channel", "hello world").Format(); Assert.AreEqual("PRIVMSG #channel :hello world", line); } [TestMethod] public void TrailingNoSpace() { var line = new Line("PRIVMSG", "#channel", "helloworld").Format(); Assert.AreEqual("PRIVMSG #channel helloworld", line); } [TestMethod] public void TrailingDoubleColon() { var line = new Line("PRIVMSG", "#channel", ":helloworld").Format(); Assert.AreEqual("PRIVMSG #channel ::helloworld", line); } [TestMethod] public void InvalidNonLastSpace() { Assert.ThrowsException(() => { new Line("USER", "user", "0 *", "real name").Format(); }); } [TestMethod] public void InvalidNonLastColon() { Assert.ThrowsException(() => { new Line("PRIVMSG", ":#channel", "hello").Format(); }); } } }