IRC parsing, tokenization, and state handling in C#
at ircrobots 51 lines 1.6 kB view raw
1using System.Globalization; 2using IRCSharp.Tests.Tokens.Data; 3using YamlDotNet.Serialization; 4using YamlDotNet.Serialization.NamingConventions; 5 6namespace IRCSharp.Tests.Tokens; 7 8[TestClass] 9public class Parser 10{ 11 private static T LoadYaml<T>(string path) 12 { 13 var deserializer = new DeserializerBuilder() 14 .WithNamingConvention(CamelCaseNamingConvention.Instance) 15 .Build(); 16 17 return deserializer.Deserialize<T>(File.ReadAllText(path)); 18 } 19 20 [TestMethod] 21 public void Split() 22 { 23 foreach (var test in LoadYaml<SplitModel>("Tokens/Data/msg-split.yaml").Tests) 24 { 25 var tokens = new Line(test.Input); 26 var atoms = test.Atoms; 27 28 Assert.AreEqual(atoms.Verb.ToUpper(CultureInfo.InvariantCulture), tokens.Command, 29 $"command failed on: '{test.Input}'"); 30 Assert.AreEqual(atoms.Source, tokens.Source, $"source failed on: '{test.Input}'"); 31 CollectionAssert.AreEqual(atoms.Tags, tokens.Tags, $"tags failed on: '{test.Input}'"); 32 CollectionAssert.AreEqual(atoms.Params ?? [], tokens.Params, 33 $"params failed on: '{test.Input}'"); 34 } 35 } 36 37 [TestMethod] 38 public void Join() 39 { 40 foreach (var test in LoadYaml<JoinModel>("Tokens/Data/msg-join.yaml").Tests) 41 { 42 var atoms = test.Atoms; 43 var line = new Line 44 { 45 Command = atoms.Verb, Params = atoms.Params, Source = atoms.Source, Tags = atoms.Tags 46 }.Format(); 47 48 Assert.IsTrue(test.Matches.Contains(line), test.Description); 49 } 50 } 51}