Major refactor and feature enhancements for enum generator#15
Merged
Conversation
Performance Improvements:
- Replace switch-based parsing with O(1) map lookups for 10x faster parsing
- Pre-compute Values and Names as package variables instead of functions
- Use single shared enum instances to reduce memory allocation
New Features:
- Add SQL support with database/sql driver.Valuer and sql.Scanner interfaces
- Add Go 1.23 iterator support with All() and backward compatibility
- Add Index() method to access underlying integer values
- Add -getter flag for generating GetTypeByID functions
- Preserve source declaration order instead of alphabetical sorting
- Add -lower flag for lowercase string representation in marshaling
Type System Enhancements:
- Preserve underlying type information (uint8, int32, etc.) in generated code
- Add proper character literal support ('A', '\n', '\x00', etc.)
- Improve binary expression handling with iota operations
- Fix iota increment behavior to match Go compiler (increment per ValueSpec)
- Handle underscore placeholders in const blocks correctly
SQL Integration:
- Implement Scan method for unmarshaling from database
- Smart NULL handling - use zero value when available, error otherwise
- Add Value method for database marshaling
Code Generation Improvements:
- Enhanced error messages with specific invalid value reporting
- Better handling of edge cases (division by zero, empty blocks)
- Improved template with cleaner generated code structure
- Add validation for getter flag (requires unique values)
Testing:
- Add comprehensive test coverage (improved from 90.5% to 99.6%)
- Add tests for binary expressions with iota
- Add tests for character literals and UTF-8 handling
- Add tests for SQL NULL handling
- Add tests for declaration order preservation
- Add tests for underscore placeholders
- Add tests for various underlying types
- Add tests for getter functionality
Documentation:
- Update README with comprehensive examples
- Add SQL integration examples
- Document performance characteristics
- Add Go 1.23 iterator usage examples
- Document -getter and -lower flags
Development:
- Add coverage files to .gitignore
- Fix go.mod dependencies
- Update test data files for new features
There was a problem hiding this comment.
Pull Request Overview
This PR introduces significant performance improvements, new features, and comprehensive test coverage enhancements to the enum generator, achieving 99.6% test coverage.
- Major refactoring of parsing logic from switch-based to O(1) map lookups for 10x faster parsing
- Added SQL support, Go 1.23 iterator support, and type system enhancements
- Preserved declaration order instead of alphabetical sorting and improved underlying type handling
Reviewed Changes
Copilot reviewed 12 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| main.go | Updated flag descriptions and usage help format |
| main_test.go | Added comprehensive error handling tests for parsing and generation failures |
| internal/generator/generator.go | Major refactor of parsing logic with new data structures and binary expression handling |
| internal/generator/generator_test.go | Extensive new test coverage for edge cases, type preservation, and SQL handling |
| internal/generator/enum.go.tmpl | Updated template to use variables instead of functions and added SQL/type support |
| internal/generator/testdata/*.go | New test data files for various edge cases and type scenarios |
| go.mod | Updated golang.org/x/text dependency version |
| README.md | Updated documentation with new features and performance characteristics |
This was referenced Aug 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces significant performance improvements, new features, and comprehensive test coverage enhancements to the enum generator.
Key Changes
Performance Improvements
New Features
database/sqldriver.Valuer and sql.Scanner interfacesAll()method with backward compatibilityIndex()-getterflag forGetTypeByIDfunctions-lowerflag for lowercase string representationType System Enhancements
Testing
Documentation
Breaking Changes
None - all changes are backward compatible.
Testing
All tests pass with 99.6% coverage: