diff options
Diffstat (limited to 'internal/rosa/azalea/evaluate_test.go')
| -rw-r--r-- | internal/rosa/azalea/evaluate_test.go | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/internal/rosa/azalea/evaluate_test.go b/internal/rosa/azalea/evaluate_test.go index 26c4e668..b4fa4802 100644 --- a/internal/rosa/azalea/evaluate_test.go +++ b/internal/rosa/azalea/evaluate_test.go @@ -32,7 +32,7 @@ func TestEvaluate(t *testing.T) { name string data string s []Frame - want string + want any err error }{ {"apply unset", `f { v = unset; }`, makeStackCheck(func( @@ -110,7 +110,7 @@ func TestEvaluate(t *testing.T) { }, V: Val{Array(nil)}}, }, }, - Err: ErrInvalidInputs, + Err: ErrInvalidSpecial, }}, {"bound inputs", `package name { inputs* = []; }`, nil, "", EvaluationError{ @@ -122,7 +122,7 @@ func TestEvaluate(t *testing.T) { {K: []Ident{"inputs"}, V: Val{Array(nil)}, R: true}, }, }, - Err: ErrInvalidInputs, + Err: ErrInvalidSpecial, }}, {"bound runtime", `package name { runtime* = []; }`, nil, "", EvaluationError{ @@ -134,7 +134,7 @@ func TestEvaluate(t *testing.T) { {K: []Ident{"runtime"}, V: Val{Array(nil)}, R: true}, }, }, - Err: ErrInvalidInputs, + Err: ErrInvalidSpecial, }}, {"concat inputs", `package name { inputs = ""+""; }`, nil, "", EvaluationError{ @@ -146,8 +146,24 @@ func TestEvaluate(t *testing.T) { {K: []Ident{"inputs"}, V: Val{String(""), String("")}}, }, }, - Err: ErrInvalidInputs, + Err: ErrInvalidSpecial, }}, + + {"concat source", `package name { source = ""+""; }`, nil, "", EvaluationError{ + Expr: Func{ + Ident: Ident("name"), + Package: true, + + Args: []Arg{ + {K: []Ident{"source"}, V: Val{String(""), String("")}}, + }, + }, + Err: ErrInvalidSpecial, + }}, + + {"source handle", `package name { source = name; }`, nil, FArgs{ + {K: unique.Make(Ident("source")), V: Ident("name")}, + }, nil}, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { @@ -161,12 +177,23 @@ func TestEvaluate(t *testing.T) { } else { expr = e[0].(Func) } - r, set, err := Evaluate[string](nil, tc.s, expr) + const rPackage = "\xff\xff\xff\xff" + r, set, err := Evaluate[string](func( + name Ident, + args FArgs, + ) (v any, set bool, err error) { + v = rPackage + if !reflect.DeepEqual(args, tc.want) { + err = fmt.Errorf("%#v, want %#v", args, tc.want) + } + set = true + return + }, tc.s, expr) if set != (err == nil) { t.Error("Evaluate: unexpected unset") } - if r != tc.want { + if r != rPackage && r != tc.want { t.Errorf("Evaluate: %q, want %q", r, tc.want) } |
