better indexing
This commit is contained in:
81
test/validator_gam_signals_linking_test.go
Normal file
81
test/validator_gam_signals_linking_test.go
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
108
test/validator_gam_signals_test.go
Normal file
108
test/validator_gam_signals_test.go
Normal file
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user