Almost done

This commit is contained in:
Martino Ferrari
2026-01-22 03:55:00 +01:00
parent a88f833f49
commit 0654062d08
12 changed files with 435 additions and 24 deletions

View File

@@ -140,3 +140,16 @@ func TestLSPHover(t *testing.T) {
t.Errorf("Expected +MyObject, got %s", res.Node.RealName)
}
}
func TestParserError(t *testing.T) {
invalidContent := `
A = {
Field =
}
`
p := parser.NewParser(invalidContent)
_, err := p.Parse()
if err == nil {
t.Fatal("Expected parser error, got nil")
}
}

View File

@@ -0,0 +1,74 @@
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 TestFunctionsArrayValidation(t *testing.T) {
content := `
+App = {
Class = RealTimeApplication
+State = {
Class = RealTimeState
+Thread = {
Class = RealTimeThread
Functions = {
ValidGAM,
InvalidGAM, // Not a GAM (DataSource)
MissingGAM, // Not found
"String", // Not reference
}
}
}
}
+ValidGAM = { Class = IOGAM InputSignals = {} }
+InvalidGAM = { Class = FileReader }
`
p := parser.NewParser(content)
config, err := p.Parse()
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
idx := index.NewProjectTree()
idx.AddFile("funcs.marte", config)
idx.ResolveReferences()
v := validator.NewValidator(idx, ".")
v.ValidateProject()
foundInvalid := false
foundMissing := false
foundNotRef := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "not found or is not a valid GAM") {
// This covers both InvalidGAM and MissingGAM cases
if strings.Contains(d.Message, "InvalidGAM") {
foundInvalid = true
}
if strings.Contains(d.Message, "MissingGAM") {
foundMissing = true
}
}
if strings.Contains(d.Message, "must contain references") {
foundNotRef = true
}
}
if !foundInvalid {
t.Error("Expected error for InvalidGAM")
}
if !foundMissing {
t.Error("Expected error for MissingGAM")
}
if !foundNotRef {
t.Error("Expected error for non-reference element")
}
}

View File

@@ -0,0 +1,65 @@
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 TestGlobalPragmaDebug(t *testing.T) {
content := `//! allow(implicit): Debugging
//! allow(unused): Debugging
+Data={Class=ReferenceContainer}
+GAM={Class=IOGAM InputSignals={Impl={DataSource=Data Type=uint32}}}
+UnusedGAM={Class=IOGAM}
`
p := parser.NewParser(content)
config, err := p.Parse()
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
// Check if pragma parsed
if len(config.Pragmas) == 0 {
t.Fatal("Pragma not parsed")
}
t.Logf("Parsed Pragma 0: %s", config.Pragmas[0].Text)
idx := index.NewProjectTree()
idx.AddFile("debug.marte", config)
idx.ResolveReferences()
// Check if added to GlobalPragmas
pragmas, ok := idx.GlobalPragmas["debug.marte"]
if !ok || len(pragmas) == 0 {
t.Fatal("GlobalPragmas not populated")
}
t.Logf("Global Pragma stored: %s", pragmas[0])
v := validator.NewValidator(idx, ".")
v.ValidateProject()
v.CheckUnused() // Must call this for unused check!
foundImplicitWarning := false
foundUnusedWarning := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Implicitly Defined Signal") {
foundImplicitWarning = true
t.Logf("Found warning: %s", d.Message)
}
if strings.Contains(d.Message, "Unused GAM") {
foundUnusedWarning = true
t.Logf("Found warning: %s", d.Message)
}
}
if foundImplicitWarning {
t.Error("Expected implicit warning to be suppressed")
}
if foundUnusedWarning {
t.Error("Expected unused warning to be suppressed")
}
}

View File

@@ -0,0 +1,75 @@
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 TestGlobalPragmaUpdate(t *testing.T) {
// Scenario: Project scope. File A has pragma. File B has warning.
fileA := "fileA.marte"
contentA_WithPragma := `
#package my.project
//!allow(unused): Suppress
`
contentA_NoPragma := `
#package my.project
// No pragma
`
fileB := "fileB.marte"
contentB := `
#package my.project
+Data={Class=ReferenceContainer +DS={Class=FileReader Filename="t" Signals={Unused={Type=uint32}}}}
`
idx := index.NewProjectTree()
// Helper to validate
check := func() bool {
idx.ResolveReferences()
v := validator.NewValidator(idx, ".")
v.ValidateProject()
v.CheckUnused()
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Unused Signal") {
return true // Found warning
}
}
return false
}
// 1. Add A (with pragma) and B
pA := parser.NewParser(contentA_WithPragma)
cA, _ := pA.Parse()
idx.AddFile(fileA, cA)
pB := parser.NewParser(contentB)
cB, _ := pB.Parse()
idx.AddFile(fileB, cB)
if check() {
t.Error("Step 1: Expected warning to be suppressed")
}
// 2. Update A (remove pragma)
pA2 := parser.NewParser(contentA_NoPragma)
cA2, _ := pA2.Parse()
idx.AddFile(fileA, cA2)
if !check() {
t.Error("Step 2: Expected warning to appear")
}
// 3. Update A (add pragma back)
idx.AddFile(fileA, cA) // Re-use config A
if check() {
t.Error("Step 3: Expected warning to be suppressed again")
}
}

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 TestIgnorePragma(t *testing.T) {
content := `
//!ignore(unused): Suppress global unused
+Data = {
Class = ReferenceContainer
+MyDS = {
Class = FileReader
Filename = "test"
Signals = {
Unused1 = { Type = uint32 }
//!ignore(unused): Suppress local unused
Unused2 = { Type = uint32 }
}
}
}
+MyGAM = {
Class = IOGAM
InputSignals = {
//!ignore(implicit): Suppress local implicit
ImplicitSig = { 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("ignore.marte", config)
idx.ResolveReferences()
v := validator.NewValidator(idx, ".")
v.ValidateProject()
v.CheckUnused()
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Unused Signal") {
t.Errorf("Unexpected warning: %s", d.Message)
}
if strings.Contains(d.Message, "Implicitly Defined Signal") {
t.Errorf("Unexpected warning: %s", d.Message)
}
}
}