diff options
author | Ben Harris <ben@tilde.team> | 2020-11-10 18:35:21 -0500 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2020-11-10 18:35:21 -0500 |
commit | 35bbd30c2506b3d0b18397ef1443fb18c0d893d6 (patch) | |
tree | 893862078b9045fbfb73296a0290d16f245b2c2c /IRCSharp.Tests/Tokenization/StatefulEncoder.cs | |
parent | b8e2634193eef0b7a4db417144fe7f38a5140c3b (diff) |
Move tests to a separate project
Diffstat (limited to 'IRCSharp.Tests/Tokenization/StatefulEncoder.cs')
-rw-r--r-- | IRCSharp.Tests/Tokenization/StatefulEncoder.cs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/IRCSharp.Tests/Tokenization/StatefulEncoder.cs b/IRCSharp.Tests/Tokenization/StatefulEncoder.cs new file mode 100644 index 0000000..d1e1e3e --- /dev/null +++ b/IRCSharp.Tests/Tokenization/StatefulEncoder.cs @@ -0,0 +1,84 @@ +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace IRCTokens.Tests +{ + [TestClass] + public class StatefulEncoder + { + private IRCTokens.StatefulEncoder _encoder; + + [TestInitialize] + public void Initialize() + { + _encoder = new IRCTokens.StatefulEncoder(); + } + + [TestMethod] + public void Push() + { + var line = new Line("PRIVMSG #channel hello"); + _encoder.Push(line); + Assert.AreEqual("PRIVMSG #channel hello\r\n", _encoder.Pending()); + } + + [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()); + } + + [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] + public void PopNoneReturned() + { + var line = new Line("PRIVMSG #channel hello"); + _encoder.Push(line); + var lines = _encoder.Pop(1); + Assert.AreEqual(0, lines.Count); + } + + [TestMethod] + public void 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); + Assert.AreEqual(2, lines.Count); + Assert.AreEqual(string.Empty, _encoder.Pending()); + } + + [TestMethod] + public void Clear() + { + _encoder.Push(new Line("PRIVMSG #channel hello")); + _encoder.Clear(); + Assert.AreEqual(string.Empty, _encoder.Pending()); + } + + [TestMethod] + public void EncodingIso8859() + { + var iso8859 = Encoding.GetEncoding("iso-8859-1"); + _encoder = new IRCTokens.StatefulEncoder {Encoding = iso8859}; + _encoder.Push(new Line("PRIVMSG #channel :hello Ç")); + CollectionAssert.AreEqual(iso8859.GetBytes("PRIVMSG #channel :hello Ç\r\n"), _encoder.PendingBytes); + } + } +} |