| 205 | } |
| 206 | |
| 207 | func TestConstantParserIotaSequence(t *testing.T) { |
| 208 | input := `package main |
| 209 | |
| 210 | //export_php:const |
| 211 | const FirstIota = iota |
| 212 | |
| 213 | //export_php:const |
| 214 | const SecondIota = iota |
| 215 | |
| 216 | //export_php:const |
| 217 | const 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 | |
| 236 | func TestConstantParserConstBlock(t *testing.T) { |
| 237 | input := `package main |