-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlazy_test.go
More file actions
50 lines (44 loc) · 1.17 KB
/
lazy_test.go
File metadata and controls
50 lines (44 loc) · 1.17 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
42
43
44
45
46
47
48
49
50
// Copyright 2025 The zb Authors
// SPDX-License-Identifier: MIT
package frontend
import (
"testing"
"github.com/google/go-cmp/cmp"
"zb.256lights.llc/pkg/internal/backendtest"
"zb.256lights.llc/pkg/internal/testcontext"
"zb.256lights.llc/pkg/internal/zbstorerpc"
)
func TestLazy(t *testing.T) {
ctx := testcontext.New(t)
storeDir := backendtest.NewStoreDirectory(t)
di := new(zbstorerpc.DeferredImporter)
_, store, err := backendtest.NewServer(ctx, t, storeDir, &backendtest.Options{
TempDir: t.TempDir(),
ClientOptions: zbstorerpc.CodecOptions{
Importer: di,
},
})
if err != nil {
t.Fatal(err)
}
eval, err := NewEval(&Options{
Store: newTestRPCStore(store, di),
StoreDirectory: storeDir,
})
if err != nil {
t.Fatal(err)
}
defer func() {
if err := eval.Close(); err != nil {
t.Error("eval.Close:", err)
}
}()
expr := `lazy(function(fib, i) if math.type(i) ~= "integer" or i < 3 then return nil end; return fib[i-2] + fib[i-1]; end, {0, 1})[10]`
got, err := eval.Expression(ctx, expr)
if err != nil {
t.Fatalf("%s: %v", expr, err)
}
if diff := cmp.Diff(int64(34), got); diff != "" {
t.Errorf("%s (-want +got):\n%s", expr, diff)
}
}