about summary refs log tree commit diff
path: root/IrcTokens/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'IrcTokens/Tests')
-rw-r--r--IrcTokens/Tests/Format.cs60
-rw-r--r--IrcTokens/Tests/Hostmask.cs2
-rw-r--r--IrcTokens/Tests/Parser.cs16
-rw-r--r--IrcTokens/Tests/StatefulDecoder.cs12
-rw-r--r--IrcTokens/Tests/StatefulEncoder.cs19
-rw-r--r--IrcTokens/Tests/Tokenization.cs12
6 files changed, 53 insertions, 68 deletions
diff --git a/IrcTokens/Tests/Format.cs b/IrcTokens/Tests/Format.cs
index 64f974a..8ef5344 100644
--- a/IrcTokens/Tests/Format.cs
+++ b/IrcTokens/Tests/Format.cs
@@ -1,6 +1,6 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
+using System;
 using System.Collections.Generic;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 namespace IrcTokens.Tests
 {
@@ -13,8 +13,8 @@ namespace IrcTokens.Tests
             var line = new Line
             {
                 Command = "PRIVMSG",
-                Params = new List<string> { "#channel", "hello" },
-                Tags = new Dictionary<string, string> { { "id", "\\" + " " + ";" + "\r\n" } }
+                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);
@@ -23,11 +23,7 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestMissingTag()
         {
-            var line = new Line
-            {
-                Command = "PRIVMSG",
-                Params = new List<string> { "#channel", "hello" }
-            }.Format();
+            var line = new Line {Command = "PRIVMSG", Params = new List<string> {"#channel", "hello"}}.Format();
 
             Assert.AreEqual("PRIVMSG #channel hello", line);
         }
@@ -38,8 +34,8 @@ namespace IrcTokens.Tests
             var line = new Line
             {
                 Command = "PRIVMSG",
-                Params = new List<string> { "#channel", "hello" },
-                Tags = new Dictionary<string, string> { { "a", null } }
+                Params  = new List<string> {"#channel", "hello"},
+                Tags    = new Dictionary<string, string> {{"a", null}}
             }.Format();
 
             Assert.AreEqual("@a PRIVMSG #channel hello", line);
@@ -51,8 +47,8 @@ namespace IrcTokens.Tests
             var line = new Line
             {
                 Command = "PRIVMSG",
-                Params = new List<string> { "#channel", "hello" },
-                Tags = new Dictionary<string, string> { { "a", "" } }
+                Params  = new List<string> {"#channel", "hello"},
+                Tags    = new Dictionary<string, string> {{"a", ""}}
             }.Format();
 
             Assert.AreEqual("@a PRIVMSG #channel hello", line);
@@ -63,9 +59,7 @@ namespace IrcTokens.Tests
         {
             var line = new Line
             {
-                Command = "PRIVMSG",
-                Params = new List<string> { "#channel", "hello" },
-                Source = "nick!user@host"
+                Command = "PRIVMSG", Params = new List<string> {"#channel", "hello"}, Source = "nick!user@host"
             }.Format();
 
             Assert.AreEqual(":nick!user@host PRIVMSG #channel hello", line);
@@ -74,25 +68,21 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestCommandLowercase()
         {
-            var line = new Line { Command = "privmsg" }.Format();
+            var line = new Line {Command = "privmsg"}.Format();
             Assert.AreEqual("privmsg", line);
         }
 
         [TestMethod]
         public void TestCommandUppercase()
         {
-            var line = new Line { Command = "PRIVMSG" }.Format();
+            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();
+            var line = new Line {Command = "PRIVMSG", Params = new List<string> {"#channel", "hello world"}}.Format();
 
             Assert.AreEqual("PRIVMSG #channel :hello world", line);
         }
@@ -100,11 +90,7 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestTrailingNoSpace()
         {
-            var line = new Line
-            {
-                Command = "PRIVMSG",
-                Params = new List<string> { "#channel", "helloworld" }
-            }.Format();
+            var line = new Line {Command = "PRIVMSG", Params = new List<string> {"#channel", "helloworld"}}.Format();
 
             Assert.AreEqual("PRIVMSG #channel helloworld", line);
         }
@@ -112,11 +98,7 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestTrailingDoubleColon()
         {
-            var line = new Line
-            {
-                Command = "PRIVMSG",
-                Params = new List<string> { "#channel", ":helloworld" }
-            }.Format();
+            var line = new Line {Command = "PRIVMSG", Params = new List<string> {"#channel", ":helloworld"}}.Format();
 
             Assert.AreEqual("PRIVMSG #channel ::helloworld", line);
         }
@@ -126,11 +108,7 @@ namespace IrcTokens.Tests
         {
             Assert.ThrowsException<ArgumentException>(() =>
             {
-                new Line
-                {
-                    Command = "USER",
-                    Params = new List<string> { "user", "0 *", "real name" }
-                }.Format();
+                new Line {Command = "USER", Params = new List<string> {"user", "0 *", "real name"}}.Format();
             });
         }
 
@@ -139,11 +117,7 @@ namespace IrcTokens.Tests
         {
             Assert.ThrowsException<ArgumentException>(() =>
             {
-                new Line
-                {
-                    Command = "PRIVMSG",
-                    Params = new List<string> { ":#channel", "hello" }
-                }.Format();
+                new Line {Command = "PRIVMSG", Params = new List<string> {":#channel", "hello"}}.Format();
             });
         }
     }
diff --git a/IrcTokens/Tests/Hostmask.cs b/IrcTokens/Tests/Hostmask.cs
index 51bc182..6a5cf65 100644
--- a/IrcTokens/Tests/Hostmask.cs
+++ b/IrcTokens/Tests/Hostmask.cs
@@ -44,7 +44,7 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestHostmaskFromLine()
         {
-            var line = new Line(":nick!user@host PRIVMSG #channel hello");
+            var line     = new Line(":nick!user@host PRIVMSG #channel hello");
             var hostmask = new IrcTokens.Hostmask("nick!user@host");
             Assert.AreEqual(hostmask.ToString(), line.Hostmask.ToString());
             Assert.AreEqual("nick", line.Hostmask.NickName);
diff --git a/IrcTokens/Tests/Parser.cs b/IrcTokens/Tests/Parser.cs
index df70b92..ed4e406 100644
--- a/IrcTokens/Tests/Parser.cs
+++ b/IrcTokens/Tests/Parser.cs
@@ -1,8 +1,8 @@
-using IrcTokens.Tests.Data;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using System.Globalization;
 using System.IO;
+using IrcTokens.Tests.Data;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
 using YamlDotNet.Serialization;
 using YamlDotNet.Serialization.NamingConventions;
 
@@ -26,13 +26,14 @@ namespace IrcTokens.Tests
             foreach (var test in LoadYaml<SplitModel>("Tests/Data/msg-split.yaml").Tests)
             {
                 var tokens = new Line(test.Input);
-                var atoms = test.Atoms;
+                var atoms  = test.Atoms;
 
                 Assert.AreEqual(atoms.Verb.ToUpper(CultureInfo.InvariantCulture), tokens.Command,
                     $"command failed on: '{test.Input}'");
                 Assert.AreEqual(atoms.Source, tokens.Source, $"source failed on: '{test.Input}'");
                 CollectionAssert.AreEqual(atoms.Tags, tokens.Tags, $"tags failed on: '{test.Input}'");
-                CollectionAssert.AreEqual(atoms.Params ?? new List<string>(), tokens.Params, $"params failed on: '{test.Input}'");
+                CollectionAssert.AreEqual(atoms.Params ?? new List<string>(), tokens.Params,
+                    $"params failed on: '{test.Input}'");
             }
         }
 
@@ -44,10 +45,7 @@ namespace IrcTokens.Tests
                 var atoms = test.Atoms;
                 var line = new Line
                 {
-                    Command = atoms.Verb,
-                    Params = atoms.Params,
-                    Source = atoms.Source,
-                    Tags = atoms.Tags
+                    Command = atoms.Verb, Params = atoms.Params, Source = atoms.Source, Tags = atoms.Tags
                 }.Format();
 
                 Assert.IsTrue(test.Matches.Contains(line), test.Description);
diff --git a/IrcTokens/Tests/StatefulDecoder.cs b/IrcTokens/Tests/StatefulDecoder.cs
index 209a6cf..da4009e 100644
--- a/IrcTokens/Tests/StatefulDecoder.cs
+++ b/IrcTokens/Tests/StatefulDecoder.cs
@@ -1,6 +1,6 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using System.Text;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 namespace IrcTokens.Tests
 {
@@ -25,7 +25,7 @@ namespace IrcTokens.Tests
             Assert.AreEqual(1, lines.Count);
 
             var line = new Line("PRIVMSG #channel hello");
-            CollectionAssert.AreEqual(new List<Line> { line }, lines);
+            CollectionAssert.AreEqual(new List<Line> {line}, lines);
         }
 
         [TestMethod]
@@ -44,9 +44,9 @@ namespace IrcTokens.Tests
         public void TestEncoding()
         {
             var iso8859 = Encoding.GetEncoding("iso-8859-1");
-            _decoder = new IrcTokens.StatefulDecoder { Encoding = iso8859 };
+            _decoder = new IrcTokens.StatefulDecoder {Encoding = iso8859};
             var lines = _decoder.Push(iso8859.GetBytes("PRIVMSG #channel :hello Ç\r\n"));
-            var line = new Line("PRIVMSG #channel :hello Ç");
+            var line  = new Line("PRIVMSG #channel :hello Ç");
             Assert.IsTrue(line.Equals(lines[0]));
         }
 
@@ -54,7 +54,7 @@ namespace IrcTokens.Tests
         public void TestEncodingFallback()
         {
             var latin1 = Encoding.GetEncoding("iso-8859-1");
-            _decoder = new IrcTokens.StatefulDecoder { Encoding = null, Fallback = latin1 };
+            _decoder = new IrcTokens.StatefulDecoder {Encoding = null, Fallback = latin1};
             var lines = _decoder.Push(latin1.GetBytes("PRIVMSG #channel hélló\r\n"));
             Assert.AreEqual(1, lines.Count);
             Assert.IsTrue(new Line("PRIVMSG #channel hélló").Equals(lines[0]));
diff --git a/IrcTokens/Tests/StatefulEncoder.cs b/IrcTokens/Tests/StatefulEncoder.cs
index e3ed70d..f2cd6c4 100644
--- a/IrcTokens/Tests/StatefulEncoder.cs
+++ b/IrcTokens/Tests/StatefulEncoder.cs
@@ -1,5 +1,5 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Text;
+using System.Text;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 namespace IrcTokens.Tests
 {
@@ -52,6 +52,19 @@ namespace IrcTokens.Tests
         }
 
         [TestMethod]
+        public void TestPopMultipleLines()
+        {
+            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 TestClear()
         {
             _encoder.Push(new Line("PRIVMSG #channel hello"));
@@ -63,7 +76,7 @@ namespace IrcTokens.Tests
         public void TestEncoding()
         {
             var iso8859 = Encoding.GetEncoding("iso-8859-1");
-            _encoder = new IrcTokens.StatefulEncoder { Encoding = iso8859 };
+            _encoder = new IrcTokens.StatefulEncoder {Encoding = iso8859};
             _encoder.Push(new Line("PRIVMSG #channel :hello Ç"));
             CollectionAssert.AreEqual(iso8859.GetBytes("PRIVMSG #channel :hello Ç\r\n"), _encoder.PendingBytes);
         }
diff --git a/IrcTokens/Tests/Tokenization.cs b/IrcTokens/Tests/Tokenization.cs
index c4970ed..7e2139d 100644
--- a/IrcTokens/Tests/Tokenization.cs
+++ b/IrcTokens/Tests/Tokenization.cs
@@ -1,5 +1,5 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Collections.Generic;
+using System.Collections.Generic;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 namespace IrcTokens.Tests
 {
@@ -87,14 +87,14 @@ namespace IrcTokens.Tests
         public void TestParamsTrailing()
         {
             var line = new Line("PRIVMSG #channel :hello world");
-            CollectionAssert.AreEqual(new List<string> { "#channel", "hello world" }, line.Params);
+            CollectionAssert.AreEqual(new List<string> {"#channel", "hello world"}, line.Params);
         }
 
         [TestMethod]
         public void TestParamsOnlyTrailing()
         {
             var line = new Line("PRIVMSG :hello world");
-            CollectionAssert.AreEqual(new List<string> { "hello world" }, line.Params);
+            CollectionAssert.AreEqual(new List<string> {"hello world"}, line.Params);
         }
 
         [TestMethod]
@@ -109,10 +109,10 @@ namespace IrcTokens.Tests
         public void TestAllTokens()
         {
             var line = new Line("@id=123 :nick!user@host PRIVMSG #channel :hello world");
-            CollectionAssert.AreEqual(new Dictionary<string, string> { { "id", "123" } }, line.Tags);
+            CollectionAssert.AreEqual(new Dictionary<string, string> {{"id", "123"}}, line.Tags);
             Assert.AreEqual("nick!user@host", line.Source);
             Assert.AreEqual("PRIVMSG", line.Command);
-            CollectionAssert.AreEqual(new List<string> { "#channel", "hello world" }, line.Params);
+            CollectionAssert.AreEqual(new List<string> {"#channel", "hello world"}, line.Params);
         }
     }
 }