diff options
author | Ben Harris <ben@tilde.team> | 2020-04-22 16:28:51 -0400 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2020-04-22 16:28:51 -0400 |
commit | 933a4f85604e21445c9bac8272d64cf3e6f65e00 (patch) | |
tree | 5b300ca37beff5cf11ed67a8b6e3550d24cf18a3 /IrcTokens/Tests/Parser.cs | |
parent | 338763fde71ba2dc0de8ea5e2437d24ee365874b (diff) |
rename to IrcSharp
also tidy up formatting with vs tools
Diffstat (limited to 'IrcTokens/Tests/Parser.cs')
-rw-r--r-- | IrcTokens/Tests/Parser.cs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/IrcTokens/Tests/Parser.cs b/IrcTokens/Tests/Parser.cs new file mode 100644 index 0000000..df70b92 --- /dev/null +++ b/IrcTokens/Tests/Parser.cs @@ -0,0 +1,57 @@ +using IrcTokens.Tests.Data; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; + +namespace IrcTokens.Tests +{ + [TestClass] + public class Parser + { + private static T LoadYaml<T>(string path) + { + var deserializer = new DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build(); + + return deserializer.Deserialize<T>(File.ReadAllText(path)); + } + + [TestMethod] + public void TestSplit() + { + foreach (var test in LoadYaml<SplitModel>("Tests/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<string>(), tokens.Params, $"params failed on: '{test.Input}'"); + } + } + + [TestMethod] + public void TestJoin() + { + foreach (var test in LoadYaml<JoinModel>("Tests/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); + } + } + } +} |