implemented ordering preservation

This commit is contained in:
Martino Ferrari
2026-01-23 10:23:02 +01:00
parent e2c87c90f3
commit 5c3f05a1a4
18 changed files with 262 additions and 279 deletions

View File

@@ -18,7 +18,7 @@ func TestMultiFileBuildMergeAndOrder(t *testing.T) {
// File 1: Has FieldA, no Class.
// File 2: Has Class, FieldB.
// Both in package +MyObj
f1Content := `
#package Proj.+MyObj
FieldA = 10
@@ -30,10 +30,10 @@ FieldB = 20
`
os.WriteFile("build_multi_test/f1.marte", []byte(f1Content), 0644)
os.WriteFile("build_multi_test/f2.marte", []byte(f2Content), 0644)
// Execute Build
b := builder.NewBuilder([]string{"build_multi_test/f1.marte", "build_multi_test/f2.marte"})
// Prepare output file
// Should be +MyObj.marte (normalized MyObj.marte) - Actually checking content
outputFile := "build_multi_test/MyObj.marte"
@@ -48,19 +48,19 @@ FieldB = 20
t.Fatalf("Build failed: %v", err)
}
f.Close() // Close to flush
// Check Output
if _, err := os.Stat(outputFile); os.IsNotExist(err) {
t.Fatalf("Expected output file not found")
}
content, err := os.ReadFile(outputFile)
if err != nil {
t.Fatalf("Failed to read output: %v", err)
}
output := string(content)
// Check presence
if !strings.Contains(output, "Class = \"MyClass\"") {
t.Error("Output missing Class")
@@ -71,23 +71,23 @@ FieldB = 20
if !strings.Contains(output, "FieldB = 20") {
t.Error("Output missing FieldB")
}
// Check Order: Class/FieldB (from f2) should come BEFORE FieldA (from f1)
// because f2 has the Class definition.
idxClass := strings.Index(output, "Class")
idxFieldB := strings.Index(output, "FieldB")
idxFieldA := strings.Index(output, "FieldA")
if idxClass == -1 || idxFieldB == -1 || idxFieldA == -1 {
t.Fatal("Missing fields in output")
}
// Class should be first
if idxClass > idxFieldA {
t.Errorf("Expected Class (from f2) to be before FieldA (from f1). Output:\n%s", output)
}
// FieldB should be near Class (same fragment)
// FieldA should be after
if idxFieldB > idxFieldA {