From 164dad896c6d392d67923e557d98f5c5f16c0900 Mon Sep 17 00:00:00 2001 From: Martino Ferrari Date: Thu, 22 Jan 2026 01:53:50 +0100 Subject: [PATCH] better indexing --- test/validator_gam_signals_linking_test.go | 81 ++++++++++++++++ test/validator_gam_signals_test.go | 108 +++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 test/validator_gam_signals_linking_test.go create mode 100644 test/validator_gam_signals_test.go diff --git a/test/validator_gam_signals_linking_test.go b/test/validator_gam_signals_linking_test.go new file mode 100644 index 0000000..7f922d0 --- /dev/null +++ b/test/validator_gam_signals_linking_test.go @@ -0,0 +1,81 @@ +package integration + +import ( + "testing" + + "github.com/marte-dev/marte-dev-tools/internal/index" + "github.com/marte-dev/marte-dev-tools/internal/parser" + "github.com/marte-dev/marte-dev-tools/internal/validator" +) + +func TestGAMSignalLinking(t *testing.T) { + content := ` ++Data = { + Class = ReferenceContainer + +MyDS = { + Class = FileReader + Filename = "test.txt" + Signals = { + MySig = { Type = uint32 } + } + } +} + ++MyGAM = { + Class = IOGAM + InputSignals = { + MySig = { + DataSource = MyDS + Type = uint32 + } + AliasedSig = { + Alias = MySig + DataSource = MyDS + Type = uint32 + } + } +} +` + p := parser.NewParser(content) + config, err := p.Parse() + if err != nil { + t.Fatalf("Parse failed: %v", err) + } + + idx := index.NewProjectTree() + idx.AddFile("gam_signals_linking.marte", config) + idx.ResolveReferences() + + v := validator.NewValidator(idx, ".") + v.ValidateProject() + + if len(v.Diagnostics) > 0 { + for _, d := range v.Diagnostics { + t.Logf("Diagnostic: %s", d.Message) + } + t.Fatalf("Validation failed with %d issues", len(v.Diagnostics)) + } + + foundMyDSRef := 0 + foundAliasRef := 0 + + for _, ref := range idx.References { + if ref.Name == "MyDS" { + if ref.Target != nil && ref.Target.RealName == "+MyDS" { + foundMyDSRef++ + } + } + if ref.Name == "MySig" { + if ref.Target != nil && ref.Target.RealName == "MySig" { + foundAliasRef++ + } + } + } + + if foundMyDSRef < 2 { + t.Errorf("Expected at least 2 resolved MyDS references, found %d", foundMyDSRef) + } + if foundAliasRef < 1 { + t.Errorf("Expected at least 1 resolved Alias MySig reference, found %d", foundAliasRef) + } +} diff --git a/test/validator_gam_signals_test.go b/test/validator_gam_signals_test.go new file mode 100644 index 0000000..54fd515 --- /dev/null +++ b/test/validator_gam_signals_test.go @@ -0,0 +1,108 @@ +package integration + +import ( + "strings" + "testing" + + "github.com/marte-dev/marte-dev-tools/internal/index" + "github.com/marte-dev/marte-dev-tools/internal/parser" + "github.com/marte-dev/marte-dev-tools/internal/validator" +) + +func TestGAMSignalValidation(t *testing.T) { + content := ` ++Data = { + Class = ReferenceContainer + +InDS = { + Class = FileReader + Signals = { + SigIn = { Type = uint32 } + } + } + +OutDS = { + Class = FileWriter + Signals = { + SigOut = { Type = uint32 } + } + } +} + ++MyGAM = { + Class = IOGAM + InputSignals = { + SigIn = { + DataSource = InDS + Type = uint32 + } + // Error: OutDS is OUT only + BadInput = { + DataSource = OutDS + Alias = SigOut + Type = uint32 + } + // Error: MissingSig not in InDS + Missing = { + DataSource = InDS + Alias = MissingSig + Type = uint32 + } + } + OutputSignals = { + SigOut = { + DataSource = OutDS + Type = uint32 + } + // Error: InDS is IN only + BadOutput = { + DataSource = InDS + Alias = SigIn + Type = uint32 + } + } +} +` + p := parser.NewParser(content) + config, err := p.Parse() + if err != nil { + t.Fatalf("Parse failed: %v", err) + } + + idx := index.NewProjectTree() + idx.AddFile("gam_signals.marte", config) + idx.ResolveReferences() + + v := validator.NewValidator(idx, ".") + v.ValidateProject() + + foundBadInput := false + foundMissing := false + foundBadOutput := false + + for _, d := range v.Diagnostics { + if strings.Contains(d.Message, "DataSource 'OutDS' (Class FileWriter) is Output-only but referenced in InputSignals") { + foundBadInput = true + } + if strings.Contains(d.Message, "Signal 'MissingSig' not found in DataSource 'InDS'") { + foundMissing = true + } + if strings.Contains(d.Message, "DataSource 'InDS' (Class FileReader) is Input-only but referenced in OutputSignals") { + foundBadOutput = true + } + } + + if !foundBadInput || !foundMissing || !foundBadOutput { + for _, d := range v.Diagnostics { + t.Logf("Diagnostic: %s", d.Message) + } + } + + if !foundBadInput { + t.Error("Expected error for OutDS in InputSignals") + } + if !foundMissing { + t.Error("Expected error for missing signal reference") + } + if !foundBadOutput { + t.Error("Expected error for InDS in OutputSignals") + } +}