(t *testing.T)
| 3992 | } |
| 3993 | |
| 3994 | func TestTranspile_ArrayUpperInRangeFunction(t *testing.T) { |
| 3995 | // Test that array_upper inside a FROM-clause function (RangeFunction) is properly |
| 3996 | // transformed to len() with the dimension argument stripped. This is the exact |
| 3997 | // pattern used by the pgx driver for type resolution. |
| 3998 | tr := New(DefaultConfig()) |
| 3999 | |
| 4000 | tests := []struct { |
| 4001 | name string |
| 4002 | input string |
| 4003 | contains string |
| 4004 | excludes string |
| 4005 | }{ |
| 4006 | { |
| 4007 | name: "array_upper in generate_series FROM clause", |
| 4008 | input: "SELECT s.r FROM generate_series(1, array_upper(current_schemas(false), 1)) AS s(r)", |
| 4009 | contains: "len(current_schemas(false))", |
| 4010 | excludes: "array_upper", |
| 4011 | }, |
| 4012 | { |
| 4013 | name: "array_upper in SELECT expression", |
| 4014 | input: "SELECT array_upper(ARRAY[1,2,3], 1)", |
| 4015 | contains: "len(ARRAY[1, 2, 3])", |
| 4016 | excludes: "array_upper", |
| 4017 | }, |
| 4018 | { |
| 4019 | name: "array_length dimension arg stripped", |
| 4020 | input: "SELECT array_length(ARRAY[1,2,3], 1)", |
| 4021 | contains: "len(ARRAY[1, 2, 3])", |
| 4022 | excludes: "array_length", |
| 4023 | }, |
| 4024 | } |
| 4025 | |
| 4026 | for _, tt := range tests { |
| 4027 | t.Run(tt.name, func(t *testing.T) { |
| 4028 | result, err := tr.Transpile(tt.input) |
| 4029 | if err != nil { |
| 4030 | t.Fatalf("Transpile(%q) error: %v", tt.input, err) |
| 4031 | } |
| 4032 | if tt.contains != "" && !strings.Contains(result.SQL, tt.contains) { |
| 4033 | t.Errorf("Transpile(%q) = %q, should contain %q", tt.input, result.SQL, tt.contains) |
| 4034 | } |
| 4035 | if tt.excludes != "" && strings.Contains(result.SQL, tt.excludes) { |
| 4036 | t.Errorf("Transpile(%q) = %q, should NOT contain %q", tt.input, result.SQL, tt.excludes) |
| 4037 | } |
| 4038 | }) |
| 4039 | } |
| 4040 | } |
| 4041 | |
| 4042 | func TestTranspile_CtidToRowid(t *testing.T) { |
| 4043 | tests := []struct { |
nothing calls this directly
no test coverage detected