| 234 | } |
| 235 | |
| 236 | func TestConstantParserConstBlock(t *testing.T) { |
| 237 | input := `package main |
| 238 | |
| 239 | const ( |
| 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 | |
| 271 | func TestConstantParserConstBlockWithBlockLevelDirective(t *testing.T) { |
| 272 | input := `package main |