MCPcopy Index your code
hub / github.com/php/frankenphp / TestFunctionParser

Function TestFunctionParser

internal/extgen/funcparser_test.go:35–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33}
34
35func TestFunctionParser(t *testing.T) {
36 tests := []struct {
37 name string
38 input string
39 expect int
40 assert func(t *testing.T, functions []phpFunction)
41 }{
42 {
43 name: "single function",
44 input: `package main
45
46//export_php:function testFunc(string $name): string
47func testFunc(name *C.zend_string) unsafe.Pointer {
48 return String("Hello " + CStringToGoString(name))
49}`,
50 expect: 1,
51 assert: func(t *testing.T, fns []phpFunction) {
52 fn := fns[0]
53 assert.Equal(t, "testFunc", fn.Name)
54 assert.Equal(t, phpString, fn.ReturnType)
55 require.Len(t, fn.Params, 1)
56 assert.Equal(t, "name", fn.Params[0].Name)
57 },
58 },
59 {
60 name: "multiple functions",
61 input: `package main
62
63//export_php:function func1(int $a): int
64func func1(a int64) int64 {
65 return a * 2
66}
67
68//export_php:function func2(string $b): string
69func func2(b *C.zend_string) unsafe.Pointer {
70 return String("processed: " + CStringToGoString(b))
71}`,
72 expect: 2,
73 },
74 {
75 name: "no php functions",
76 input: `package main
77
78func regularFunc() {
79 // Just a regular Go function
80}`,
81 expect: 0,
82 },
83 {
84 name: "mixed functions",
85 input: `package main
86
87//export_php:function phpFunc(string $data): string
88func phpFunc(data *C.zend_string) unsafe.Pointer {
89 return String("PHP: " + CStringToGoString(data))
90}
91
92func internalFunc() {

Callers

nothing calls this directly

Calls 1

parseMethod · 0.95

Tested by

no test coverage detected