ircsharp/IRCTokens/Tests/Format.cs

106 lines
3.0 KiB
C#
Raw Normal View History

2020-04-28 04:35:52 +00:00
using System;
2020-04-20 00:52:41 +00:00
using System.Collections.Generic;
2020-04-28 04:35:52 +00:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
2020-04-20 00:52:41 +00:00
2020-05-15 03:06:10 +00:00
namespace IRCTokens.Tests
2020-04-20 00:52:41 +00:00
{
[TestClass]
public class Format
2020-04-20 00:52:41 +00:00
{
[TestMethod]
public void TestTags()
{
2020-05-06 14:39:59 +00:00
var line = new Line("PRIVMSG", "#channel", "hello")
2020-04-20 00:52:41 +00:00
{
2020-05-06 14:39:59 +00:00
Tags = new Dictionary<string, string> {{"id", "\\" + " " + ";" + "\r\n"}}
2020-04-20 00:52:41 +00:00
}.Format();
Assert.AreEqual("@id=\\\\\\s\\:\\r\\n PRIVMSG #channel hello", line);
}
[TestMethod]
public void TestMissingTag()
{
2020-05-06 14:39:59 +00:00
var line = new Line("PRIVMSG", "#channel", "hello").Format();
2020-04-20 00:52:41 +00:00
Assert.AreEqual("PRIVMSG #channel hello", line);
}
[TestMethod]
public void TestNullTag()
{
2020-05-06 14:39:59 +00:00
var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new Dictionary<string, string> {{"a", null}}}
.Format();
2020-04-20 00:52:41 +00:00
Assert.AreEqual("@a PRIVMSG #channel hello", line);
}
[TestMethod]
public void TestEmptyTag()
{
2020-05-06 14:39:59 +00:00
var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new Dictionary<string, string> {{"a", ""}}}
.Format();
2020-04-20 00:52:41 +00:00
Assert.AreEqual("@a PRIVMSG #channel hello", line);
}
[TestMethod]
public void TestSource()
{
2020-05-06 14:39:59 +00:00
var line = new Line("PRIVMSG", "#channel", "hello") {Source = "nick!user@host"}.Format();
2020-04-20 00:52:41 +00:00
Assert.AreEqual(":nick!user@host PRIVMSG #channel hello", line);
}
[TestMethod]
public void TestCommandLowercase()
{
2020-04-28 04:35:52 +00:00
var line = new Line {Command = "privmsg"}.Format();
2020-04-20 00:52:41 +00:00
Assert.AreEqual("privmsg", line);
}
[TestMethod]
public void TestCommandUppercase()
{
2020-04-28 04:35:52 +00:00
var line = new Line {Command = "PRIVMSG"}.Format();
2020-04-20 00:52:41 +00:00
Assert.AreEqual("PRIVMSG", line);
}
[TestMethod]
public void TestTrailingSpace()
{
2020-05-06 14:39:59 +00:00
var line = new Line("PRIVMSG", "#channel", "hello world").Format();
2020-04-20 00:52:41 +00:00
Assert.AreEqual("PRIVMSG #channel :hello world", line);
}
[TestMethod]
public void TestTrailingNoSpace()
{
2020-05-06 14:39:59 +00:00
var line = new Line("PRIVMSG", "#channel", "helloworld").Format();
2020-04-20 00:52:41 +00:00
Assert.AreEqual("PRIVMSG #channel helloworld", line);
}
[TestMethod]
public void TestTrailingDoubleColon()
{
2020-05-06 14:39:59 +00:00
var line = new Line("PRIVMSG", "#channel", ":helloworld").Format();
2020-04-20 00:52:41 +00:00
Assert.AreEqual("PRIVMSG #channel ::helloworld", line);
}
[TestMethod]
public void TestInvalidNonLastSpace()
{
2020-05-06 14:39:59 +00:00
Assert.ThrowsException<ArgumentException>(() => { new Line("USER", "user", "0 *", "real name").Format(); });
2020-04-20 00:52:41 +00:00
}
[TestMethod]
public void TestInvalidNonLastColon()
{
2020-05-06 14:39:59 +00:00
Assert.ThrowsException<ArgumentException>(() => { new Line("PRIVMSG", ":#channel", "hello").Format(); });
2020-04-20 00:52:41 +00:00
}
}
}