Skip to content

Commit 2ba671e

Browse files
committed
Add more tests and comments
1 parent 0d1e620 commit 2ba671e

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

conf/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
)
1212

1313
var (
14-
// DefaultMemoryBudget represents an upper limit of memory usage
14+
// DefaultMemoryBudget represents default maximum allowed memory usage by the vm.VM.
1515
DefaultMemoryBudget uint = 1e6
1616

17-
// DefaultMaxNodes represents an upper limit of AST nodes
17+
// DefaultMaxNodes represents default maximum allowed AST nodes by the compiler.
1818
DefaultMaxNodes uint = 1e4
1919
)
2020

expr.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func Timezone(name string) Option {
197197

198198
// MaxNodes sets the maximum number of nodes allowed in the expression.
199199
// By default, the maximum number of nodes is conf.DefaultMaxNodes.
200+
// If MaxNodes is set to 0, the node budget check is disabled.
200201
func MaxNodes(n uint) Option {
201202
return func(c *conf.Config) {
202203
c.MaxNodes = n

expr_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13+
"github.com/expr-lang/expr/conf"
1314
"github.com/expr-lang/expr/internal/testify/assert"
1415
"github.com/expr-lang/expr/internal/testify/require"
1516
"github.com/expr-lang/expr/types"
@@ -2729,6 +2730,16 @@ func TestMaxNodes(t *testing.T) {
27292730
require.NoError(t, err)
27302731
}
27312732

2733+
func TestMaxNodesDisabled(t *testing.T) {
2734+
code := ""
2735+
for i := 0; i < 2*int(conf.DefaultMaxNodes); i++ {
2736+
code += "1; "
2737+
}
2738+
2739+
_, err := expr.Compile(code, expr.MaxNodes(0))
2740+
require.NoError(t, err)
2741+
}
2742+
27322743
func TestMemoryBudget(t *testing.T) {
27332744
tests := []struct {
27342745
code string

0 commit comments

Comments
 (0)