ircsharp/IRCSharp.Tests/Tokenization/Parser.cs

57 lines
1.9 KiB
C#
Raw Normal View History

2020-04-28 04:35:52 +00:00
using System.Collections.Generic;
using System.Globalization;
2020-04-20 00:52:41 +00:00
using System.IO;
2022-03-25 19:11:48 +00:00
using IRCSharp.Tests.Tokenization.Data;
using IRCTokens;
2020-04-28 04:35:52 +00:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
2020-04-20 00:52:41 +00:00
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
2022-03-25 19:11:48 +00:00
namespace IRCSharp.Tests.Tokenization
2020-04-20 00:52:41 +00:00
{
[TestClass]
public class Parser
2020-04-20 00:52:41 +00:00
{
private static T LoadYaml<T>(string path)
{
var deserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();
return deserializer.Deserialize<T>(File.ReadAllText(path));
}
[TestMethod]
2020-05-17 02:08:40 +00:00
public void Split()
2020-04-20 00:52:41 +00:00
{
2020-11-10 23:35:21 +00:00
foreach (var test in LoadYaml<SplitModel>("Tokenization/Data/msg-split.yaml").Tests)
2020-04-20 00:52:41 +00:00
{
var tokens = new Line(test.Input);
2020-04-28 04:35:52 +00:00
var atoms = test.Atoms;
2020-04-20 00:52:41 +00:00
Assert.AreEqual(atoms.Verb.ToUpper(CultureInfo.InvariantCulture), tokens.Command,
$"command failed on: '{test.Input}'");
2020-04-20 00:52:41 +00:00
Assert.AreEqual(atoms.Source, tokens.Source, $"source failed on: '{test.Input}'");
CollectionAssert.AreEqual(atoms.Tags, tokens.Tags, $"tags failed on: '{test.Input}'");
2020-04-28 04:35:52 +00:00
CollectionAssert.AreEqual(atoms.Params ?? new List<string>(), tokens.Params,
$"params failed on: '{test.Input}'");
2020-04-20 00:52:41 +00:00
}
}
[TestMethod]
2020-05-17 02:08:40 +00:00
public void Join()
2020-04-20 00:52:41 +00:00
{
2020-11-10 23:35:21 +00:00
foreach (var test in LoadYaml<JoinModel>("Tokenization/Data/msg-join.yaml").Tests)
2020-04-20 00:52:41 +00:00
{
var atoms = test.Atoms;
var line = new Line
{
2020-04-28 04:35:52 +00:00
Command = atoms.Verb, Params = atoms.Params, Source = atoms.Source, Tags = atoms.Tags
2020-04-20 00:52:41 +00:00
}.Format();
Assert.IsTrue(test.Matches.Contains(line), test.Description);
}
}
}
}