Initial support to variables and to producer/consumer logic
This commit is contained in:
45
test/formatter_variables_test.go
Normal file
45
test/formatter_variables_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/marte-community/marte-dev-tools/internal/formatter"
|
||||
"github.com/marte-community/marte-dev-tools/internal/parser"
|
||||
)
|
||||
|
||||
func TestFormatterVariables(t *testing.T) {
|
||||
content := `
|
||||
#var MyInt: int = 10
|
||||
#var MyStr: string | "A" = "default"
|
||||
|
||||
+Obj = {
|
||||
Field1 = $MyInt
|
||||
Field2 = $MyStr
|
||||
}
|
||||
`
|
||||
p := parser.NewParser(content)
|
||||
cfg, err := p.Parse()
|
||||
if err != nil {
|
||||
t.Fatalf("Parse failed: %v", err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
formatter.Format(cfg, &buf)
|
||||
|
||||
output := buf.String()
|
||||
|
||||
// Parser reconstructs type expression with spaces
|
||||
if !strings.Contains(output, "#var MyInt: int = 10") {
|
||||
t.Errorf("Variable MyInt formatted incorrectly. Got:\n%s", output)
|
||||
}
|
||||
// Note: parser adds space after each token in TypeExpr
|
||||
// string | "A" -> "string | \"A\""
|
||||
if !strings.Contains(output, "#var MyStr: string | \"A\" = \"default\"") {
|
||||
t.Errorf("Variable MyStr formatted incorrectly. Got:\n%s", output)
|
||||
}
|
||||
if !strings.Contains(output, "Field1 = $MyInt") {
|
||||
t.Errorf("Variable reference $MyInt formatted incorrectly. Got:\n%s", output)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user