Skip to content

Commit c68da2e

Browse files
authored
feat: support go 1.24 Text Appender (#271)
1 parent c8900b3 commit c68da2e

27 files changed

+1502
-17
lines changed

example/color_enum.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/color_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,19 @@ func TestColorMarshal(t *testing.T) {
238238
}
239239
}
240240

241+
func TestColorAppendText(t *testing.T) {
242+
input := ColorRedOrangeBlue
243+
expected := "red-orange-blue"
244+
245+
a, err1 := input.AppendText(nil)
246+
b, err2 := input.MarshalText()
247+
require.NoError(t, err1, "AppendText should not return an error")
248+
require.NoError(t, err2, "MarshalText should not return an error")
249+
assert.Equal(t, expected, string(a), "AppendText should return the correct string")
250+
assert.Equal(t, expected, string(b), "MarshalText should return the correct string")
251+
assert.Equal(t, expected, input.String(), "String should return the correct string")
252+
}
253+
241254
func BenchmarkColorParse(b *testing.B) {
242255
knownItems := []string{
243256
ColorRedOrangeBlue.String(),

example/commented_enum.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example_enum.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/replace_prefix_enum.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/replace_prefix_int_enum.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/sql_enum.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/strings_only_enum.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generator/.snapshots/Test118CustomPrefixExampleFile-1.18

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
([]string) (len=288) {
1+
([]string) (len=296) {
22
(string) (len=41) "// Code generated by go-enum DO NOT EDIT.",
33
(string) (len=13) "// Version: -",
44
(string) (len=14) "// Revision: -",
@@ -87,6 +87,14 @@
8787
(string) (len=11) "\treturn nil",
8888
(string) (len=1) "}",
8989
(string) "",
90+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
91+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
92+
(string) (len=2) "//",
93+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
94+
(string) (len=59) "func (x *ChangeType) AppendText(b []byte) ([]byte, error) {",
95+
(string) (len=37) "\treturn append(b, x.String()...), nil",
96+
(string) (len=1) "}",
97+
(string) "",
9098
(string) (len=96) "var errChangeTypeNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
9199
(string) "",
92100
(string) (len=41) "// Scan implements the Scanner interface.",

generator/.snapshots/Test118CustomPrefixExampleFile-og

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
([]string) (len=4062) {
1+
([]string) (len=4174) {
22
(string) (len=41) "// Code generated by go-enum DO NOT EDIT.",
33
(string) (len=13) "// Version: -",
44
(string) (len=14) "// Revision: -",
@@ -87,6 +87,14 @@
8787
(string) (len=11) "\treturn nil",
8888
(string) (len=1) "}",
8989
(string) "",
90+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
91+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
92+
(string) (len=2) "//",
93+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
94+
(string) (len=55) "func (x *Animal) AppendText(b []byte) ([]byte, error) {",
95+
(string) (len=37) "\treturn append(b, x.String()...), nil",
96+
(string) (len=1) "}",
97+
(string) "",
9098
(string) (len=92) "var errAnimalNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
9199
(string) "",
92100
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -358,6 +366,14 @@
358366
(string) (len=11) "\treturn nil",
359367
(string) (len=1) "}",
360368
(string) "",
369+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
370+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
371+
(string) (len=2) "//",
372+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
373+
(string) (len=54) "func (x *Cases) AppendText(b []byte) ([]byte, error) {",
374+
(string) (len=37) "\treturn append(b, x.String()...), nil",
375+
(string) (len=1) "}",
376+
(string) "",
361377
(string) (len=91) "var errCasesNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
362378
(string) "",
363379
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -649,6 +665,14 @@
649665
(string) (len=11) "\treturn nil",
650666
(string) (len=1) "}",
651667
(string) "",
668+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
669+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
670+
(string) (len=2) "//",
671+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
672+
(string) (len=54) "func (x *Color) AppendText(b []byte) ([]byte, error) {",
673+
(string) (len=37) "\treturn append(b, x.String()...), nil",
674+
(string) (len=1) "}",
675+
(string) "",
652676
(string) (len=91) "var errColorNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
653677
(string) "",
654678
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -941,6 +965,14 @@
941965
(string) (len=11) "\treturn nil",
942966
(string) (len=1) "}",
943967
(string) "",
968+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
969+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
970+
(string) (len=2) "//",
971+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
972+
(string) (len=65) "func (x *ColorWithComment) AppendText(b []byte) ([]byte, error) {",
973+
(string) (len=37) "\treturn append(b, x.String()...), nil",
974+
(string) (len=1) "}",
975+
(string) "",
944976
(string) (len=102) "var errColorWithCommentNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
945977
(string) "",
946978
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -1233,6 +1265,14 @@
12331265
(string) (len=11) "\treturn nil",
12341266
(string) (len=1) "}",
12351267
(string) "",
1268+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
1269+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
1270+
(string) (len=2) "//",
1271+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
1272+
(string) (len=66) "func (x *ColorWithComment2) AppendText(b []byte) ([]byte, error) {",
1273+
(string) (len=37) "\treturn append(b, x.String()...), nil",
1274+
(string) (len=1) "}",
1275+
(string) "",
12361276
(string) (len=103) "var errColorWithComment2NilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
12371277
(string) "",
12381278
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -1541,6 +1581,14 @@
15411581
(string) (len=11) "\treturn nil",
15421582
(string) (len=1) "}",
15431583
(string) "",
1584+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
1585+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
1586+
(string) (len=2) "//",
1587+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
1588+
(string) (len=66) "func (x *ColorWithComment3) AppendText(b []byte) ([]byte, error) {",
1589+
(string) (len=37) "\treturn append(b, x.String()...), nil",
1590+
(string) (len=1) "}",
1591+
(string) "",
15441592
(string) (len=103) "var errColorWithComment3NilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
15451593
(string) "",
15461594
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -1849,6 +1897,14 @@
18491897
(string) (len=11) "\treturn nil",
18501898
(string) (len=1) "}",
18511899
(string) "",
1900+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
1901+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
1902+
(string) (len=2) "//",
1903+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
1904+
(string) (len=66) "func (x *ColorWithComment4) AppendText(b []byte) ([]byte, error) {",
1905+
(string) (len=37) "\treturn append(b, x.String()...), nil",
1906+
(string) (len=1) "}",
1907+
(string) "",
18521908
(string) (len=103) "var errColorWithComment4NilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
18531909
(string) "",
18541910
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -2180,6 +2236,14 @@
21802236
(string) (len=11) "\treturn nil",
21812237
(string) (len=1) "}",
21822238
(string) "",
2239+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
2240+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
2241+
(string) (len=2) "//",
2242+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
2243+
(string) (len=58) "func (x *Enum64bit) AppendText(b []byte) ([]byte, error) {",
2244+
(string) (len=37) "\treturn append(b, x.String()...), nil",
2245+
(string) (len=1) "}",
2246+
(string) "",
21832247
(string) (len=95) "var errEnum64bitNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
21842248
(string) "",
21852249
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -2455,6 +2519,14 @@
24552519
(string) (len=11) "\treturn nil",
24562520
(string) (len=1) "}",
24572521
(string) "",
2522+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
2523+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
2524+
(string) (len=2) "//",
2525+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
2526+
(string) (len=54) "func (x *Model) AppendText(b []byte) ([]byte, error) {",
2527+
(string) (len=37) "\treturn append(b, x.String()...), nil",
2528+
(string) (len=1) "}",
2529+
(string) "",
24582530
(string) (len=91) "var errModelNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
24592531
(string) "",
24602532
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -2726,6 +2798,14 @@
27262798
(string) (len=11) "\treturn nil",
27272799
(string) (len=1) "}",
27282800
(string) "",
2801+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
2802+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
2803+
(string) (len=2) "//",
2804+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
2805+
(string) (len=57) "func (x *NonASCII) AppendText(b []byte) ([]byte, error) {",
2806+
(string) (len=37) "\treturn append(b, x.String()...), nil",
2807+
(string) (len=1) "}",
2808+
(string) "",
27292809
(string) (len=94) "var errNonASCIINilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
27302810
(string) "",
27312811
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -3017,6 +3097,14 @@
30173097
(string) (len=11) "\treturn nil",
30183098
(string) (len=1) "}",
30193099
(string) "",
3100+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
3101+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
3102+
(string) (len=2) "//",
3103+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
3104+
(string) (len=59) "func (x *Sanitizing) AppendText(b []byte) ([]byte, error) {",
3105+
(string) (len=37) "\treturn append(b, x.String()...), nil",
3106+
(string) (len=1) "}",
3107+
(string) "",
30203108
(string) (len=96) "var errSanitizingNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
30213109
(string) "",
30223110
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -3288,6 +3376,14 @@
32883376
(string) (len=11) "\treturn nil",
32893377
(string) (len=1) "}",
32903378
(string) "",
3379+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
3380+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
3381+
(string) (len=2) "//",
3382+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
3383+
(string) (len=53) "func (x *Soda) AppendText(b []byte) ([]byte, error) {",
3384+
(string) (len=37) "\treturn append(b, x.String()...), nil",
3385+
(string) (len=1) "}",
3386+
(string) "",
32913387
(string) (len=90) "var errSodaNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
32923388
(string) "",
32933389
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -3554,6 +3650,14 @@
35543650
(string) (len=11) "\treturn nil",
35553651
(string) (len=1) "}",
35563652
(string) "",
3653+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
3654+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
3655+
(string) (len=2) "//",
3656+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
3657+
(string) (len=61) "func (x *StartNotZero) AppendText(b []byte) ([]byte, error) {",
3658+
(string) (len=37) "\treturn append(b, x.String()...), nil",
3659+
(string) (len=1) "}",
3660+
(string) "",
35573661
(string) (len=98) "var errStartNotZeroNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
35583662
(string) "",
35593663
(string) (len=41) "// Scan implements the Scanner interface.",
@@ -3810,6 +3914,14 @@
38103914
(string) (len=11) "\treturn nil",
38113915
(string) (len=1) "}",
38123916
(string) "",
3917+
(string) (len=74) "// AppendText appends the textual representation of itself to the end of b",
3918+
(string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.",
3919+
(string) (len=2) "//",
3920+
(string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].",
3921+
(string) (len=59) "func (x *StringEnum) AppendText(b []byte) ([]byte, error) {",
3922+
(string) (len=37) "\treturn append(b, x.String()...), nil",
3923+
(string) (len=1) "}",
3924+
(string) "",
38133925
(string) (len=96) "var errStringEnumNilPtr = errors.New(\"value pointer is nil\") // one per type for package clashes",
38143926
(string) "",
38153927
(string) (len=41) "// Scan implements the Scanner interface.",

0 commit comments

Comments
 (0)