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

Function TestConstantParserConstBlock

internal/extgen/constparser_test.go:236–269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

234}
235
236func TestConstantParserConstBlock(t *testing.T) {
237 input := `package main
238
239const (
240 // export_php:const
241 STATUS_PENDING = iota
242
243 // export_php:const
244 STATUS_PROCESSING
245
246 // export_php:const
247 STATUS_COMPLETED
248)`
249
250 tmpDir := t.TempDir()
251 fileName := filepath.Join(tmpDir, "test.go")
252 require.NoError(t, os.WriteFile(fileName, []byte(input), 0644))
253
254 parser := &ConstantParser{}
255 constants, err := parser.parse(fileName)
256 assert.NoError(t, err, "parse() error")
257
258 assert.Len(t, constants, 3, "Expected 3 constants")
259
260 expectedNames := []string{"STATUS_PENDING", "STATUS_PROCESSING", "STATUS_COMPLETED"}
261 expectedValues := []string{"0", "1", "2"}
262
263 for i, c := range constants {
264 assert.Equal(t, expectedNames[i], c.Name, "Expected constant %d name to be '%s'", i, expectedNames[i])
265 assert.True(t, c.IsIota, "Expected constant %d to be iota", i)
266 assert.Equal(t, expectedValues[i], c.Value, "Expected constant %d value to be '%s'", i, expectedValues[i])
267 assert.Equal(t, phpInt, c.PhpType, "Expected constant %d to be phpInt type", i)
268 }
269}
270
271func TestConstantParserConstBlockWithBlockLevelDirective(t *testing.T) {
272 input := `package main

Callers

nothing calls this directly

Calls 1

parseMethod · 0.95

Tested by

no test coverage detected