Implementing pragmas

This commit is contained in:
Martino Ferrari
2026-01-22 02:51:36 +01:00
parent 8fe319de2d
commit b2e963fc04
8 changed files with 287 additions and 14 deletions

View File

@@ -0,0 +1,73 @@
package integration
import (
"testing"
"github.com/marte-dev/marte-dev-tools/internal/index"
"github.com/marte-dev/marte-dev-tools/internal/parser"
)
func TestGetNodeContaining(t *testing.T) {
content := `
+App = {
Class = RealTimeApplication
+State1 = {
Class = RealTimeState
+Thread1 = {
Class = RealTimeThread
Functions = { GAM1 }
}
}
}
+GAM1 = { Class = IOGAM }
`
p := parser.NewParser(content)
config, err := p.Parse()
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
idx := index.NewProjectTree()
file := "hover_context.marte"
idx.AddFile(file, config)
idx.ResolveReferences()
// Find reference to GAM1
var gamRef *index.Reference
for i := range idx.References {
ref := &idx.References[i]
if ref.Name == "GAM1" {
gamRef = ref
break
}
}
if gamRef == nil {
t.Fatal("Reference to GAM1 not found")
}
// Check containing node
container := idx.GetNodeContaining(file, gamRef.Position)
if container == nil {
t.Fatal("Container not found")
}
if container.RealName != "+Thread1" {
t.Errorf("Expected container +Thread1, got %s", container.RealName)
}
// Check traversal up to State
curr := container
foundState := false
for curr != nil {
if curr.RealName == "+State1" {
foundState = true
break
}
curr = curr.Parent
}
if !foundState {
t.Error("State parent not found")
}
}

View File

@@ -0,0 +1,67 @@
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 TestGlobalPragma(t *testing.T) {
content := `
//!allow(unused): Suppress all unused
//!allow(implicit): Suppress all implicit
+Data = {
Class = ReferenceContainer
+MyDS = {
Class = FileReader
Filename = "test"
Signals = {
UnusedSig = { Type = uint32 }
}
}
}
+MyGAM = {
Class = IOGAM
InputSignals = {
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("global_pragma.marte", config)
idx.ResolveReferences()
v := validator.NewValidator(idx, ".")
v.ValidateProject()
v.CheckUnused()
foundUnusedWarning := false
foundImplicitWarning := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Unused Signal") {
foundUnusedWarning = true
}
if strings.Contains(d.Message, "Implicitly Defined Signal") {
foundImplicitWarning = true
}
}
if foundUnusedWarning {
t.Error("Expected warning for UnusedSig to be suppressed globally")
}
if foundImplicitWarning {
t.Error("Expected warning for ImplicitSig to be suppressed globally")
}
}