fix(template-engine): resolve TemplateEngine-015,016 — cascade-rename nested derived templates, correct composed-script ParentPath
This commit is contained in:
@@ -624,4 +624,46 @@ public class FlatteningServiceTests
|
||||
var alarm = result.Value.Alarms.First(a => a.CanonicalName == "MainPump.PumpFault");
|
||||
Assert.Equal("MainPump.PumpAlarmHandler", alarm.OnTriggerScriptCanonicalName);
|
||||
}
|
||||
|
||||
// ── TemplateEngine-016: composed-script ScriptScope.ParentPath ─────────
|
||||
|
||||
[Fact]
|
||||
public void Flatten_NestedComposedScript_ScopeCarriesCorrectParentPath()
|
||||
{
|
||||
// Station composes Pump (level 1); Pump composes Motor (level 2).
|
||||
// The depth-1 script's parent is the root template (ParentPath "");
|
||||
// the depth-2 script's parent is the Pump module (ParentPath "MainPump").
|
||||
var motor = CreateTemplate(3, "Motor");
|
||||
motor.Scripts.Add(new TemplateScript("MonitorMotor", "// m") { Id = 70 });
|
||||
|
||||
var pump = CreateTemplate(2, "Pump");
|
||||
pump.Scripts.Add(new TemplateScript("MonitorPump", "// p") { Id = 71 });
|
||||
|
||||
var station = CreateTemplate(1, "Station");
|
||||
|
||||
var compositions = new Dictionary<int, IReadOnlyList<TemplateComposition>>
|
||||
{
|
||||
[1] = new List<TemplateComposition> { new("MainPump") { ComposedTemplateId = 2 } },
|
||||
[2] = new List<TemplateComposition> { new("DriveMotor") { ComposedTemplateId = 3 } },
|
||||
};
|
||||
var composedChains = new Dictionary<int, IReadOnlyList<Template>>
|
||||
{
|
||||
[2] = [pump], [3] = [motor],
|
||||
};
|
||||
|
||||
var instance = CreateInstance();
|
||||
var result = _sut.Flatten(instance, [station], compositions, composedChains,
|
||||
new Dictionary<int, DataConnection>());
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
|
||||
var depth1 = result.Value.Scripts.First(s => s.CanonicalName == "MainPump.MonitorPump");
|
||||
Assert.Equal("MainPump", depth1.Scope.SelfPath);
|
||||
Assert.Equal("", depth1.Scope.ParentPath);
|
||||
|
||||
var depth2 = result.Value.Scripts.First(s => s.CanonicalName == "MainPump.DriveMotor.MonitorMotor");
|
||||
Assert.Equal("MainPump.DriveMotor", depth2.Scope.SelfPath);
|
||||
// Parent module of a depth-2 script is the enclosing Pump module.
|
||||
Assert.Equal("MainPump", depth2.Scope.ParentPath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user