feat(commons): TryParseRelayBody — detect pure ctx.GetTag relay scripts
This commit is contained in:
@@ -211,4 +211,29 @@ public class EquipmentScriptPathsTests
|
||||
{
|
||||
EquipmentScriptPaths.ContainsEquipToken(null).ShouldBeFalse();
|
||||
}
|
||||
|
||||
// ---- TryParseRelayBody ----
|
||||
|
||||
[Theory]
|
||||
[InlineData("return ctx.GetTag(\"TestMachine_020.TestChangingInt\").Value;", "TestMachine_020.TestChangingInt")]
|
||||
[InlineData(" return ctx . GetTag ( \"A.B\" ) . Value ; ", "A.B")]
|
||||
[InlineData("return ctx.GetTag(\"{{equip}}.Speed\").Value;", "{{equip}}.Speed")]
|
||||
public void TryParseRelayBody_accepts_exact_passthrough(string src, string expectedRef)
|
||||
{
|
||||
EquipmentScriptPaths.TryParseRelayBody(src, out var r).ShouldBeTrue();
|
||||
r.ShouldBe(expectedRef);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("return ctx.GetTag(\"A.B\").Value * 2;")]
|
||||
[InlineData("var x = ctx.GetTag(\"A.B\").Value; return x;")]
|
||||
[InlineData("return ctx.GetTag(\"A.B\").Value + ctx.GetTag(\"C.D\").Value;")]
|
||||
[InlineData("return ctx.GetTag(\"A.B\").Quality;")]
|
||||
[InlineData("return 5;")]
|
||||
[InlineData("")]
|
||||
public void TryParseRelayBody_rejects_non_relay(string src)
|
||||
{
|
||||
EquipmentScriptPaths.TryParseRelayBody(src, out var r).ShouldBeFalse();
|
||||
r.ShouldBeNull();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user