mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2025-12-18 04:22:52 +00:00
Extend supported variables and improve parser errors
This commit is contained in:
40
Sharp7.Rx.Tests/S7VariableAddressTests/MatchesType.cs
Normal file
40
Sharp7.Rx.Tests/S7VariableAddressTests/MatchesType.cs
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user