about summary refs log tree commit diff
path: root/IrcTokens/Tests/StatefulEncoder.cs
blob: e3ed70d0847d1ccb2629eb863f96224a0030250e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Text;

namespace IrcTokens.Tests
{
    [TestClass]
    public class StatefulEncoder
    {
        private IrcTokens.StatefulEncoder _encoder;

        [TestInitialize]
        public void TestInitialize()
        {
            _encoder = new IrcTokens.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 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);
        }
    }
}