119 lines
3.5 KiB
C#
119 lines
3.5 KiB
C#
using System.Collections.Generic;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|