2020-04-28 04:35:52 +00:00
|
|
|
|
using System;
|
2020-04-20 00:52:41 +00:00
|
|
|
|
using System.Collections.Generic;
|
2022-03-25 19:11:48 +00:00
|
|
|
|
using IRCTokens;
|
2020-04-28 04:35:52 +00:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2020-04-20 00:52:41 +00:00
|
|
|
|
|
2022-03-25 19:11:48 +00:00
|
|
|
|
namespace IRCSharp.Tests.Tokenization
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
2020-04-22 20:28:51 +00:00
|
|
|
|
public class Format
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void Tags()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void MissingTag()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void NullTag()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void EmptyTag()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void Source()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void CommandLowercase()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void CommandUppercase()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void TrailingSpace()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void TrailingNoSpace()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void TrailingDoubleColon()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void InvalidNonLastSpace()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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]
|
2020-05-17 02:08:40 +00:00
|
|
|
|
public void InvalidNonLastColon()
|
2020-04-20 00:52:41 +00:00
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|