(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestGoFileGenerator_Generate(t *testing.T) { |
| 16 | tmpDir := t.TempDir() |
| 17 | |
| 18 | sourceContent := `package main |
| 19 | |
| 20 | import ( |
| 21 | "fmt" |
| 22 | "strings" |
| 23 | "github.com/dunglas/frankenphp/internal/extensions/types" |
| 24 | ) |
| 25 | |
| 26 | //export_php: greet(name string): string |
| 27 | func greet(name *go_string) *go_value { |
| 28 | return types.String("Hello " + CStringToGoString(name)) |
| 29 | } |
| 30 | |
| 31 | //export_php: calculate(a int, b int): int |
| 32 | func calculate(a long, b long) *go_value { |
| 33 | result := a + b |
| 34 | return types.Int(result) |
| 35 | } |
| 36 | |
| 37 | func internalHelper(data string) string { |
| 38 | return strings.ToUpper(data) |
| 39 | } |
| 40 | |
| 41 | func anotherHelper() { |
| 42 | fmt.Println("Internal helper") |
| 43 | }` |
| 44 | |
| 45 | sourceFile := filepath.Join(tmpDir, "test.go") |
| 46 | require.NoError(t, os.WriteFile(sourceFile, []byte(sourceContent), 0644)) |
| 47 | |
| 48 | generator := &Generator{ |
| 49 | BaseName: "test", |
| 50 | SourceFile: sourceFile, |
| 51 | BuildDir: tmpDir, |
| 52 | Functions: []phpFunction{ |
| 53 | { |
| 54 | Name: "greet", |
| 55 | ReturnType: phpString, |
| 56 | GoFunction: `func greet(name *go_string) *go_value { |
| 57 | return types.String("Hello " + CStringToGoString(name)) |
| 58 | }`, |
| 59 | }, |
| 60 | { |
| 61 | Name: "calculate", |
| 62 | ReturnType: phpInt, |
| 63 | GoFunction: `func calculate(a long, b long) *go_value { |
| 64 | result := a + b |
| 65 | return types.Int(result) |
| 66 | }`, |
| 67 | }, |
| 68 | }, |
| 69 | } |
| 70 | |
| 71 | goGen := GoFileGenerator{generator} |
| 72 | require.NoError(t, goGen.generate()) |
nothing calls this directly
no test coverage detected