~sircmpwn/ChatSharp

f712abaaef9b9d7f589d55e9547acfac7db097a8 — Alexandre Oliveira 4 years ago 0ec65c9
Update tag parsing to differentiate null from empty string

- https://github.com/ircv3/ircv3-specifications/issues/334
2 files changed, 14 insertions(+), 1 deletions(-)

M ChatSharp/IrcMessage.cs
M ChatSharpTests/IrcMessageTests.cs
M ChatSharp/IrcMessage.cs => ChatSharp/IrcMessage.cs +2 -1
@@ 52,7 52,8 @@ namespace ChatSharp
                foreach (string rawTag in rawTags.Split(';'))
                {
                    var replacedTag = rawTag.Replace(@"\:", ";");
                    KeyValuePair<string, string> tag = new KeyValuePair<string, string>(replacedTag, string.Empty);
                    // The spec declares `@a=` as a tag with an empty value, while `@b;` as a tag with a null value
                    KeyValuePair<string, string> tag = new KeyValuePair<string, string>(replacedTag, null);

                    if (replacedTag.Contains("="))
                    {

M ChatSharpTests/IrcMessageTests.cs => ChatSharpTests/IrcMessageTests.cs +12 -0
@@ 83,6 83,18 @@ namespace ChatSharp.Tests
        }

        [TestMethod]
        public void NewValidMessage_TagsNoValue()
        {
            IrcMessage fromMessage = new IrcMessage("@a=;b :nick!ident@host.com PRIVMSG me :Hello");
            KeyValuePair<string, string>[] compareTags = new KeyValuePair<string, string>[]
            {
                new KeyValuePair<string, string>("a", ""),
                new KeyValuePair<string, string>("b", null),
            };
            CollectionAssert.AreEqual(fromMessage.Tags, compareTags);
        }

        [TestMethod]
        public void Timestamp_CompareISOString()
        {
            IrcMessage[] messages = {