-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpressionLanguageScenario_test.go
More file actions
executable file
·41 lines (36 loc) · 1.39 KB
/
ExpressionLanguageScenario_test.go
File metadata and controls
executable file
·41 lines (36 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"github.com/weaweawe01/ParserSpel/ast"
"strings"
"testing"
)
// Lightweight parser/AST tests inspired by ExpressionLanguageScenarioTests.java.
// These tests focus on parsing and AST string outputs using existing Go APIs.
func TestBasicParsingAndAST(t *testing.T) {
parser := ast.NewSpelExpressionParser()
// Simple literal parsing
expr, err := parser.ParseExpressionWithContext("'hello world'", nil)
if err != nil {
t.Fatalf("failed to parse literal expression: %v", err)
}
// Ensure AST contains the literal content
if !strings.Contains(expr.ToStringAST(), "hello world") {
t.Fatalf("AST should contain literal 'hello world', got: %s", expr.ToStringAST())
}
// Variable reference parsing (we only test parsing, not evaluation wiring)
expr, err = parser.ParseExpressionWithContext("#favouriteColour", nil)
if err != nil {
t.Fatalf("failed to parse variable reference: %v", err)
}
if !strings.Contains(expr.ToStringAST(), "#favouriteColour") {
t.Fatalf("AST should contain variable reference '#favouriteColour', got: %s", expr.ToStringAST())
}
// List access parsing - just ensure parse succeeds
expr, err = parser.ParseExpressionWithContext("{2,3,5,7}.get(1)", nil)
if err != nil {
t.Fatalf("failed to parse list access: %v", err)
}
if !strings.Contains(expr.ToStringAST(), "get(1)") {
t.Fatalf("AST should contain get(1), got: %s", expr.ToStringAST())
}
}