| 171 | } |
| 172 | |
| 173 | func TestConstantParserErrors(t *testing.T) { |
| 174 | tests := []struct { |
| 175 | name string |
| 176 | input string |
| 177 | }{ |
| 178 | { |
| 179 | name: "invalid constant declaration", |
| 180 | input: `package main |
| 181 | |
| 182 | //export_php:const |
| 183 | const = "missing name"`, |
| 184 | }, |
| 185 | { |
| 186 | name: "malformed constant", |
| 187 | input: `package main |
| 188 | |
| 189 | //export_php:const |
| 190 | const InvalidSyntax`, |
| 191 | }, |
| 192 | } |
| 193 | |
| 194 | for _, tt := range tests { |
| 195 | t.Run(tt.name, func(t *testing.T) { |
| 196 | tmpDir := t.TempDir() |
| 197 | tmpFile := filepath.Join(tmpDir, tt.name+".go") |
| 198 | require.NoError(t, os.WriteFile(tmpFile, []byte(tt.input), 0644)) |
| 199 | |
| 200 | parser := &ConstantParser{} |
| 201 | _, err := parser.parse(tmpFile) |
| 202 | assert.Error(t, err, "Expected error but got none") |
| 203 | }) |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | func TestConstantParserIotaSequence(t *testing.T) { |
| 208 | input := `package main |