better indexing

This commit is contained in:
Martino Ferrari
2026-01-22 01:26:24 +01:00
parent 5b0834137b
commit 4a624aa929
3 changed files with 6546 additions and 0 deletions

6414
examples/test_app.marte Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,73 @@
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 TestSignalValidation(t *testing.T) {
content := `
+Data = {
Class = ReferenceContainer
+ValidDS = {
Class = DataSource
Signals = {
ValidSig = {
Type = uint32
}
}
}
+MissingTypeDS = {
Class = DataSource
Signals = {
InvalidSig = {
// Missing Type
Dummy = 1
}
}
}
+InvalidTypeDS = {
Class = DataSource
Signals = {
InvalidSig = {
Type = invalid_type
}
}
}
}
`
p := parser.NewParser(content)
config, err := p.Parse()
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
idx := index.NewProjectTree()
idx.AddFile("signal_test.marte", config)
v := validator.NewValidator(idx, ".")
v.ValidateProject()
foundMissing := false
foundInvalid := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "missing mandatory field 'Type'") {
foundMissing = true
}
if strings.Contains(d.Message, "Invalid Type 'invalid_type'") {
foundInvalid = true
}
}
if !foundMissing {
t.Error("Expected error for missing Type field in Signal")
}
if !foundInvalid {
t.Error("Expected error for invalid Type value in Signal")
}
}

View File

@@ -0,0 +1,59 @@
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 TestSignalsContentValidation(t *testing.T) {
content := `
+Data = {
Class = ReferenceContainer
+BadDS = {
Class = DataSource
Signals = {
BadField = 1
BadArray = { 1 2 }
// Valid signal
ValidSig = {
Type = uint32
}
}
}
}
`
p := parser.NewParser(content)
config, err := p.Parse()
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
idx := index.NewProjectTree()
idx.AddFile("signals_content.marte", config)
v := validator.NewValidator(idx, ".")
v.ValidateProject()
foundBadField := false
foundBadArray := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Field 'BadField' is not allowed") {
foundBadField = true
}
if strings.Contains(d.Message, "Field 'BadArray' is not allowed") {
foundBadArray = true
}
}
if !foundBadField {
t.Error("Expected error for BadField in Signals")
}
if !foundBadArray {
t.Error("Expected error for BadArray in Signals")
}
}