about summary refs log tree commit diff
path: root/IrcTokens/Tests/StatefulEncoderTests.cs
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2020-04-20 17:24:59 -0400
committerBen Harris <ben@tilde.team>2020-04-20 17:24:59 -0400
commit6a3bfd314d87bed96611d24440b0961a06bf7e91 (patch)
tree5652d9ab48d850b7c9bd905b49b6d2709ae849c8 /IrcTokens/Tests/StatefulEncoderTests.cs
parent616abc70303990fbf8096fc6ada5fac100a6c66a (diff)
stateful in progress
Diffstat (limited to 'IrcTokens/Tests/StatefulEncoderTests.cs')
-rw-r--r--IrcTokens/Tests/StatefulEncoderTests.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/IrcTokens/Tests/StatefulEncoderTests.cs b/IrcTokens/Tests/StatefulEncoderTests.cs
new file mode 100644
index 0000000..4732573
--- /dev/null
+++ b/IrcTokens/Tests/StatefulEncoderTests.cs
@@ -0,0 +1,72 @@
+using System.Linq;
+using System.Text;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace IrcTokens.Tests
+{
+    [TestClass]
+    public class StatefulEncoderTests
+    {
+        private StatefulEncoder _encoder;
+
+        [TestInitialize]
+        public void TestInitialize()
+        {
+            _encoder = new StatefulEncoder();
+        }
+
+        [TestMethod]
+        public void TestPush()
+        {
+            var line = new Line("PRIVMSG #channel hello");
+            _encoder.Push(line);
+            Assert.AreEqual("PRIVMSG #channel hello\r\n", _encoder.Pending);
+        }
+
+        [TestMethod]
+        public void TestPopPartial()
+        {
+            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 TestPopNoneReturned()
+        {
+            var line = new Line("PRIVMSG #channel hello");
+            _encoder.Push(line);
+            var lines = _encoder.Pop(1);
+            Assert.AreEqual(0, lines.Count);
+        }
+
+        [TestMethod]
+        public void TestClear()
+        {
+            _encoder.Push(new Line("PRIVMSG #channel hello"));
+            _encoder.Clear();
+            Assert.AreEqual(string.Empty, _encoder.Pending);
+        }
+
+        [TestMethod]
+        public void TestEncoding()
+        {
+            var iso88592 = Encoding.GetEncodings().Single(ei => ei.Name == "iso-8859-2");
+            _encoder = new StatefulEncoder {Encoding = iso88592};
+            _encoder.Push(new Line("PRIVMSG #channel :hello Č"));
+            Assert.AreEqual("PRIVMSG #channel :hello Č\r\n", _encoder.Pending);
+        }
+    }
+}