(t *testing.T)
| 176 | } |
| 177 | |
| 178 | func TestFunctionZeroArityBinding(t *testing.T) { |
| 179 | now := types.DefaultTypeAdapter.NativeToValue(time.UnixMilli(1000)) |
| 180 | nowFunc, err := NewFunction("now", |
| 181 | Overload("now", []*types.Type{}, types.TimestampType, |
| 182 | FunctionBinding(func(args ...ref.Val) ref.Val { |
| 183 | return now |
| 184 | })), |
| 185 | ) |
| 186 | if err != nil { |
| 187 | t.Fatalf("NewFunction() failed: %v", err) |
| 188 | } |
| 189 | for _, od := range nowFunc.OverloadDecls() { |
| 190 | if !od.HasBinding() { |
| 191 | t.Errorf("Overload %s does not have binding, wanted function binding", od.ID()) |
| 192 | } |
| 193 | } |
| 194 | bindings, err := nowFunc.Bindings() |
| 195 | if err != nil { |
| 196 | t.Fatalf("nowFunc.Bindings() produced an err: %v", err) |
| 197 | } |
| 198 | if len(bindings) != 1 { |
| 199 | t.Errorf("nowFunc.Bindings() produced %d bindings, wanted one", len(bindings)) |
| 200 | } |
| 201 | out := bindings[0].Function() |
| 202 | if out != now { |
| 203 | t.Errorf("now() got %v, wanted %v", out, now) |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | func TestFunctionSingletonBinding(t *testing.T) { |
| 208 | size, err := NewFunction("size", |
nothing calls this directly
no test coverage detected