Skip to content

Commit cce0000

Browse files
authored
Fixes (#37)
* fixes * Code fixes and regeneration * formatting
1 parent ea64c75 commit cce0000

File tree

13 files changed

+76
-76
lines changed

13 files changed

+76
-76
lines changed

generator/gofile/gofile_parser.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,14 @@ func (p *Parser) getEnums(node *ast.File, enumIota *enum.EnumIota) []enum.Enum {
190190
// Check if this const block contains iota with the target type
191191
blockHasIota := false
192192
blockHasTargetType := false
193-
193+
194194
// First pass: check if this const block has both iota and the target type
195195
for _, spec := range t.Specs {
196196
vs, ok := spec.(*ast.ValueSpec)
197197
if !ok {
198198
continue
199199
}
200-
200+
201201
// Check for iota in values
202202
if vs.Values != nil {
203203
for _, v := range vs.Values {
@@ -212,20 +212,20 @@ func (p *Parser) getEnums(node *ast.File, enumIota *enum.EnumIota) []enum.Enum {
212212
}
213213
}
214214
}
215-
215+
216216
// Check if this spec has the target type
217217
if vs.Type != nil {
218218
if typeIdent, ok := vs.Type.(*ast.Ident); ok && typeIdent.Name == enumIota.Type {
219219
blockHasTargetType = true
220220
}
221221
}
222222
}
223-
223+
224224
// Only process this const block if it has both iota and the target type
225225
if !blockHasIota || !blockHasTargetType {
226226
continue
227227
}
228-
228+
229229
// Second pass: collect enums from this const block
230230
idx := 0
231231
constBlockIotaFound := false

internal/testdata/aliases/orders_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestOrdersIteration(t *testing.T) {
2727

2828
// Verify expected order sequence
2929
expected := []orders.Order{
30-
orders.Orders.CREATED, orders.Orders.APPROVED, orders.Orders.PROCESSING, orders.Orders.READYTOSHIP,
30+
orders.Orders.CREATED, orders.Orders.APPROVED, orders.Orders.PROCESSING, orders.Orders.READYTOSHIP,
3131
orders.Orders.SHIPPED, orders.Orders.DELIVERED, orders.Orders.CANCELLED,
3232
}
3333
for i, order := range collected {
@@ -51,7 +51,7 @@ func TestOrdersStringParsing(t *testing.T) {
5151
{"SHIPPED", orders.Orders.SHIPPED, false},
5252
{"DELIVERED", orders.Orders.DELIVERED, false},
5353
{"CANCELLED", orders.Orders.CANCELLED, false},
54-
54+
5555
// Non-existent should fail
5656
{"InvalidOrder", orders.Order{}, true},
5757
}
@@ -77,10 +77,10 @@ func TestOrdersValidity(t *testing.T) {
7777
orders.Orders.CREATED, orders.Orders.APPROVED, orders.Orders.PROCESSING, orders.Orders.READYTOSHIP,
7878
orders.Orders.SHIPPED, orders.Orders.DELIVERED, orders.Orders.CANCELLED,
7979
}
80-
80+
8181
for _, order := range validOrders {
8282
if !order.IsValid() {
8383
t.Errorf("Order %v should be valid", order)
8484
}
8585
}
86-
}
86+
}

internal/testdata/enum_validation_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestGeneratedEnumsExist(t *testing.T) {
3434
for _, tc := range testCases {
3535
t.Run(tc.dir+"/"+tc.expectedFile, func(t *testing.T) {
3636
filePath := filepath.Join(tc.dir, tc.expectedFile)
37-
37+
3838
// Check file exists
3939
if _, err := os.Stat(filePath); os.IsNotExist(err) {
4040
t.Errorf("Expected generated file %s does not exist", filePath)
@@ -66,21 +66,21 @@ func TestGeneratedEnumsExist(t *testing.T) {
6666
// validateEnumFileStructure checks that the generated file has the expected enum components
6767
func validateEnumFileStructure(t *testing.T, content, filePath string) error {
6868
requiredPatterns := []string{
69-
"// DO NOT EDIT.", // Generated file header
70-
"code generated by goenums", // Generator attribution
71-
"type .* struct {", // Enum wrapper type
72-
"Container struct {", // Container type
73-
"func Parse.*\\(input any\\)", // Parse function
74-
"func .*\\.String\\(\\) string", // String method
75-
"func .*\\.IsValid\\(\\) bool", // IsValid method
76-
"func .*\\.MarshalJSON\\(\\)", // JSON marshaling
77-
"func .*\\.UnmarshalJSON\\(", // JSON unmarshaling
78-
"func .*\\.MarshalText\\(\\)", // Text marshaling
79-
"func .*\\.UnmarshalText\\(", // Text unmarshaling
80-
"func .*\\.MarshalBinary\\(\\)", // Binary marshaling
81-
"func .*\\.UnmarshalBinary\\(", // Binary unmarshaling
82-
"func .*\\.Scan\\(", // SQL Scanner
83-
"func .*\\.Value\\(\\)", // SQL Valuer
69+
"// DO NOT EDIT.", // Generated file header
70+
"code generated by goenums", // Generator attribution
71+
"type .* struct {", // Enum wrapper type
72+
"Container struct {", // Container type
73+
"func Parse.*\\(input any\\)", // Parse function
74+
"func .*\\.String\\(\\) string", // String method
75+
"func .*\\.IsValid\\(\\) bool", // IsValid method
76+
"func .*\\.MarshalJSON\\(\\)", // JSON marshaling
77+
"func .*\\.UnmarshalJSON\\(", // JSON unmarshaling
78+
"func .*\\.MarshalText\\(\\)", // Text marshaling
79+
"func .*\\.UnmarshalText\\(", // Text unmarshaling
80+
"func .*\\.MarshalBinary\\(\\)", // Binary marshaling
81+
"func .*\\.UnmarshalBinary\\(", // Binary unmarshaling
82+
"func .*\\.Scan\\(", // SQL Scanner
83+
"func .*\\.Value\\(\\)", // SQL Valuer
8484
}
8585

8686
for _, pattern := range requiredPatterns {
@@ -90,7 +90,7 @@ func validateEnumFileStructure(t *testing.T, content, filePath string) error {
9090
simplePattern = strings.ReplaceAll(simplePattern, "\\(", "(")
9191
simplePattern = strings.ReplaceAll(simplePattern, "\\)", ")")
9292
simplePattern = strings.ReplaceAll(simplePattern, "\\\\", "")
93-
93+
9494
if !strings.Contains(content, simplePattern) {
9595
t.Logf("Missing pattern in %s: %s", filePath, pattern)
9696
}
@@ -104,7 +104,7 @@ func validateEnumFileStructure(t *testing.T, content, filePath string) error {
104104
func TestGeneratedEnumsAreValidJSONMarshalable(t *testing.T) {
105105
// This is a compile-time test - if any enum doesn't implement json.Marshaler properly,
106106
// the compilation will fail when we try to marshal it
107-
107+
108108
testData := []interface{}{
109109
map[string]interface{}{"test": "value"},
110110
}
@@ -152,7 +152,7 @@ func TestParsePointerFix(t *testing.T) {
152152
found = true
153153
break
154154
}
155-
155+
156156
// Also check for the new number type format
157157
if tc.content == "func numberToAlgorithm[T constraints.Integer | constraints.Float](num T) *Algorithm" {
158158
// Check for the new format
@@ -170,7 +170,7 @@ func TestParsePointerFix(t *testing.T) {
170170
}
171171
}
172172

173-
// TestValidityMapFix tests that the validity map fix works correctly
173+
// TestValidityMapFix tests that the validity map fix works correctly
174174
func TestValidityMapFix(t *testing.T) {
175175
// Test that invalid package correctly marks only FAILED as invalid
176176
content, err := os.ReadFile("invalid/statuses_enums.go")
@@ -180,7 +180,7 @@ func TestValidityMapFix(t *testing.T) {
180180

181181
contentStr := string(content)
182182

183-
// Should have FAILED: false (invalid)
183+
// Should have FAILED: false (invalid)
184184
if !strings.Contains(contentStr, "Statuses.FAILED") || !strings.Contains(contentStr, "false") {
185185
t.Error("FAILED should be marked as invalid (false) in validity map")
186186
}
@@ -211,12 +211,12 @@ func TestNegativePackageCompiles(t *testing.T) {
211211

212212
// Check validity markers: NONE should be invalid, others should be valid
213213
contentStr := string(content)
214-
214+
215215
// NONE should be invalid due to "// invalid" comment
216216
if !strings.Contains(contentStr, "Algorithms.NONE:") || !strings.Contains(contentStr, "false,") {
217217
t.Errorf("NONE should be marked as invalid (false) in validity map")
218218
}
219-
219+
220220
// AES256 and CHACHA20 should be valid
221221
validEnums := []string{"AES256", "CHACHA20"}
222222
for _, enum := range validEnums {
@@ -229,7 +229,7 @@ func TestNegativePackageCompiles(t *testing.T) {
229229
// TestMultiplePackageCompiles tests that the multiple package compiles correctly
230230
func TestMultiplePackageCompiles(t *testing.T) {
231231
files := []string{"multiple/statuses_enums.go", "multiple/orders_enums.go"}
232-
232+
233233
for _, file := range files {
234234
t.Run(file, func(t *testing.T) {
235235
content, err := os.ReadFile(file)
@@ -260,4 +260,4 @@ func TestTimePackageFloatIssue(t *testing.T) {
260260
if err != nil {
261261
t.Errorf("time/sales_enums.go should compile without errors: %v", err)
262262
}
263-
}
263+
}

internal/testdata/invalid/statuses_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestStatusIteration(t *testing.T) {
2727

2828
// Verify expected valid statuses are present
2929
expected := []validation.Status{
30-
validation.Statuses.PASSED, validation.Statuses.SKIPPED, validation.Statuses.SCHEDULED,
30+
validation.Statuses.PASSED, validation.Statuses.SKIPPED, validation.Statuses.SCHEDULED,
3131
validation.Statuses.RUNNING, validation.Statuses.BOOKED,
3232
}
3333
for i, status := range collected {
@@ -49,10 +49,10 @@ func TestStatusStringParsing(t *testing.T) {
4949
{"scheduled", validation.Statuses.SCHEDULED, false},
5050
{"running", validation.Statuses.RUNNING, false},
5151
{"booked", validation.Statuses.BOOKED, false},
52-
52+
5353
// Failed status should also parse (but will be marked as invalid)
5454
{"failed", validation.Statuses.FAILED, false},
55-
55+
5656
// Non-existent should fail
5757
{"NonExistent", validation.Status{}, true},
5858
}
@@ -78,7 +78,7 @@ func TestStatusValidity(t *testing.T) {
7878
validation.Statuses.PASSED, validation.Statuses.SKIPPED, validation.Statuses.SCHEDULED,
7979
validation.Statuses.RUNNING, validation.Statuses.BOOKED,
8080
}
81-
81+
8282
for _, status := range validStatuses {
8383
if !status.IsValid() {
8484
t.Errorf("Status %v should be valid", status)
@@ -89,4 +89,4 @@ func TestStatusValidity(t *testing.T) {
8989
if validation.Statuses.FAILED.IsValid() {
9090
t.Error("FAILED status should be invalid")
9191
}
92-
}
92+
}

internal/testdata/invalid_alias/statuses_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ func TestStatusAliasStringParsing(t *testing.T) {
3838
{"SCHEDULED", validationstrings.Statuses.SCHEDULED, false},
3939
{"RUNNING", validationstrings.Statuses.RUNNING, false},
4040
{"BOOKED", validationstrings.Statuses.BOOKED, false},
41-
41+
4242
// Failed status should also parse
4343
{"FAILED", validationstrings.Statuses.FAILED, false},
44-
44+
4545
// Non-existent should fail
4646
{"NonExistent", validationstrings.Status{}, true},
4747
}
@@ -67,7 +67,7 @@ func TestStatusAliasValidity(t *testing.T) {
6767
validationstrings.Statuses.PASSED, validationstrings.Statuses.SKIPPED, validationstrings.Statuses.SCHEDULED,
6868
validationstrings.Statuses.RUNNING, validationstrings.Statuses.BOOKED,
6969
}
70-
70+
7171
for _, status := range validStatuses {
7272
if !status.IsValid() {
7373
t.Errorf("Status %v should be valid", status)
@@ -78,4 +78,4 @@ func TestStatusAliasValidity(t *testing.T) {
7878
if validationstrings.Statuses.FAILED.IsValid() {
7979
t.Error("FAILED status should be invalid")
8080
}
81-
}
81+
}

internal/testdata/multiple/multiple_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ func TestMultipleEnumsNotMixed(t *testing.T) {
1313
orderEnums = append(orderEnums, e)
1414
}
1515
orderCount := 7 // created, approved, processing, readyToShip, shipped, delivered, cancelled
16-
16+
1717
if len(orderEnums) != orderCount {
1818
t.Errorf("Expected %d order enums, got %d", orderCount, len(orderEnums))
1919
}
20-
20+
2121
// Check that no status constants are in the order container
2222
for _, e := range orderEnums {
2323
name := e.String()
@@ -28,18 +28,18 @@ func TestMultipleEnumsNotMixed(t *testing.T) {
2828
}
2929
}
3030
}
31-
31+
3232
// Test that status enums only contain status constants
3333
var statusEnums []multipleenums.Status
3434
for e := range multipleenums.Statuses.All() {
3535
statusEnums = append(statusEnums, e)
3636
}
3737
statusCount := 6 // failed, passed, skipped, scheduled, running, booked
38-
38+
3939
if len(statusEnums) != statusCount {
4040
t.Errorf("Expected %d status enums, got %d", statusCount, len(statusEnums))
4141
}
42-
42+
4343
// Check that no order constants are in the status container
4444
for _, e := range statusEnums {
4545
name := e.String()
@@ -50,4 +50,4 @@ func TestMultipleEnumsNotMixed(t *testing.T) {
5050
}
5151
}
5252
}
53-
}
53+
}

internal/testdata/negative/algorithms_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ func TestAlgorithmsStringParsing(t *testing.T) {
4343
// Valid algorithms should parse successfully
4444
{"AES256", crypto.Algorithms.AES256, false},
4545
{"ChaCha20", crypto.Algorithms.CHACHA20, false},
46-
46+
4747
// Invalid algorithm should also parse (but will be marked as invalid)
4848
{"None", crypto.Algorithms.NONE, false},
49-
49+
5050
// Non-existent should fail
5151
{"InvalidAlgorithm", crypto.Algorithm{}, true},
5252
}
@@ -69,7 +69,7 @@ func TestAlgorithmsStringParsing(t *testing.T) {
6969
func TestAlgorithmsValidity(t *testing.T) {
7070
// Valid algorithms should return true
7171
validAlgorithms := []crypto.Algorithm{crypto.Algorithms.AES256, crypto.Algorithms.CHACHA20}
72-
72+
7373
for _, alg := range validAlgorithms {
7474
if !alg.IsValid() {
7575
t.Errorf("Algorithm %v should be valid", alg)
@@ -108,10 +108,10 @@ func TestAlgorithmsNumericParsing(t *testing.T) {
108108
// Numeric parsing based on valid algorithm indices (not enum values)
109109
{1, crypto.Algorithms.AES256, false}, // First valid algorithm
110110
{2, crypto.Algorithms.CHACHA20, false}, // Second valid algorithm
111-
111+
112112
// Out of bounds should fail
113-
{0, crypto.Algorithm{}, true}, // Invalid index
114-
{3, crypto.Algorithm{}, true}, // Out of bounds
113+
{0, crypto.Algorithm{}, true}, // Invalid index
114+
{3, crypto.Algorithm{}, true}, // Out of bounds
115115
{999, crypto.Algorithm{}, true},
116116
}
117117

@@ -128,4 +128,4 @@ func TestAlgorithmsNumericParsing(t *testing.T) {
128128
t.Errorf("ParseAlgorithm(%d): expected %v, got %v", test.input, test.expected, got)
129129
}
130130
}
131-
}
131+
}

internal/testdata/plural/discounttypes_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestDiscountTypesIteration(t *testing.T) {
2727

2828
// Verify expected discount type sequence
2929
expected := []sale.DiscountType{
30-
sale.DiscountTypes.SALE, sale.DiscountTypes.PERCENTAGE,
30+
sale.DiscountTypes.SALE, sale.DiscountTypes.PERCENTAGE,
3131
sale.DiscountTypes.AMOUNT, sale.DiscountTypes.GIVEAWAY,
3232
}
3333
for i, discountType := range collected {
@@ -48,7 +48,7 @@ func TestDiscountTypesStringParsing(t *testing.T) {
4848
{"percentage", sale.DiscountTypes.PERCENTAGE, false},
4949
{"amount", sale.DiscountTypes.AMOUNT, false},
5050
{"giveaway", sale.DiscountTypes.GIVEAWAY, false},
51-
51+
5252
// Non-existent should fail
5353
{"invalid", sale.DiscountType{}, true},
5454
}
@@ -74,10 +74,10 @@ func TestDiscountTypesValidity(t *testing.T) {
7474
sale.DiscountTypes.SALE, sale.DiscountTypes.PERCENTAGE,
7575
sale.DiscountTypes.AMOUNT, sale.DiscountTypes.GIVEAWAY,
7676
}
77-
77+
7878
for _, discountType := range validDiscountTypes {
7979
if !discountType.IsValid() {
8080
t.Errorf("DiscountType %v should be valid", discountType)
8181
}
8282
}
83-
}
83+
}

0 commit comments

Comments
 (0)