Test WindowSpec node
(t *testing.T)
| 329 | |
| 330 | // Test WindowSpec node |
| 331 | func TestWindowSpec(t *testing.T) { |
| 332 | tests := []struct { |
| 333 | name string |
| 334 | windowSpec *WindowSpec |
| 335 | wantLiteral string |
| 336 | wantChildren int |
| 337 | }{ |
| 338 | { |
| 339 | name: "simple window spec", |
| 340 | windowSpec: &WindowSpec{ |
| 341 | Name: "w", |
| 342 | }, |
| 343 | wantLiteral: "WINDOW", |
| 344 | wantChildren: 0, |
| 345 | }, |
| 346 | { |
| 347 | name: "with PARTITION BY", |
| 348 | windowSpec: &WindowSpec{ |
| 349 | Name: "w", |
| 350 | PartitionBy: []Expression{&Identifier{Name: "dept"}}, |
| 351 | }, |
| 352 | wantLiteral: "WINDOW", |
| 353 | wantChildren: 1, |
| 354 | }, |
| 355 | { |
| 356 | name: "with PARTITION BY and ORDER BY", |
| 357 | windowSpec: &WindowSpec{ |
| 358 | Name: "w", |
| 359 | PartitionBy: []Expression{&Identifier{Name: "dept"}}, |
| 360 | OrderBy: []OrderByExpression{{Expression: &Identifier{Name: "salary"}, Ascending: true}}, |
| 361 | }, |
| 362 | wantLiteral: "WINDOW", |
| 363 | wantChildren: 2, |
| 364 | }, |
| 365 | { |
| 366 | name: "with frame clause", |
| 367 | windowSpec: &WindowSpec{ |
| 368 | Name: "w", |
| 369 | FrameClause: &WindowFrame{ |
| 370 | Type: "ROWS", |
| 371 | Start: WindowFrameBound{Type: "CURRENT ROW"}, |
| 372 | }, |
| 373 | }, |
| 374 | wantLiteral: "WINDOW", |
| 375 | wantChildren: 1, |
| 376 | }, |
| 377 | } |
| 378 | |
| 379 | for _, tt := range tests { |
| 380 | tt := tt // G601: Create local copy to avoid memory aliasing |
| 381 | t.Run(tt.name, func(t *testing.T) { |
| 382 | // Test TokenLiteral |
| 383 | if got := tt.windowSpec.TokenLiteral(); got != tt.wantLiteral { |
| 384 | t.Errorf("WindowSpec.TokenLiteral() = %v, want %v", got, tt.wantLiteral) |
| 385 | } |
| 386 | |
| 387 | // Test Children |
| 388 | children := tt.windowSpec.Children() |
nothing calls this directly
no test coverage detected