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

Function ExampleAllowUndefinedVariables_zero_value_functions

expr_test.go:573–598  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

571}
572
573func ExampleAllowUndefinedVariables_zero_value_functions() {
574 code := `words == "" ? Split("foo,bar", ",") : Split(words, ",")`
575
576 // Env is map[string]string type on which methods are defined.
577 env := mock.MapStringStringEnv{}
578
579 options := []expr.Option{
580 expr.Env(env),
581 expr.AllowUndefinedVariables(), // Allow to use undefined variables.
582 }
583
584 program, err := expr.Compile(code, options...)
585 if err != nil {
586 fmt.Printf("%v", err)
587 return
588 }
589
590 output, err := expr.Run(program, env)
591 if err != nil {
592 fmt.Printf("%v", err)
593 return
594 }
595 fmt.Printf("%v", output)
596
597 // Output: [foo bar]
598}
599
600type patcher struct{}
601

Callers

nothing calls this directly

Calls 5

EnvStruct · 0.92
AllowUndefinedVariablesFunction · 0.92
CompileFunction · 0.92
RunFunction · 0.92
PrintfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…