about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2020-05-06 10:39:59 -0400
committerBen Harris <ben@tilde.team>2020-05-06 10:39:59 -0400
commitbe7ffb0d5d36f6f292bfdc779bfd903308c7b439 (patch)
tree23c4c0318488c318483f7a3ed426075cbc880e78
parent7c482d8cd99b59bbbecf636b797e9e7fec652514 (diff)
add params Line() constructor
-rw-r--r--Examples/Tokens/Client.cs14
-rw-r--r--Examples/Tokens/Program.cs3
-rw-r--r--IrcTokens/Line.cs6
-rw-r--r--IrcTokens/README.md2
-rw-r--r--IrcTokens/Tests/Format.cs45
5 files changed, 26 insertions, 44 deletions
diff --git a/Examples/Tokens/Client.cs b/Examples/Tokens/Client.cs
index 1061986..3dd3933 100644
--- a/Examples/Tokens/Client.cs
+++ b/Examples/Tokens/Client.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections.Generic;
 using System.Net.Sockets;
 using System.Threading;
 using IrcTokens;
@@ -26,8 +25,8 @@ namespace TokensSample
             _socket.Connect("127.0.0.1", 6667);
             while (!_socket.Connected) Thread.Sleep(1000);
 
-            Send(new Line {Command = "NICK", Params = new List<string> {"tokensbot"}});
-            Send(new Line {Command = "USER", Params = new List<string> {"tokensbot", "0", "*", "real name"}});
+            Send(new Line("NICK", "tokensbot"));
+            Send(new Line("USER", "tokensbot", "0", "*", "real name"));
 
             while (true)
             {
@@ -50,16 +49,13 @@ namespace TokensSample
                     switch (line.Command)
                     {
                         case "PING":
-                            Send(new Line {Command = "PONG", Params = line.Params});
+                            Send(new Line("PONG", line.Params[0]));
                             break;
                         case "001":
-                            Send(new Line {Command = "JOIN", Params = new List<string> {"#test"}});
+                            Send(new Line("JOIN", "#test"));
                             break;
                         case "PRIVMSG":
-                            Send(new Line
-                            {
-                                Command = "PRIVMSG", Params = new List<string> {line.Params[0], "hello there"}
-                            });
+                            Send(new Line("PRIVMSG", line.Params[0], "hello there"));
                             break;
                     }
                 }
diff --git a/Examples/Tokens/Program.cs b/Examples/Tokens/Program.cs
index c3a0885..ba57836 100644
--- a/Examples/Tokens/Program.cs
+++ b/Examples/Tokens/Program.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections.Generic;
 using IrcTokens;
 
 namespace TokensSample
@@ -14,7 +13,7 @@ namespace TokensSample
             Console.WriteLine(line.Format());
 
             // formatting
-            var line2 = new Line {Command = "USER", Params = new List<string> {"user", "0", "*", "real name"}};
+            var line2 = new Line("USER", "user", "0", "*", "real name");
             Console.WriteLine(line2);
             Console.WriteLine(line2.Format());
 
diff --git a/IrcTokens/Line.cs b/IrcTokens/Line.cs
index 50f93ec..79d8b2d 100644
--- a/IrcTokens/Line.cs
+++ b/IrcTokens/Line.cs
@@ -21,6 +21,12 @@ namespace IrcTokens
         {
         }
 
+        public Line(string command, params string[] parameters)
+        {
+            Command = command;
+            Params  = parameters.ToList();
+        }
+
         /// <summary>
         ///     Build new <see cref="Line" /> object parsed from
         ///     <param name="line">a string</param>
diff --git a/IrcTokens/README.md b/IrcTokens/README.md
index 94780eb..216dcf8 100644
--- a/IrcTokens/README.md
+++ b/IrcTokens/README.md
@@ -23,7 +23,7 @@ https://github.com/jesopo/irctokens)
 
 ### stateful
 
