fix(ab-transport): widen libplctag guard regex to catch aliases and static usings

This commit is contained in:
Joseph Doherty
2026-10-07 15:49:24 -04:00
parent 29f456c3ef
commit de14d354e6
@@ -7,7 +7,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.Ab.Transport.Tests;
public sealed class LibplctagConfinementGuardTests
{
private static readonly Regex Reference = new(
@"\busing\s+libplctag\b|\blibplctag\.(Tag|Status|PlcType|Protocol|LibPlcTagException|NativeImport)\b",
@"\busing\s+(static\s+)?(\w+\s*=\s*)?libplctag\b|\blibplctag\.[A-Z]",
RegexOptions.Compiled);
[Fact]
@@ -43,4 +43,15 @@ public sealed class LibplctagConfinementGuardTests
var prose = "via libplctag. Second of six driver CLIs";
Reference.IsMatch(prose).ShouldBeFalse();
}
[Theory]
[InlineData("using libplctag;")]
[InlineData("global using libplctag;")]
[InlineData("using static libplctag.NativeImport.plctag;")]
[InlineData("using T = libplctag.Tag;")]
[InlineData("var x = new libplctag.DataTypes.DintPlcMapper();")]
public void Code_references_trip_the_guard(string code)
{
Reference.IsMatch(code).ShouldBeTrue($"regex should match: {code}");
}
}