about summary refs log tree commit diff
path: root/IrcTokens/Tests/Tokenization.cs
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2020-04-22 16:28:51 -0400
committerBen Harris <ben@tilde.team>2020-04-22 16:28:51 -0400
commit933a4f85604e21445c9bac8272d64cf3e6f65e00 (patch)
tree5b300ca37beff5cf11ed67a8b6e3550d24cf18a3 /IrcTokens/Tests/Tokenization.cs
parent338763fde71ba2dc0de8ea5e2437d24ee365874b (diff)
rename to IrcSharp
also tidy up formatting with vs tools
Diffstat (limited to 'IrcTokens/Tests/Tokenization.cs')
-rw-r--r--IrcTokens/Tests/Tokenization.cs118
1 files changed, 118 insertions, 0 deletions
diff --git a/IrcTokens/Tests/Tokenization.cs b/IrcTokens/Tests/Tokenization.cs
new file mode 100644
index 0000000..c4970ed
--- /dev/null
+++ b/IrcTokens/Tests/Tokenization.cs
@@ -0,0 +1,118 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Collections.Generic;
+
+namespace IrcTokens.Tests
+{
+    [TestClass]
+    public class Tokenization
+    {
+        [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);
+        }
+    }
+}