()
| 571 | } |
| 572 | |
| 573 | func 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 | |
| 600 | type patcher struct{} |
| 601 |
nothing calls this directly
no test coverage detected
searching dependent graphs…