(t *testing.T)
| 888 | } |
| 889 | |
| 890 | func TestReducerCollectToMap(t *testing.T) { |
| 891 | tests := []struct { |
| 892 | name string |
| 893 | rows [][]ast.Constant |
| 894 | }{ |
| 895 | { |
| 896 | name: "simple key-value pairs", |
| 897 | rows: [][]ast.Constant{ |
| 898 | {name("/key1"), ast.Number(1)}, |
| 899 | {name("/key2"), ast.Number(2)}, |
| 900 | {name("/key3"), ast.Number(3)}, |
| 901 | }, |
| 902 | }, |
| 903 | { |
| 904 | name: "duplicate keys (should use first occurrence)", |
| 905 | rows: [][]ast.Constant{ |
| 906 | {name("/key1"), ast.Number(1)}, |
| 907 | {name("/key2"), ast.Number(2)}, |
| 908 | {name("/key1"), ast.Number(10)}, // duplicate key, should be ignored |
| 909 | }, |
| 910 | }, |
| 911 | { |
| 912 | name: "empty input", |
| 913 | rows: [][]ast.Constant{}, |
| 914 | }, |
| 915 | } |
| 916 | |
| 917 | for _, test := range tests { |
| 918 | t.Run(test.name, func(t *testing.T) { |
| 919 | var rows []ast.ConstSubstList |
| 920 | for _, row := range test.rows { |
| 921 | if len(row) > 0 { |
| 922 | rows = append(rows, makeConstSubstList(makeVarList(len(row)), row)) |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | // CollectToMap expects exactly 2 arguments (key variable, value variable) |
| 927 | args := []ast.BaseTerm{ast.Variable{"X0"}, ast.Variable{"X1"}} |
| 928 | expr := ast.ApplyFn{symbols.CollectToMap, args} |
| 929 | got, err := EvalReduceFn(expr, rows) |
| 930 | if err != nil { |
| 931 | t.Fatalf("EvalReduceFn(%v,%v) failed with %v", expr, rows, err) |
| 932 | } |
| 933 | |
| 934 | // Validate that we got a map |
| 935 | if got.Type != ast.MapShape { |
| 936 | t.Errorf("EvalReduceFn(%v,%v) returned %v (type %v), expected map", expr, rows, got, got.Type) |
| 937 | return |
| 938 | } |
| 939 | |
| 940 | // For empty input, expect empty map |
| 941 | if len(test.rows) == 0 { |
| 942 | if !got.IsMapNil() { |
| 943 | t.Errorf("EvalReduceFn with empty input should return empty map, got %v", got) |
| 944 | } |
| 945 | return |
| 946 | } |
| 947 |
nothing calls this directly
no test coverage detected