namespace IRCSharp.Tests.Tokenization; public class StatefulEncoder { private readonly IRCTokens.StatefulEncoder _encoder = new(); [Test] public async Task Push() { var line = new Line("PRIVMSG #channel hello"); _encoder.Push(line); await Assert.That(_encoder.Pending()).IsEqualTo("PRIVMSG #channel hello\r\n"); } [Test] public async Task PopPartial() { var line = new Line("PRIVMSG #channel hello"); _encoder.Push(line); _encoder.Pop("PRIVMSG #channel hello".Length); await Assert.That(_encoder.Pending()).IsEqualTo("\r\n"); } [Test] public async Task TestPopReturned() { var line = new Line("PRIVMSG #channel hello"); _encoder.Push(line); _encoder.Push(line); var lines = _encoder.Pop("PRIVMSG #channel hello\r\n".Length); await Assert.That(lines).HasCount(1); await Assert.That(lines[0]).IsEqualTo(line); } [Test] public async Task PopNoneReturned() { var line = new Line("PRIVMSG #channel hello"); _encoder.Push(line); var lines = _encoder.Pop(1); await Assert.That(lines).IsEmpty(); } [Test] public async Task PopMultipleLines() { 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); await Assert.That(lines).HasCount(2); await Assert.That(_encoder.Pending()).IsEmpty(); } [Test] public async Task Clear() { _encoder.Push(new Line("PRIVMSG #channel hello")); _encoder.Clear(); await Assert.That(_encoder.Pending()).IsEmpty(); } [Test] public async Task EncodingIso8859() { var encoder = new IRCTokens.StatefulEncoder {Encoding = Encoding.Latin1}; encoder.Push(new Line("PRIVMSG #channel :hello Ç")); await Assert.That(encoder.PendingBytes).IsEquivalentTo(Encoding.Latin1.GetBytes("PRIVMSG #channel :hello Ç\r\n")); } }