Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/ScriptAnalysis/HoverSignatureTests.cs
T
2026-06-09 15:03:40 -04:00

52 lines
2.2 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.ScriptAnalysis;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.ScriptAnalysis;
public sealed class HoverSignatureTests
{
private static readonly ScriptAnalysisService Svc = new();
[Fact] public void Hover_on_GetTag_returns_member_markdown()
{
// hover over the "GetTag" identifier in ctx.GetTag("A")
var md = Svc.Hover(new HoverRequest("""return ctx.GetTag("A").Value;""", 1, 16)).Markdown;
md.ShouldNotBeNull();
md!.ShouldContain("GetTag");
}
[Fact] public void Hover_on_nothing_returns_null()
=> Svc.Hover(new HoverRequest(" ", 1, 1)).Markdown.ShouldBeNull();
[Fact] public void SignatureHelp_inside_GetTag_call_shows_the_signature()
{
// caret just after the open paren of ctx.GetTag(
var sh = Svc.SignatureHelp(new SignatureHelpRequest("""return ctx.GetTag();""", 1, 19));
sh.Label.ShouldNotBeNull();
sh.Label!.ShouldContain("GetTag");
sh.Parameters.ShouldNotBeNull();
sh.Parameters!.ShouldContain(p => p.Label.Contains("path") || p.Label.Contains("string"));
}
[Fact] public void Hover_on_a_plain_local_resolves_the_local_not_an_enclosing_member()
{
// hovering the local `x` (not a member) must resolve the LOCAL, and must NOT climb to GetTag/Value.
var md = Svc.Hover(new HoverRequest("var x = 1;\nreturn ctx.GetTag(\"A\").Value + x;", 2, 33)).Markdown;
md.ShouldNotBeNull();
md!.ShouldContain("x");
md.ShouldNotContain("GetTag");
}
[Fact] public void SignatureHelp_for_parameterless_call_does_not_throw_and_clamps_active_to_zero()
{
// ctx.Now is a property, not a call; use a parameterless method if one exists, else assert empty-safe behavior.
// Deadband is static on ScriptContext (3 params) — instead verify a 0-arg edge via an empty arg list doesn't throw:
var sh = Svc.SignatureHelp(new SignatureHelpRequest("return ctx.GetTag();", 1, 19));
sh.ActiveParameter.ShouldBe(0); // clamped; no exception
}
[Fact] public void Hover_with_out_of_range_position_returns_null_without_throwing()
=> Svc.Hover(new HoverRequest("return 1;", 99, 99)).Markdown.ShouldBeNull();
}