(t *testing.T)
| 401 | } |
| 402 | |
| 403 | func TestCFileConstants(t *testing.T) { |
| 404 | tests := []struct { |
| 405 | name string |
| 406 | baseName string |
| 407 | constants []phpConstant |
| 408 | classes []phpClass |
| 409 | contains []string |
| 410 | }{ |
| 411 | { |
| 412 | name: "global constants only", |
| 413 | baseName: "const_test", |
| 414 | constants: []phpConstant{ |
| 415 | { |
| 416 | Name: "GLOBAL_INT", |
| 417 | Value: "42", |
| 418 | PhpType: phpInt, |
| 419 | }, |
| 420 | { |
| 421 | Name: "GLOBAL_STRING", |
| 422 | Value: `"test"`, |
| 423 | PhpType: phpString, |
| 424 | }, |
| 425 | }, |
| 426 | contains: []string{ |
| 427 | `REGISTER_LONG_CONSTANT("GLOBAL_INT", 42, CONST_CS | CONST_PERSISTENT);`, |
| 428 | `REGISTER_STRING_CONSTANT("GLOBAL_STRING", "test", CONST_CS | CONST_PERSISTENT);`, |
| 429 | }, |
| 430 | }, |
| 431 | } |
| 432 | |
| 433 | for _, tt := range tests { |
| 434 | t.Run(tt.name, func(t *testing.T) { |
| 435 | generator := &Generator{ |
| 436 | BaseName: tt.baseName, |
| 437 | Constants: tt.constants, |
| 438 | Classes: tt.classes, |
| 439 | } |
| 440 | |
| 441 | cGen := cFileGenerator{generator} |
| 442 | content, err := cGen.buildContent() |
| 443 | require.NoError(t, err) |
| 444 | |
| 445 | for _, expected := range tt.contains { |
| 446 | assert.Contains(t, content, expected, "Generated C content should contain '%s'", expected) |
| 447 | } |
| 448 | }) |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | func TestCFileTemplateErrorHandling(t *testing.T) { |
| 453 | generator := &Generator{ |
nothing calls this directly
no test coverage detected