From 35bbd30c2506b3d0b18397ef1443fb18c0d893d6 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 10 Nov 2020 18:35:21 -0500 Subject: Move tests to a separate project --- IRCSharp.Tests/Tokenization/Parser.cs | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 IRCSharp.Tests/Tokenization/Parser.cs (limited to 'IRCSharp.Tests/Tokenization/Parser.cs') diff --git a/IRCSharp.Tests/Tokenization/Parser.cs b/IRCSharp.Tests/Tokenization/Parser.cs new file mode 100644 index 0000000..40ff803 --- /dev/null +++ b/IRCSharp.Tests/Tokenization/Parser.cs @@ -0,0 +1,55 @@ +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; + +namespace IRCTokens.Tests +{ + [TestClass] + public class Parser + { + private static T LoadYaml(string path) + { + var deserializer = new DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build(); + + return deserializer.Deserialize(File.ReadAllText(path)); + } + + [TestMethod] + public void Split() + { + foreach (var test in LoadYaml("Tokenization/Data/msg-split.yaml").Tests) + { + var tokens = new Line(test.Input); + 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(), tokens.Params, + $"params failed on: '{test.Input}'"); + } + } + + [TestMethod] + public void Join() + { + foreach (var test in LoadYaml("Tokenization/Data/msg-join.yaml").Tests) + { + var atoms = test.Atoms; + var line = new Line + { + Command = atoms.Verb, Params = atoms.Params, Source = atoms.Source, Tags = atoms.Tags + }.Format(); + + Assert.IsTrue(test.Matches.Contains(line), test.Description); + } + } + } +} -- cgit 1.4.1