-see the full example in [Examples/Tokens/Client.cs](Examples/Tokens/Client.cs)
+see the full example in [Examples/Tokens/Client.cs](../Examples/Tokens/Client.cs)
 
     public class Client
     {
diff --git a/IrcTokens/Tests/Format.cs b/IrcTokens/Tests/Format.cs
index 8ef5344..69a5682 100644
--- a/IrcTokens/Tests/Format.cs
+++ b/IrcTokens/Tests/Format.cs
@@ -10,11 +10,9 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestTags()
         {
-            var line = new Line
+            var line = new Line("PRIVMSG", "#channel", "hello")
             {
-                Command = "PRIVMSG",
-                Params  = new List<string> {"#channel", "hello"},
-                Tags    = new Dictionary<string, string> {{"id", "\\" + " " + ";" + "\r\n"}}
+                Tags = new Dictionary<string, string> {{"id", "\\" + " " + ";" + "\r\n"}}
             }.Format();
 
             Assert.AreEqual("@id=\\\\\\s\\:\\r\\n PRIVMSG #channel hello", line);
@@ -23,7 +21,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("PRIVMSG", "#channel", "hello").Format();
 
             Assert.AreEqual("PRIVMSG #channel hello", line);
         }
@@ -31,12 +29,8 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestNullTag()
         {
-            var line = new Line
-            {
-                Command = "PRIVMSG",
-                Params  = new List<string> {"#channel", "hello"},
-                Tags    = new Dictionary<string, string> {{"a", null}}
-            }.Format();
+            var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new Dictionary<string, string> {{"a", null}}}
+                .Format();
 
             Assert.AreEqual("@a PRIVMSG #channel hello", line);
         }
@@ -44,12 +38,8 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestEmptyTag()
         {
-            var line = new Line
-            {
-                Command = "PRIVMSG",
-                Params  = new List<string> {"#channel", "hello"},
-                Tags    = new Dictionary<string, string> {{"a", ""}}
-            }.Format();
+            var line = new Line("PRIVMSG", "#channel", "hello") {Tags = new Dictionary<string, string> {{"a", ""}}}
+                .Format();
 
             Assert.AreEqual("@a PRIVMSG #channel hello", line);
         }
@@ -57,10 +47,7 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestSource()
         {
-            var line = new Line
-            {
-                Command = "PRIVMSG", Params = new List<string> {"#channel", "hello"}, Source = "nick!user@host"
-            }.Format();
+            var line = new Line("PRIVMSG", "#channel", "hello") {Source = "nick!user@host"}.Format();
 
             Assert.AreEqual(":nick!user@host PRIVMSG #channel hello", line);
         }
@@ -82,7 +69,7 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestTrailingSpace()
         {
-            var line = new Line {Command = "PRIVMSG", Params = new List<string> {"#channel", "hello world"}}.Format();
+            var line = new Line("PRIVMSG", "#channel", "hello world").Format();
 
             Assert.AreEqual("PRIVMSG #channel :hello world", line);
         }
@@ -90,7 +77,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("PRIVMSG", "#channel", "helloworld").Format();
 
             Assert.AreEqual("PRIVMSG #channel helloworld", line);
         }
@@ -98,7 +85,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("PRIVMSG", "#channel", ":helloworld").Format();
 
             Assert.AreEqual("PRIVMSG #channel ::helloworld", line);
         }
@@ -106,19 +93,13 @@ namespace IrcTokens.Tests
         [TestMethod]
         public void TestInvalidNonLastSpace()
         {
-            Assert.ThrowsException<ArgumentException>(() =>
-            {
-                new Line {Command = "USER", Params = new List<string> {"user", "0 *", "real name"}}.Format();
-            });
+            Assert.ThrowsException<ArgumentException>(() => { new Line("USER", "user", "0 *", "real name").Format(); });
         }
 
         [TestMethod]
         public void TestInvalidNonLastColon()
         {
-            Assert.ThrowsException<ArgumentException>(() =>
-            {
-                new Line {Command = "PRIVMSG", Params = new List<string> {":#channel", "hello"}}.Format();
-            });
+            Assert.ThrowsException<ArgumentException>(() => { new Line("PRIVMSG", ":#channel", "hello").Format(); });
         }
     }
 }