TestLateBoundFunctionSingleActivation covers the requirement that only one activation in a hierarchy supplies late-bound function implementations. Layering them would make the bindings which apply depend on the order of composition, which is reported instead.
(t *testing.T)
| 6729 | // hierarchy supplies late-bound function implementations. Layering them would make the bindings |
| 6730 | // which apply depend on the order of composition, which is reported instead. |
| 6731 | func TestLateBoundFunctionSingleActivation(t *testing.T) { |
| 6732 | env := lateBoundComprehensionEnv(t) |
| 6733 | fnA := map[string]LateBoundFunction{"inc": lateBoundInc} |
| 6734 | fnB := map[string]LateBoundFunction{"inc": lateBoundInc} |
| 6735 | ast, iss := env.Compile("inc(1)") |
| 6736 | if iss.Err() != nil { |
| 6737 | t.Fatalf("Compile() failed: %v", iss.Err()) |
| 6738 | } |
| 6739 | |
| 6740 | t.Run("FunctionVars over FunctionVars", func(t *testing.T) { |
| 6741 | inner, err := FunctionVars(map[string]any{}, fnA) |
| 6742 | if err != nil { |
| 6743 | t.Fatalf("FunctionVars() failed: %v", err) |
| 6744 | } |
| 6745 | if _, err := FunctionVars(inner, fnB); err == nil { |
| 6746 | t.Error("FunctionVars() over existing bindings wanted error, got nil") |
| 6747 | } |
| 6748 | }) |
| 6749 | t.Run("Globals applied twice", func(t *testing.T) { |
| 6750 | defaultsA, err := FunctionVars(map[string]any{}, fnA) |
| 6751 | if err != nil { |
| 6752 | t.Fatalf("FunctionVars() failed: %v", err) |
| 6753 | } |
| 6754 | defaultsB, err := FunctionVars(map[string]any{}, fnB) |
| 6755 | if err != nil { |
| 6756 | t.Fatalf("FunctionVars() failed: %v", err) |
| 6757 | } |
| 6758 | if _, err := env.Program(ast, Globals(defaultsA), Globals(defaultsB)); err == nil { |
| 6759 | t.Error("Program() with two sources of bindings wanted error, got nil") |
| 6760 | } |
| 6761 | }) |
| 6762 | t.Run("Globals and evaluation-time bindings", func(t *testing.T) { |
| 6763 | defaults, err := FunctionVars(map[string]any{}, fnA) |
| 6764 | if err != nil { |
| 6765 | t.Fatalf("FunctionVars() failed: %v", err) |
| 6766 | } |
| 6767 | prg, err := env.Program(ast, Globals(defaults)) |
| 6768 | if err != nil { |
| 6769 | t.Fatalf("Program() failed: %v", err) |
| 6770 | } |
| 6771 | evalVars, err := FunctionVars(map[string]any{}, fnB) |
| 6772 | if err != nil { |
| 6773 | t.Fatalf("FunctionVars() failed: %v", err) |
| 6774 | } |
| 6775 | // The conflict only exists once the two hierarchies are combined, so it is reported by |
| 6776 | // Eval rather than by Program. |
| 6777 | if _, _, err := prg.Eval(evalVars); err == nil { |
| 6778 | t.Error("Eval() with bindings from defaults and input wanted error, got nil") |
| 6779 | } |
| 6780 | }) |
| 6781 | t.Run("Globals alone remains valid", func(t *testing.T) { |
| 6782 | defaults, err := FunctionVars(map[string]any{}, fnA) |
| 6783 | if err != nil { |
| 6784 | t.Fatalf("FunctionVars() failed: %v", err) |
| 6785 | } |
| 6786 | prg, err := env.Program(ast, Globals(defaults)) |
| 6787 | if err != nil { |
| 6788 | t.Fatalf("Program() failed: %v", err) |
nothing calls this directly
no test coverage detected