MCPcopy Create free account
hub / github.com/php/frankenphp / TestConstantParserIotaSequence

Function TestConstantParserIotaSequence

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

Source from the content-addressed store, hash-verified

205}
206
207func TestConstantParserIotaSequence(t *testing.T) {
208 input := `package main
209
210//export_php:const
211const FirstIota = iota
212
213//export_php:const
214const SecondIota = iota
215
216//export_php:const
217const ThirdIota = iota`
218
219 tmpDir := t.TempDir()
220 fileName := filepath.Join(tmpDir, "test.go")
221 require.NoError(t, os.WriteFile(fileName, []byte(input), 0644))
222
223 parser := &ConstantParser{}
224 constants, err := parser.parse(fileName)
225 assert.NoError(t, err, "parse() error")
226
227 assert.Len(t, constants, 3, "Expected 3 constants")
228
229 expectedValues := []string{"0", "1", "2"}
230 for i, c := range constants {
231 assert.True(t, c.IsIota, "Expected constant %d to be iota", i)
232 assert.Equal(t, expectedValues[i], c.Value, "Expected constant %d value to be '%s'", i, expectedValues[i])
233 }
234}
235
236func TestConstantParserConstBlock(t *testing.T) {
237 input := `package main

Callers

nothing calls this directly

Calls 1

parseMethod · 0.95

Tested by

no test coverage detected