From 933a4f85604e21445c9bac8272d64cf3e6f65e00 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 22 Apr 2020 16:28:51 -0400 Subject: rename to IrcSharp also tidy up formatting with vs tools --- IrcTokens/Tests/Format.cs | 150 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 IrcTokens/Tests/Format.cs (limited to 'IrcTokens/Tests/Format.cs') diff --git a/IrcTokens/Tests/Format.cs b/IrcTokens/Tests/Format.cs new file mode 100644 index 0000000..64f974a --- /dev/null +++ b/IrcTokens/Tests/Format.cs @@ -0,0 +1,150 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; + +namespace IrcTokens.Tests +{ + [TestClass] + public class Format + { + [TestMethod] + public void TestTags() + { + var line = new Line + { + Command = "PRIVMSG", + Params = new List { "#channel", "hello" }, + Tags = new Dictionary { { "id", "\\" + " " + ";" + "\r\n" } } + }.Format(); + + Assert.AreEqual("@id=\\\\\\s\\:\\r\\n PRIVMSG #channel hello", line); + } + + [TestMethod] + public void TestMissingTag() + { + var line = new Line + { + Command = "PRIVMSG", + Params = new List { "#channel", "hello" } + }.Format(); + + Assert.AreEqual("PRIVMSG #channel hello", line); + } + + [TestMethod] + public void TestNullTag() + { + var line = new Line + { + Command = "PRIVMSG", + Params = new List { "#channel", "hello" }, + Tags = new Dictionary { { "a", null } } + }.Format(); + + Assert.AreEqual("@a PRIVMSG #channel hello", line); + } + + [TestMethod] + public void TestEmptyTag() + { + var line = new Line + { + Command = "PRIVMSG", + Params = new List { "#channel", "hello" }, + Tags = new Dictionary { { "a", "" } } + }.Format(); + + Assert.AreEqual("@a PRIVMSG #channel hello", line); + } + + [TestMethod] + public void TestSource() + { + var line = new Line + { + Command = "PRIVMSG", + Params = new List { "#channel", "hello" }, + Source = "nick!user@host" + }.Format(); + + Assert.AreEqual(":nick!user@host PRIVMSG #channel hello", line); + } + + [TestMethod] + public void TestCommandLowercase() + { + var line = new Line { Command = "privmsg" }.Format(); + Assert.AreEqual("privmsg", line); + } + + [TestMethod] + public void TestCommandUppercase() + { + var line = new Line { Command = "PRIVMSG" }.Format(); + Assert.AreEqual("PRIVMSG", line); + } + + [TestMethod] + public void TestTrailingSpace() + { + var line = new Line + { + Command = "PRIVMSG", + Params = new List { "#channel", "hello world" } + }.Format(); + + Assert.AreEqual("PRIVMSG #channel :hello world", line); + } + + [TestMethod] + public void TestTrailingNoSpace() + { + var line = new Line + { + Command = "PRIVMSG", + Params = new List { "#channel", "helloworld" } + }.Format(); + + Assert.AreEqual("PRIVMSG #channel helloworld", line); + } + + [TestMethod] + public void TestTrailingDoubleColon() + { + var line = new Line + { + Command = "PRIVMSG", + Params = new List { "#channel", ":helloworld" } + }.Format(); + + Assert.AreEqual("PRIVMSG #channel ::helloworld", line); + } + + [TestMethod] + public void TestInvalidNonLastSpace() + { + Assert.ThrowsException(() => + { + new Line + { + Command = "USER", + Params = new List { "user", "0 *", "real name" } + }.Format(); + }); + } + + [TestMethod] + public void TestInvalidNonLastColon() + { + Assert.ThrowsException(() => + { + new Line + { + Command = "PRIVMSG", + Params = new List { ":#channel", "hello" } + }.Format(); + }); + } + } +} -- cgit 1.4.1