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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IrcTokens.Tests
{
[TestClass]
public class StatefulDecoderTests
{
private StatefulDecoder _decoder;
[TestInitialize]
public void TestInitialize()
{
_decoder = new StatefulDecoder();
}
[TestMethod]
public void TestPartial()
{
var lines = _decoder.Push("PRIVMSG ");
Assert.AreEqual(new List<string>(), lines);
lines = _decoder.Push("#channel hello\r\n");
Assert.AreEqual(1, lines.Count);
var line = new Line("PRIVMSG #channel hello");
CollectionAssert.AreEqual(new List<Line> {line}, lines);
}
[TestMethod]
public void TestMultiple()
{
_decoder.Push("PRIVMSG #channel1 hello\r\n");
var lines = _decoder.Push("PRIVMSG #channel2 hello\r\n");
Assert.AreEqual(2, lines.Count);
var line1 = new Line("PRIVMSG #channel1 hello");
var line2 = new Line("PRIVMSG #channel2 hello");
Assert.AreEqual(line1, lines[0]);
Assert.AreEqual(line2, lines[1]);
}
[TestMethod]
public void TestEncoding()
{
var iso8859 = Encoding.GetEncodings().Single(ei => ei.Name == "iso-8859-1");
_decoder = new StatefulDecoder {Encoding = iso8859};
var lines = _decoder.Push("PRIVMSG #channel :hello Č\r\n");
var line = new Line("PRIVMSG #channel :hello Č");
Assert.AreEqual(line, lines[0]);
}
[TestMethod]
public void TestEncodingFallback()
{
var latin1 = Encoding.GetEncodings().Single(ei => ei.Name == "latin-1");
_decoder = new StatefulDecoder {Fallback = latin1};
var lines = _decoder.Push("PRIVMSG #channel hélló\r\n");
Assert.AreEqual(1, lines.Count);
Assert.AreEqual(new Line("PRIVMSG #channel hélló"), lines[0]);
}
[TestMethod]
public void TestEmpty()
{
var lines = _decoder.Push(string.Empty);
Assert.IsNull(lines);
}
[TestMethod]
public void TestBufferUnfinished()
{
_decoder.Push("PRIVMSG #channel hello");
var lines = _decoder.Push(string.Empty);
Assert.IsNull(lines);
}
[TestMethod]
public void TestClear()
{
_decoder.Push("PRIVMSG ");
_decoder.Clear();
Assert.AreEqual(string.Empty, _decoder.Pending);
}
[TestMethod]
public void TestTagEncodingMismatch()
{
_decoder.Push("@asd=á ");
var lines = _decoder.Push("PRIVMSG #chan :á\r\n");
Assert.AreEqual("á", lines[0].Params[0]);
Assert.AreEqual("á", lines[0].Tags["asd"]);
}
}
}
|