ircsharp/IRCSharp.Tests/Tokenization/Format.cs

100 lines
2.5 KiB
C#
Raw Normal View History

2024-03-26 20:10:54 +00:00
namespace IRCSharp.Tests.Tokenization;
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestClass]
public class Format
2020-04-20 00:52:41 +00:00
{
2024-03-26 20:10:54 +00:00
[TestMethod]
public void Tags()
2020-04-20 00:52:41 +00:00
{
2024-03-26 20:10:54 +00:00
var line = new Line("PRIVMSG", "#channel", "hello")
2020-04-20 00:52:41 +00:00
{
2024-03-26 20:10:54 +00:00
Tags = new() {{"id", "\\" + " " + ";" + "\r\n"}}
}.Format();
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
Assert.AreEqual(@"@id=\\\s\:\r\n PRIVMSG #channel hello", line);
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void MissingTag()
{
var line = new Line("PRIVMSG", "#channel", "hello").Format();
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
Assert.AreEqual("PRIVMSG #channel hello", line);
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void NullTag()
{
var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new() {{"a", null}}}
.Format();
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
Assert.AreEqual("@a PRIVMSG #channel hello", line);
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void EmptyTag()
{
var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new() {{"a", ""}}}
.Format();
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
Assert.AreEqual("@a PRIVMSG #channel hello", line);
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void Source()
{
var line = new Line("PRIVMSG", "#channel", "hello") {Source = "nick!user@host"}.Format();
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
Assert.AreEqual(":nick!user@host PRIVMSG #channel hello", line);
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void CommandLowercase()
{
var line = new Line {Command = "privmsg"}.Format();
Assert.AreEqual("privmsg", line);
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void CommandUppercase()
{
var line = new Line {Command = "PRIVMSG"}.Format();
Assert.AreEqual("PRIVMSG", line);
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void TrailingSpace()
{
var line = new Line("PRIVMSG", "#channel", "hello world").Format();
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
Assert.AreEqual("PRIVMSG #channel :hello world", line);
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void TrailingNoSpace()
{
var line = new Line("PRIVMSG", "#channel", "helloworld").Format();
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
Assert.AreEqual("PRIVMSG #channel helloworld", line);
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void TrailingDoubleColon()
{
var line = new Line("PRIVMSG", "#channel", ":helloworld").Format();
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
Assert.AreEqual("PRIVMSG #channel ::helloworld", line);
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void InvalidNonLastSpace()
{
Assert.ThrowsException<ArgumentException>(() => { new Line("USER", "user", "0 *", "real name").Format(); });
}
2020-04-20 00:52:41 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void InvalidNonLastColon()
{
Assert.ThrowsException<ArgumentException>(() => { new Line("PRIVMSG", ":#channel", "hello").Format(); });
2020-04-20 00:52:41 +00:00
}
2024-03-26 20:10:54 +00:00
}