about summary refs log tree commit diff
path: root/IrcTokens/Tests/TokenizationTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'IrcTokens/Tests/TokenizationTests.cs')
-rw-r--r--IrcTokens/Tests/TokenizationTests.cs118
1 files changed, 118 insertions, 0 deletions
diff --git a/IrcTokens/Tests/TokenizationTests.cs b/IrcTokens/Tests/TokenizationTests.cs
new file mode 100644
index 0000000..6d8a69d
--- /dev/null
+++ b/IrcTokens/Tests/TokenizationTests.cs
@@ -0,0 +1,118 @@
+using System.Collections.Generic;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace IrcTokens.Tests
+{
+    [TestClass]
+    public class TokenizationTests
+    {
+        [TestMethod]
+        public void TestTagsMissing()
+        {
+            var line = new Line("PRIVMSG #channel");
+            Assert.IsNull(line.Tags);
+        }
+
+        [TestMethod]
+        public void TestTagsMissingValue()
+        {
+            var line = new Line("@id= PRIVMSG #channel");
+            Assert.AreEqual(string.Empty, line.Tags["id"]);
+        }
+
+        [TestMethod]
+        public void TestTagsMissingEqual()
+        {
+            var line = new Line("@id PRIVMSG #channel");
+            Assert.AreEqual(string.Empty, line.Tags["id"]);
+        }
+
+        [TestMethod]
+        public void TestTagsUnescape()
+        {
+            var line = new Line(@"@id=1\\\:\r\n\s2 PRIVMSG #channel");
+            Assert.AreEqual("1\\;\r\n 2", line.Tags["id"]);
+        }
+
+        [TestMethod]
+        public void TestTagsOverlap()
+        {
+            var line = new Line(@"@id=1\\\s\\s PRIVMSG #channel");
+            Assert.AreEqual("1\\ \\s", line.Tags["id"]);
+        }
+
+        [TestMethod]
+        public void TestTagsLoneEndSlash()
+        {
+            var line = new Line("@id=1\\ PRIVMSG #channel");
+            Assert.AreEqual("1", line.Tags["id"]);
+        }
+
+        [TestMethod]
+        public void TestSourceWithoutTags()
+        {
+            var line = new Line(":nick!user@host PRIVMSG #channel");
+            Assert.AreEqual("nick!user@host", line.Source);
+        }
+
+        [TestMethod]
+        public void TestSourceWithTags()
+        {
+            var line = new Line("@id=123 :nick!user@host PRIVMSG #channel");
+            Assert.AreEqual("nick!user@host", line.Source);
+        }
+
+        [TestMethod]
+        public void TestSourceMissingWithoutTags()
+        {
+            var line = new Line("PRIVMSG #channel");
+            Assert.IsNull(line.Source);
+        }
+
+        [TestMethod]
+        public void TestSourceMissingWithTags()
+        {
+            var line = new Line("@id=123 PRIVMSG #channel");
+            Assert.IsNull(line.Source);
+        }
+
+        [TestMethod]
+        public void TestCommand()
+        {
+            var line = new Line("privmsg #channel");
+            Assert.AreEqual("PRIVMSG", line.Command);
+        }
+
+        [TestMethod]
+        public void TestParamsTrailing()
+        {
+            var line = new Line("PRIVMSG #channel :hello world");
+            CollectionAssert.AreEqual(new List<string> {"#channel", "hello world"}, line.Params);
+        }
+
+        [TestMethod]
+        public void TestParamsOnlyTrailing()
+        {
+            var line = new Line("PRIVMSG :hello world");
+            CollectionAssert.AreEqual(new List<string> {"hello world"}, line.Params);
+        }
+
+        [TestMethod]
+        public void TestParamsMissing()
+        {
+            var line = new Line("PRIVMSG");
+            Assert.AreEqual("PRIVMSG", line.Command);
+            CollectionAssert.AreEqual(new List<string>(), line.Params);
+        }
+
+        [TestMethod]
+        public void TestAllTokens()
+        {
+            var line = new Line("@id=123 :nick!user@host PRIVMSG #channel :hello world");
+            CollectionAssert.AreEqual(new Dictionary<string, string> {{"id", "123"}}, line.Tags);
+            Assert.AreEqual("nick!user@host", line.Source);
+            Assert.AreEqual("PRIVMSG", line.Command);
+            CollectionAssert.AreEqual(new List<string> {"#channel", "hello world"}, line.Params);
+        }
+    }
+}