diff options
author | Ben Harris <ben@tilde.team> | 2020-11-10 18:35:21 -0500 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2020-11-10 18:35:21 -0500 |
commit | 35bbd30c2506b3d0b18397ef1443fb18c0d893d6 (patch) | |
tree | 893862078b9045fbfb73296a0290d16f245b2c2c /IRCSharp.Tests/Tokenization/Format.cs | |
parent | b8e2634193eef0b7a4db417144fe7f38a5140c3b (diff) |
Move tests to a separate project
Diffstat (limited to 'IRCSharp.Tests/Tokenization/Format.cs')
-rw-r--r-- | IRCSharp.Tests/Tokenization/Format.cs | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/IRCSharp.Tests/Tokenization/Format.cs b/IRCSharp.Tests/Tokenization/Format.cs new file mode 100644 index 0000000..7224f97 --- /dev/null +++ b/IRCSharp.Tests/Tokenization/Format.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace IRCTokens.Tests +{ + [TestClass] + public class Format + { + [TestMethod] + public void Tags() + { + var line = new Line("PRIVMSG", "#channel", "hello") + { + Tags = new Dictionary<string, string> {{"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<string, string> {{"a", null}}} + .Format(); + + Assert.AreEqual("@a PRIVMSG #channel hello", line); + } + + [TestMethod] + public void EmptyTag() + { + var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new Dictionary<string, string> {{"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<ArgumentException>(() => { new Line("USER", "user", "0 *", "real name").Format(); }); + } + + [TestMethod] + public void InvalidNonLastColon() + { + Assert.ThrowsException<ArgumentException>(() => { new Line("PRIVMSG", ":#channel", "hello").Format(); }); + } + } +} |