ircsharp/IRCSharp.Tests/Tokenization/StatefulEncoder.cs

85 lines
2.5 KiB
C#
Raw Normal View History

2020-04-28 04:35:52 +00:00
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
2020-04-20 21:24:59 +00:00
2020-05-15 03:06:10 +00:00
namespace IRCTokens.Tests
2020-04-20 21:24:59 +00:00
{
[TestClass]
public class StatefulEncoder
2020-04-20 21:24:59 +00:00
{
2020-05-15 03:06:10 +00:00
private IRCTokens.StatefulEncoder _encoder;
2020-04-20 21:24:59 +00:00
[TestInitialize]
2020-05-17 02:08:40 +00:00
public void Initialize()
2020-04-20 21:24:59 +00:00
{
2020-05-15 03:06:10 +00:00
_encoder = new IRCTokens.StatefulEncoder();
2020-04-20 21:24:59 +00:00
}
[TestMethod]
2020-05-17 02:08:40 +00:00
public void Push()
2020-04-20 21:24:59 +00:00
{
var line = new Line("PRIVMSG #channel hello");
_encoder.Push(line);
Assert.AreEqual("PRIVMSG #channel hello\r\n", _encoder.Pending());
2020-04-20 21:24:59 +00:00
}
[TestMethod]
2020-05-17 02:08:40 +00:00
public void PopPartial()
2020-04-20 21:24:59 +00:00
{
var line = new Line("PRIVMSG #channel hello");
_encoder.Push(line);
_encoder.Pop("PRIVMSG #channel hello".Length);
Assert.AreEqual("\r\n", _encoder.Pending());
2020-04-20 21:24:59 +00:00
}
[TestMethod]
public void TestPopReturned()
{
var line = new Line("PRIVMSG #channel hello");
_encoder.Push(line);
_encoder.Push(line);
var lines = _encoder.Pop("PRIVMSG #channel hello\r\n".Length);
Assert.AreEqual(1, lines.Count);
Assert.AreEqual(line, lines[0]);
}
[TestMethod]
2020-05-17 02:08:40 +00:00
public void PopNoneReturned()
2020-04-20 21:24:59 +00:00
{
var line = new Line("PRIVMSG #channel hello");
_encoder.Push(line);
var lines = _encoder.Pop(1);
Assert.AreEqual(0, lines.Count);
}
2020-04-28 04:35:52 +00:00
[TestMethod]
2020-05-17 02:08:40 +00:00
public void PopMultipleLines()
2020-04-28 04:35:52 +00:00
{
var line1 = new Line("PRIVMSG #channel1 hello");
_encoder.Push(line1);
var line2 = new Line("PRIVMSG #channel2 hello");
_encoder.Push(line2);
var lines = _encoder.Pop(_encoder.Pending().Length);
Assert.AreEqual(2, lines.Count);
Assert.AreEqual(string.Empty, _encoder.Pending());
}
2020-04-20 21:24:59 +00:00
[TestMethod]
2020-05-17 02:08:40 +00:00
public void Clear()
2020-04-20 21:24:59 +00:00
{
_encoder.Push(new Line("PRIVMSG #channel hello"));
_encoder.Clear();
Assert.AreEqual(string.Empty, _encoder.Pending());
2020-04-20 21:24:59 +00:00
}
[TestMethod]
2020-05-17 02:08:40 +00:00
public void EncodingIso8859()
2020-04-20 21:24:59 +00:00
{
var iso8859 = Encoding.GetEncoding("iso-8859-1");
2020-05-15 03:06:10 +00:00
_encoder = new IRCTokens.StatefulEncoder {Encoding = iso8859};
_encoder.Push(new Line("PRIVMSG #channel :hello Ç"));
CollectionAssert.AreEqual(iso8859.GetBytes("PRIVMSG #channel :hello Ç\r\n"), _encoder.PendingBytes);
2020-04-20 21:24:59 +00:00
}
}
}