Add regression test for enum values containing backslashes#2454
Conversation
Closes: #2180 The reported miscompilation — a string enum value like N\A emitted verbatim into a double-quoted Go literal — was already fixed by #2433, which routes string enum constants through strconv.Quote. That change shipped without an end-to-end test for this scenario, so pin it with a test generating from the issue's schema and asserting the escaped constant and formattable output. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Greptile SummaryThis PR adds a regression test for the backslash-in-enum-value miscompilation fixed in #2433, confirming that
Confidence Score: 4/5Safe to merge — the test correctly exercises the fix and cannot break anything in production code. The only change is an additive test that passes today. The sole concern is organizational: the test lives in codegen_test.go instead of the internal/test/schemas/enums leaf, which means no committed golden file is produced and the connection to the project's feature-category test tree is lost. No files require special attention beyond the test placement question in pkg/codegen/codegen_test.go.
|
| Filename | Overview |
|---|---|
| pkg/codegen/codegen_test.go | Adds TestEnumValueEscaping, which correctly verifies that a backslash-containing enum value is emitted as a properly escaped Go literal and that the output is go/format-clean. Functionally sound, but placed in codegen_test.go instead of the canonical internal/test/schemas/enums leaf where it would also produce a committed golden file. |
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
pkg/codegen/codegen_test.go:584-626
**Test belongs in `internal/test/schemas/enums`, not `codegen_test.go`**
Per the project's test placement rules, enum-escaping scenarios belong in `internal/test/schemas/enums`. The existing leaf already tests illegal identifier generation from pathological enum string values; a backslash-containing value is the same construct with one more variant. The fix is straightforward: add `"N\\A"` to the `Bar` enum in `internal/test/schemas/enums/spec.yaml` (that spec has a path using `Bar`, so `SkipPrune` is not needed), add an assertion in `enums_test.go`, and regenerate `enums.gen.go`. Landing the change in the generated golden file gives a committed proof that `strconv.Quote` is in the output and gives CI a diff-check that will catch any future regression at the template level.
Reviews (1): Last reviewed commit: "Add regression test for enum values cont..." | Re-trigger Greptile
Closes: #2180
The reported miscompilation — a string enum value like N\A emitted verbatim into a double-quoted Go literal — was already fixed by #2433, which routes string enum constants through strconv.Quote. That change shipped without an end-to-end test for this scenario, so pin it with a test generating from the issue's schema and asserting the escaped constant and formattable output.