aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/azalea/evaluate_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-05-17 23:44:00 +0900
committerOphestra <cat@gensokyo.uk>2026-05-17 23:49:19 +0900
commitf24ae21af111e0ce34f62a37ddb4a9fc18166ae6 (patch)
treeaf7325047441c592bbdfeccf17753eea82d8ee6e /internal/rosa/azalea/evaluate_test.go
parent99b324fb174fbbf069bf0db39ee280590aad1f4f (diff)
internal/rosa/azalea: package special case
This is more efficient for the inputs array and packages in general. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/rosa/azalea/evaluate_test.go')
-rw-r--r--internal/rosa/azalea/evaluate_test.go128
1 files changed, 61 insertions, 67 deletions
diff --git a/internal/rosa/azalea/evaluate_test.go b/internal/rosa/azalea/evaluate_test.go
index 9036e782..aa7de27e 100644
--- a/internal/rosa/azalea/evaluate_test.go
+++ b/internal/rosa/azalea/evaluate_test.go
@@ -16,14 +16,10 @@ import (
func makeStackCheck(check func(args FArgs) (any, error)) []Frame {
return []Frame{{Func: map[unique.Handle[Ident]]F{
unique.Make(Ident("f")): {F: func(
- isPackage bool,
args FArgs,
) (v any, set bool, err error) {
set = true
v, err = check(args)
- if isPackage {
- err = errors.New("unexpected package")
- }
return
}},
}}}
@@ -101,6 +97,45 @@ func TestEvaluate(t *testing.T) {
Expr: Ident("nil"),
Err: UndefinedError("nil"),
}},
+
+ {"common inputs", `package name { inputs, v = []; }`, nil, "", EvaluationError{
+ Expr: Func{
+ Ident: Ident("name"),
+ Package: true,
+
+ Args: []Arg{
+ {K: []Ident{
+ "inputs",
+ "v",
+ }, V: Val{Array(nil)}},
+ },
+ },
+ Err: ErrInvalidInputs,
+ }},
+
+ {"bound inputs", `package name { inputs* = []; }`, nil, "", EvaluationError{
+ Expr: Func{
+ Ident: Ident("name"),
+ Package: true,
+
+ Args: []Arg{
+ {K: []Ident{"inputs"}, V: Val{Array(nil)}, R: true},
+ },
+ },
+ Err: ErrInvalidInputs,
+ }},
+
+ {"concat inputs", `package name { inputs = ""+""; }`, nil, "", EvaluationError{
+ Expr: Func{
+ Ident: Ident("name"),
+ Package: true,
+
+ Args: []Arg{
+ {K: []Ident{"inputs"}, V: Val{String(""), String("")}},
+ },
+ },
+ Err: ErrInvalidInputs,
+ }},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
@@ -114,7 +149,7 @@ func TestEvaluate(t *testing.T) {
} else {
expr = e[0].(Func)
}
- r, set, err := Evaluate[string](tc.s, expr)
+ r, set, err := Evaluate[string](nil, tc.s, expr)
if set != (err == nil) {
t.Error("Evaluate: unexpected unset")
}
@@ -147,36 +182,19 @@ func TestEvaluateGCC(t *testing.T) {
}
var got [3]FArgs
- if r, set, err := Evaluate[string]([]Frame{{
+ if r, set, err := Evaluate[string](func(
+ name Ident,
+ args FArgs,
+ ) (v any, set bool, err error) {
+ v = "\x00"
+ set = true
+ got[0] = args
+ return
+ }, []Frame{{
Func: map[unique.Handle[Ident]]F{
- unique.Make(Ident("gcc")): {F: func(
- isPackage bool,
- args FArgs,
- ) (v any, set bool, err error) {
- v = "\x00"
- if !isPackage {
- err = errors.New("not a package")
- }
- set = true
- got[0] = args
- return
- }, V: map[unique.Handle[Ident]]any{
- unique.Make(Ident("binutils")): "binutils",
- unique.Make(Ident("mpc")): "mpc",
- unique.Make(Ident("zlib")): "zlib",
- unique.Make(Ident("libucontext")): "libucontext",
- unique.Make(Ident("kernel-headers")): "kernel-headers",
- }},
-
unique.Make(Ident("remoteTar")): {F: func(
- isPackage bool,
args FArgs,
) (v any, set bool, err error) {
- if isPackage {
- err = errors.New("unexpected package")
- return
- }
-
var url, checksum string
var compress int
if err = args.Apply(map[unique.Handle[Ident]]any{
@@ -198,37 +216,25 @@ func TestEvaluateGCC(t *testing.T) {
}},
unique.Make(Ident("make")): {F: func(
- isPackage bool,
args FArgs,
) (v any, set bool, err error) {
v = args
- if isPackage {
- err = errors.New("unexpected package")
- }
set = true
return
}},
unique.Make(Ident("arch")): {F: func(
- isPackage bool,
args FArgs,
) (v any, set bool, err error) {
set = false
- if isPackage {
- err = errors.New("unexpected package")
- }
got[1] = args
return
}},
unique.Make(Ident("noop")): {F: func(
- isPackage bool,
args FArgs,
) (v any, set bool, err error) {
set = false
- if isPackage {
- err = errors.New("unexpected package")
- }
set = true
got[2] = args
return
@@ -274,12 +280,12 @@ func TestEvaluateGCC(t *testing.T) {
{K: unique.Make(Ident("skip-check")), V: true},
}},
- {K: unique.Make(Ident("inputs")), V: []string{
- "binutils",
- "mpc",
- "zlib",
- "libucontext",
- "kernel-headers",
+ {K: unique.Make(Ident("inputs")), V: Array{
+ {Ident("binutils")},
+ {Ident("mpc")},
+ {Ident("zlib")},
+ {Ident("libucontext")},
+ {Ident("kernel-headers")},
}},
},
{
@@ -304,21 +310,7 @@ func BenchmarkEvaluate(b *testing.B) {
s := []Frame{{
Func: map[unique.Handle[Ident]]F{
- unique.Make(Ident("gcc")): {F: func(
- bool,
- FArgs,
- ) (v any, set bool, err error) {
- return
- }, V: map[unique.Handle[Ident]]any{
- unique.Make(Ident("binutils")): "binutils",
- unique.Make(Ident("mpc")): "mpc",
- unique.Make(Ident("zlib")): "zlib",
- unique.Make(Ident("libucontext")): "libucontext",
- unique.Make(Ident("kernel-headers")): "kernel-headers",
- }},
-
unique.Make(Ident("remoteTar")): {F: func(
- bool,
FArgs,
) (v any, set bool, err error) {
return
@@ -327,21 +319,18 @@ func BenchmarkEvaluate(b *testing.B) {
}},
unique.Make(Ident("make")): {F: func(
- bool,
FArgs,
) (v any, set bool, err error) {
return
}},
unique.Make(Ident("arch")): {F: func(
- bool,
FArgs,
) (v any, set bool, err error) {
return
}},
unique.Make(Ident("noop")): {F: func(
- bool,
FArgs,
) (v any, set bool, err error) {
return
@@ -351,7 +340,12 @@ func BenchmarkEvaluate(b *testing.B) {
},
}}
for b.Loop() {
- if _, _, err := Evaluate[string](s, gcc); err != nil {
+ if _, _, err := Evaluate[string](func(
+ Ident,
+ FArgs,
+ ) (v any, set bool, err error) {
+ return
+ }, s, gcc); err != nil {
b.Fatal(err)
}
}