Extend supported variables and improve parser errors

This commit is contained in:
Peter Butzhammer
2024-02-07 17:40:51 +01:00
parent 2a694bf980
commit 6492d039da
11 changed files with 323 additions and 73 deletions

View File

@@ -0,0 +1,40 @@
using System.Reflection;
using NUnit.Framework;
using Sharp7.Rx.Extensions;
using Sharp7.Rx.Interfaces;
using Shouldly;
namespace Sharp7.Rx.Tests.S7VariableAddressTests;
[TestFixture]
public class MatchesType
{
static readonly IS7VariableNameParser parser = new S7VariableNameParser();
public void Supported(Type type, string address)
{
Check(type, address, true);
}
public IEnumerable<TestCase> GetValid()
{
yield return new TestCase(typeof(bool), "DB0.DBx0.0");
yield return new TestCase(typeof(short), "DB0.INT0");
yield return new TestCase(typeof(int), "DB0.DINT0");
yield return new TestCase(typeof(long), "DB0.DUL0");
yield return new TestCase(typeof(ulong), "DB0.DUL0");
}
private static void Check(Type type, string address, bool expected)
{
//Arrange
var variableAddress = parser.Parse(address);
//Act
variableAddress.MatchesType(type).ShouldBe(expected);
}
public record TestCase(Type Type, string Address);
}