about summary refs log tree commit diff
path: root/IrcTokens/Tests/Format.cs
blob: 8ef53446bd27d3151d2af4ac04c6431befc1b654 (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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace IrcTokens.Tests
{
    [TestClass]
    public class Format
    {
        [TestMethod]
        public void TestTags()
        {
            var line = new Line
            {
                Command = "PRIVMSG",
                Params  = new List<string> {"#channel", "hello"},
                Tags    = new Dictionary<string, string> {{"id", "\\" + " " + ";" + "\r\n"}}
            }.Format();

            Assert.AreEqual("@id=\\\\\\s\\:\\r\\n PRIVMSG #channel hello", line);
        }

        [TestMethod]
        public void TestMissingTag()
        {
            var line = new Line {Command = "PRIVMSG", Params = new List<string> {"#channel", "hello"}}.Format();

            Assert.AreEqual("PRIVMSG #channel hello", line);
        }

        [TestMethod]
        public void TestNullTag()
        {
            var line = new Line
            {
                Command = "PRIVMSG",
                Params  = new List<string> {"#channel", "hello"},
                Tags    = new Dictionary<string, string> {{"a", null}}
            }.Format();

            Assert.AreEqual("@a PRIVMSG #channel hello", line);
        }

        [TestMethod]
        public void TestEmptyTag()
        {
            var line = new Line
            {
                Command = "PRIVMSG",
                Params  = new List<string> {"#channel", "hello"},
                Tags    = new Dictionary<string, string> {{"a", ""}}
            }.Format();

            Assert.AreEqual("@a PRIVMSG #channel hello", line);
        }

        [TestMethod]
        public void TestSource()
        {
            var line = new Line
            {
                Command = "PRIVMSG", Params = new List<string> {"#channel", "hello"}, Source = "nick!user@host"
            }.Format();

            Assert.AreEqual(":nick!user@host PRIVMSG #channel hello", line);
        }

        [TestMethod]
        public void TestCommandLowercase()
        {
            var line = new Line {Command = "privmsg"}.Format();
            Assert.AreEqual("privmsg", line);
        }

        [TestMethod]
        public void TestCommandUppercase()
        {
            var line = new Line {Command = "PRIVMSG"}.Format();
            Assert.AreEqual("PRIVMSG", line);
        }

        [TestMethod]
        public void TestTrailingSpace()
        {
            var line = new Line {Command = "PRIVMSG", Params = new List<string> {"#channel", "hello world"}}.Format();

            Assert.AreEqual("PRIVMSG #channel :hello world", line);
        }

        [TestMethod]
        public void TestTrailingNoSpace()
        {
            var line = new Line {Command = "PRIVMSG", Params = new List<string> {"#channel", "helloworld"}}.Format();

            Assert.AreEqual("PRIVMSG #channel helloworld", line);
        }

        [TestMethod]
        public void TestTrailingDoubleColon()
        {
            var line = new Line {Command = "PRIVMSG", Params = new List<string> {"#channel", ":helloworld"}}.Format();

            Assert.AreEqual("PRIVMSG #channel ::helloworld", line);
        }

        [TestMethod]
        public void TestInvalidNonLastSpace()
        {
            Assert.ThrowsException<ArgumentException>(() =>
            {
                new Line {Command = "USER", Params = new List<string> {"user", "0 *", "real name"}}.Format();
            });
        }

        [TestMethod]
        public void TestInvalidNonLastColon()
        {
            Assert.ThrowsException<ArgumentException>(() =>
            {
                new Line {Command = "PRIVMSG", Params = new List<string> {":#channel", "hello"}}.Format();
            });
        }
    }
}