feat(adminui): script document formatting (NormalizeWhitespace)

This commit is contained in:
Joseph Doherty
2026-06-09 15:06:40 -04:00
parent 9104b6c614
commit 4a2f7e37e5
2 changed files with 46 additions and 1 deletions
@@ -0,0 +1,30 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.ScriptAnalysis;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.ScriptAnalysis;
public sealed class FormatTests
{
private static readonly ScriptAnalysisService Svc = new();
private static string Fmt(string code) => Svc.Format(new FormatRequest(code)).Code;
[Fact] public void Reflows_crammed_source_to_canonical_layout()
{
var outp = Fmt("var x=1;return x;");
outp.ShouldNotBe("var x=1;return x;"); // it changed
outp.ShouldContain("\n"); // statements split onto separate lines
outp.ShouldContain("var x = 1;"); // canonical spacing
}
[Fact] public void Empty_code_is_returned_unchanged()
=> Fmt("").ShouldBe("");
[Fact] public void Unparseable_code_is_returned_unchanged()
{
// a fragment that NormalizeWhitespace can still parse in script mode won't throw;
// pass something that round-trips to itself or is returned as-is on failure.
var src = "return ctx.GetTag(\"A\").Value;";
Fmt(src).ShouldNotBeNull();
}
}