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

Function TestNamespaceParser

internal/extgen/namespace_test.go:10–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestNamespaceParser(t *testing.T) {
11 tests := []struct {
12 name string
13 content string
14 expected string
15 shouldError bool
16 }{
17 {
18 name: "basic namespace",
19 content: `package main
20
21//export_php:namespace My\Test\Namespace
22
23func main() {}`,
24 expected: `My\Test\Namespace`,
25 },
26 {
27 name: "namespace with spaces",
28 content: `package main
29
30//export_php:namespace My\Test\Namespace
31
32func main() {}`,
33 expected: `My\Test\Namespace`,
34 },
35 {
36 name: "no namespace",
37 content: `package main
38
39func main() {}`,
40 expected: "",
41 },
42 {
43 name: "multiple namespaces should error",
44 content: `package main
45
46//export_php:namespace First\Namespace
47//export_php:namespace Second\Namespace
48
49func main() {}`,
50 expected: "",
51 shouldError: true,
52 },
53 }
54
55 for _, tt := range tests {
56 t.Run(tt.name, func(t *testing.T) {
57 tmpfile, err := os.CreateTemp("", "test_namespace_*.go")
58 require.NoError(t, err, "Failed to create temp file")
59 defer func() {
60 require.NoError(t, os.Remove(tmpfile.Name()), "Failed to remove temp file")
61 }()
62
63 _, err = tmpfile.Write([]byte(tt.content))
64 require.NoError(t, err, "Failed to write to temp file")
65
66 err = tmpfile.Close()
67 require.NoError(t, err, "Failed to close temp file")

Callers

nothing calls this directly

Calls 5

parseMethod · 0.95
NameMethod · 0.80
CloseMethod · 0.80
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected