(t *testing.T)
| 782 | } |
| 783 | |
| 784 | func TestFunctionDeclExcludeOverloads(t *testing.T) { |
| 785 | funcs := []*decls.FunctionDecl{} |
| 786 | for _, fn := range stdlib.Functions() { |
| 787 | if fn.Name() == operators.Add { |
| 788 | fn = fn.Subset(ExcludeOverloads(overloads.AddList, overloads.AddBytes, overloads.AddString)) |
| 789 | } |
| 790 | funcs = append(funcs, fn) |
| 791 | } |
| 792 | env, err := NewCustomEnv(FunctionDecls(funcs...)) |
| 793 | if err != nil { |
| 794 | t.Fatalf("NewCustomEnv() failed: %v", err) |
| 795 | } |
| 796 | |
| 797 | successTests := []struct { |
| 798 | name string |
| 799 | expr string |
| 800 | want ref.Val |
| 801 | }{ |
| 802 | { |
| 803 | name: "ints", |
| 804 | expr: "1 + 1", |
| 805 | want: types.Int(2), |
| 806 | }, |
| 807 | { |
| 808 | name: "doubles", |
| 809 | expr: "1.5 + 1.5", |
| 810 | want: types.Double(3.0), |
| 811 | }, |
| 812 | { |
| 813 | name: "uints", |
| 814 | expr: "1u + 2u", |
| 815 | want: types.Uint(3), |
| 816 | }, |
| 817 | { |
| 818 | name: "timestamp plus duration", |
| 819 | expr: "timestamp('2001-01-01T00:00:00Z') + duration('1h') == timestamp('2001-01-01T01:00:00Z')", |
| 820 | want: types.True, |
| 821 | }, |
| 822 | { |
| 823 | name: "durations", |
| 824 | expr: "duration('1h') + duration('1m') == duration('1h1m')", |
| 825 | want: types.True, |
| 826 | }, |
| 827 | } |
| 828 | for _, tst := range successTests { |
| 829 | tc := tst |
| 830 | t.Run(tc.name, func(t *testing.T) { |
| 831 | ast, iss := env.Compile(tc.expr) |
| 832 | if iss.Err() != nil { |
| 833 | t.Fatalf("env.Compile() failed: %v", iss.Err()) |
| 834 | } |
| 835 | prg, err := env.Program(ast) |
| 836 | if err != nil { |
| 837 | t.Fatalf("env.Program() failed: %v", err) |
| 838 | } |
| 839 | out, _, err := prg.Eval(NoVars()) |
| 840 | if err != nil { |
| 841 | t.Fatalf("prg.Eval() errored: %v", err) |
nothing calls this directly
no test coverage detected