Skip to content

Commit 96bace4

Browse files
chore: add regression test for issue 823 (#867)
Fixed in #824 Signed-off-by: Ville Vesilehto <ville@vesilehto.fi> Co-authored-by: Anton Medvedev <anton@medv.io>
1 parent cf589a4 commit 96bace4

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/issues/823/issue_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package issue_test
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"testing"
7+
"time"
8+
9+
"github.com/expr-lang/expr"
10+
"github.com/expr-lang/expr/internal/testify/require"
11+
)
12+
13+
type env struct {
14+
Ctx context.Context `expr:"ctx"`
15+
}
16+
17+
func TestIssue823(t *testing.T) {
18+
p, err := expr.Compile(
19+
"now2().After(date2())",
20+
expr.Env(env{}),
21+
expr.WithContext("ctx"),
22+
expr.Function(
23+
"now2",
24+
func(params ...any) (any, error) { return time.Now(), nil },
25+
new(func(context.Context) time.Time),
26+
),
27+
expr.Function(
28+
"date2",
29+
func(params ...any) (any, error) { return time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), nil },
30+
new(func(context.Context) time.Time),
31+
),
32+
)
33+
fmt.Printf("Compile result err: %v\n", err)
34+
require.NoError(t, err)
35+
36+
r, err := expr.Run(p, &env{Ctx: context.Background()})
37+
require.NoError(t, err)
38+
require.True(t, r.(bool))
39+
}

0 commit comments

Comments
 (0)