ircsharp/IRCSharp.Tests/Tokenization/StatefulEncoder.cs

80 lines
2.1 KiB
C#
Raw Normal View History

2024-03-26 20:10:54 +00:00
namespace IRCSharp.Tests.Tokenization;
2020-04-20 21:24:59 +00:00
2024-03-26 20:10:54 +00:00
[TestClass]
public class StatefulEncoder
2020-04-20 21:24:59 +00:00
{
2024-03-26 20:10:54 +00:00
private IRCTokens.StatefulEncoder _encoder;
2020-04-20 21:24:59 +00:00
2024-03-26 20:10:54 +00:00
[TestInitialize]
public void Initialize()
{
_encoder = new();
}
2020-04-20 21:24:59 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void Push()
{
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
2024-03-26 20:10:54 +00:00
[TestMethod]
public void PopPartial()
{
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
2024-03-26 20:10:54 +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]);
}
2020-04-20 21:24:59 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void PopNoneReturned()
{
var line = new Line("PRIVMSG #channel hello");
_encoder.Push(line);
var lines = _encoder.Pop(1);
Assert.AreEqual(0, lines.Count);
}
2020-04-20 21:24:59 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void PopMultipleLines()
{
var line1 = new Line("PRIVMSG #channel1 hello");
_encoder.Push(line1);
var line2 = new Line("PRIVMSG #channel2 hello");
_encoder.Push(line2);
2020-04-28 04:35:52 +00:00
2024-03-26 20:10:54 +00:00
var lines = _encoder.Pop(_encoder.Pending().Length);
Assert.AreEqual(2, lines.Count);
Assert.AreEqual(string.Empty, _encoder.Pending());
}
2020-04-28 04:35:52 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void Clear()
{
_encoder.Push(new("PRIVMSG #channel hello"));
_encoder.Clear();
Assert.AreEqual(string.Empty, _encoder.Pending());
}
2020-04-20 21:24:59 +00:00
2024-03-26 20:10:54 +00:00
[TestMethod]
public void EncodingIso8859()
{
var iso8859 = Encoding.GetEncoding("iso-8859-1");
_encoder = new() {Encoding = iso8859};
_encoder.Push(new("PRIVMSG #channel :hello Ç"));
CollectionAssert.AreEqual(iso8859.GetBytes("PRIVMSG #channel :hello Ç\r\n"), _encoder.PendingBytes);
2020-04-20 21:24:59 +00:00
}
2024-03-26 20:10:54 +00:00
}