(t *testing.T)
| 307 | } |
| 308 | |
| 309 | func TestArrayLowerCompatibilityMacro(t *testing.T) { |
| 310 | db, err := sql.Open("duckdb", ":memory:") |
| 311 | if err != nil { |
| 312 | t.Fatalf("Failed to open database: %v", err) |
| 313 | } |
| 314 | defer func() { _ = db.Close() }() |
| 315 | |
| 316 | if err := initPgCatalog(db, processStartTime, processStartTime, "dev", "dev"); err != nil { |
| 317 | t.Fatalf("Failed to init pg_catalog: %v", err) |
| 318 | } |
| 319 | |
| 320 | tests := []struct { |
| 321 | name string |
| 322 | query string |
| 323 | want sql.NullInt64 |
| 324 | }{ |
| 325 | { |
| 326 | name: "one dimensional non-empty array", |
| 327 | query: "SELECT array_lower(ARRAY[1, 2, 3], 1)", |
| 328 | want: sql.NullInt64{Int64: 1, Valid: true}, |
| 329 | }, |
| 330 | { |
| 331 | name: "empty array", |
| 332 | query: "SELECT array_lower(ARRAY[]::INTEGER[], 1)", |
| 333 | want: sql.NullInt64{}, |
| 334 | }, |
| 335 | { |
| 336 | name: "null array", |
| 337 | query: "SELECT array_lower(NULL::INTEGER[], 1)", |
| 338 | want: sql.NullInt64{}, |
| 339 | }, |
| 340 | { |
| 341 | name: "unsupported dimension", |
| 342 | query: "SELECT array_lower(ARRAY[1, 2, 3], 2)", |
| 343 | want: sql.NullInt64{}, |
| 344 | }, |
| 345 | { |
| 346 | name: "null dimension", |
| 347 | query: "SELECT array_lower(ARRAY[1, 2, 3], NULL)", |
| 348 | want: sql.NullInt64{}, |
| 349 | }, |
| 350 | } |
| 351 | |
| 352 | for _, tt := range tests { |
| 353 | t.Run(tt.name, func(t *testing.T) { |
| 354 | var got sql.NullInt64 |
| 355 | if err := db.QueryRow(tt.query).Scan(&got); err != nil { |
| 356 | t.Fatalf("%s failed: %v", tt.query, err) |
| 357 | } |
| 358 | if got.Valid != tt.want.Valid || got.Int64 != tt.want.Int64 { |
| 359 | t.Fatalf("array_lower result = %+v, want %+v", got, tt.want) |
| 360 | } |
| 361 | }) |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | func TestUtilityMacrosWithoutPgCatalog(t *testing.T) { |
| 366 | // Verify that initUtilityMacros works independently of initPgCatalog, |
nothing calls this directly
no test coverage detected