MCPcopy
hub / github.com/expr-lang/expr / TestMemoryBudget

Function TestMemoryBudget

expr_test.go:2867–2891  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2865}
2866
2867func TestMemoryBudget(t *testing.T) {
2868 tests := []struct {
2869 code string
2870 max int
2871 }{
2872 {`map(1..100, {map(1..100, {map(1..100, {0})})})`, -1},
2873 {`len(1..10000000)`, -1},
2874 {`1..100`, 100},
2875 }
2876
2877 for _, tt := range tests {
2878 t.Run(tt.code, func(t *testing.T) {
2879 program, err := expr.Compile(tt.code)
2880 require.NoError(t, err, "compile error")
2881
2882 vm := vm.VM{}
2883 if tt.max > 0 {
2884 vm.MemoryBudget = uint(tt.max)
2885 }
2886 _, err = vm.Run(program, nil)
2887 require.Error(t, err, "run error")
2888 assert.Contains(t, err.Error(), "memory budget exceeded")
2889 })
2890 }
2891}
2892
2893func TestIssue802(t *testing.T) {
2894 prog, err := expr.Compile(`arr[1:2][0]`)

Callers

nothing calls this directly

Calls 6

RunMethod · 0.95
CompileFunction · 0.92
NoErrorFunction · 0.92
ErrorFunction · 0.92
ContainsFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…