(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestCFileGenerator_Generate(t *testing.T) { |
| 13 | tmpDir := t.TempDir() |
| 14 | |
| 15 | generator := &Generator{ |
| 16 | BaseName: "test_extension", |
| 17 | BuildDir: tmpDir, |
| 18 | Functions: []phpFunction{ |
| 19 | { |
| 20 | Name: "simpleFunction", |
| 21 | ReturnType: phpString, |
| 22 | Params: []phpParameter{ |
| 23 | {Name: "input", PhpType: phpString}, |
| 24 | }, |
| 25 | }, |
| 26 | { |
| 27 | Name: "complexFunction", |
| 28 | ReturnType: phpArray, |
| 29 | Params: []phpParameter{ |
| 30 | {Name: "data", PhpType: phpString}, |
| 31 | {Name: "count", PhpType: phpInt, IsNullable: true}, |
| 32 | {Name: "options", PhpType: phpArray, HasDefault: true, DefaultValue: "[]"}, |
| 33 | }, |
| 34 | }, |
| 35 | }, |
| 36 | Classes: []phpClass{ |
| 37 | { |
| 38 | Name: "TestClass", |
| 39 | GoStruct: "TestStruct", |
| 40 | Properties: []phpClassProperty{ |
| 41 | {Name: "id", PhpType: phpInt}, |
| 42 | {Name: "name", PhpType: phpString}, |
| 43 | }, |
| 44 | }, |
| 45 | }, |
| 46 | } |
| 47 | |
| 48 | cGen := cFileGenerator{generator} |
| 49 | require.NoError(t, cGen.generate()) |
| 50 | |
| 51 | expectedFile := filepath.Join(tmpDir, "test_extension.c") |
| 52 | require.FileExists(t, expectedFile, "Expected C file was not created: %s", expectedFile) |
| 53 | |
| 54 | content, err := readFile(expectedFile) |
| 55 | require.NoError(t, err) |
| 56 | |
| 57 | testCFileBasicStructure(t, content, "test_extension") |
| 58 | testCFileFunctions(t, content, generator.Functions) |
| 59 | testCFileClasses(t, content, generator.Classes) |
| 60 | } |
| 61 | |
| 62 | func TestCFileGenerator_BuildContent(t *testing.T) { |
| 63 | tests := []struct { |
nothing calls this directly
no test coverage detected