better indexing
This commit is contained in:
6414
examples/test_app.marte
Normal file
6414
examples/test_app.marte
Normal file
File diff suppressed because it is too large
Load Diff
73
test/validator_signal_test.go
Normal file
73
test/validator_signal_test.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
59
test/validator_signals_content_test.go
Normal file
59
test/validator_signals_content_test.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user