fix(scripting): #1056 refuse a {{equip}} token in a verbatim/raw/interpolated path literal — editor diagnostic + deploy-gate refusal

This commit is contained in:
Joseph Doherty
2026-12-03 15:05:40 -05:00
parent 16c8b7ffad
commit e840ec1fbc
6 changed files with 211 additions and 2 deletions
@@ -0,0 +1,29 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.ScriptAnalysis;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.ScriptAnalysis;
/// <summary>lmxopcua#1056 — the editor refuses a <c>{{equip}}</c> token in a verbatim/raw/interpolated path literal, as the deploy gate does.</summary>
public sealed class EquipLiteralDiagnosticTests
{
private static readonly ScriptAnalysisService Svc = new();
[Theory]
[InlineData("return ctx.GetTag(@\"{{equip}}/speed\").Value;", null)]
[InlineData("return ctx.GetTag(\"\"\"{{equip}}/speed\"\"\").Value;", null)]
[InlineData("return ctx.GetTag(@\"{{equip}}/speed\").Value is not null;", ScriptAnalysisModes.AlarmPredicate)]
public void A_token_in_a_non_regular_literal_is_an_error_marker_on_its_line(string code, string? mode)
{
var m = Svc.Diagnose(new DiagnoseRequest("var a = 1;\n" + code, Mode: mode), TestContext.Current.CancellationToken).Markers
.Single(x => x.Code == "OTSCRIPT_EQUIPLITERAL");
m.Severity.ShouldBe(8);
m.StartLineNumber.ShouldBe(2);
m.Message.ShouldContain("regular");
}
[Fact]
public void The_regular_literal_form_is_not_flagged_positive_control()
=> Svc.Diagnose(new DiagnoseRequest("return ctx.GetTag(\"{{equip}}/speed\").Value;"), TestContext.Current.CancellationToken).Markers
.ShouldNotContain(x => x.Code == "OTSCRIPT_EQUIPLITERAL");
}