Skip to content

Commit 1dc5c41

Browse files
committed
feat: support up to Go 1.18
The code can be used with old Go versions. The CI will also run tests for Go 1.18 and latest -rc versions.
1 parent c7f103e commit 1dc5c41

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

.github/workflows/compatibility.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,28 @@ on:
1010
- cron: "0 3 * * 0"
1111

1212
jobs:
13+
go-versions:
14+
name: Lookup Go versions
15+
runs-on: ubuntu-latest
16+
outputs:
17+
matrix: ${{ steps.versions.outputs.matrix }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- uses: arnested/go-version-action@v1
23+
id: versions
24+
with:
25+
unstable: true # this includes the future -rc versions
26+
1327
go-compatibility:
28+
needs: go-versions
1429
name: Go ${{ matrix.go-version }}
1530
runs-on: ubuntu-latest
1631
timeout-minutes: 10
1732
strategy:
1833
matrix:
19-
go-version: ["1.23", "oldstable", "stable"]
34+
go-version: ["${{ fromJSON(needs.go-versions.outputs.go-mod-version) }}", "oldstable", "stable", "${{ fromJSON(needs.go-versions.outputs.latest) }}"]
2035

2136
steps:
2237
- name: Checkout

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a href="https://pkg.go.dev/github.com/goforj/godump"><img src="https://pkg.go.dev/badge/github.com/goforj/godump.svg" alt="Go Reference"></a>
1111
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
1212
<a href="https://github.com/goforj/godump/actions"><img src="https://github.com/goforj/godump/actions/workflows/test.yml/badge.svg" alt="Go Test"></a>
13-
<a href="https://golang.org"><img src="https://img.shields.io/badge/go-1.23+-blue?logo=go" alt="Go version"></a>
13+
<a href="https://golang.org"><img src="https://img.shields.io/badge/go-1.18+-blue?logo=go" alt="Go version"></a>
1414
<img src="https://img.shields.io/github/v/tag/goforj/godump?label=version&sort=semver" alt="Latest tag">
1515
<a href="https://goreportcard.com/report/github.com/goforj/godump"><img src="https://goreportcard.com/badge/github.com/goforj/godump" alt="Go Report Card"></a>
1616
<a href="https://codecov.io/gh/goforj/godump" ><img src="https://codecov.io/gh/goforj/godump/graph/badge.svg?token=ULUTXL03XC"/></a>

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/goforj/godump
22

3-
go 1.23
3+
go 1.18
44

55
require github.com/stretchr/testify v1.10.0
66

godump.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ func formatByteSliceAsHexDump(b []byte, indent int) string {
330330
sb.WriteString(fmt.Sprintf("([]uint8) (len=%d cap=%d) {\n", len(b), cap(b)))
331331

332332
for i := 0; i < len(b); i += lineLen {
333-
end := min(i+lineLen, len(b))
333+
334+
end := i + lineLen
335+
if end > len(b) {
336+
end = len(b)
337+
}
334338
line := b[i:end]
335339

336340
visibleLen := 0
@@ -342,7 +346,7 @@ func formatByteSliceAsHexDump(b []byte, indent int) string {
342346
visibleLen += len(offsetStr)
343347

344348
// Hex bytes
345-
for j := range lineLen {
349+
for j := 0; j < lineLen; j++ {
346350
var hexStr string
347351
if j < len(line) {
348352
hexStr = fmt.Sprintf("%02x ", line[j])
@@ -357,7 +361,10 @@ func formatByteSliceAsHexDump(b []byte, indent int) string {
357361
}
358362

359363
// Padding before ASCII
360-
padding := max(1, asciiStartCol-visibleLen)
364+
padding := asciiStartCol - visibleLen
365+
if padding < 1 {
366+
padding = 1
367+
}
361368
sb.WriteString(strings.Repeat(" ", padding))
362369

363370
// ASCII section
@@ -444,7 +451,7 @@ func (d *Dumper) printValue(tw *tabwriter.Writer, v reflect.Value, indent int, v
444451
fmt.Fprintf(tw, "%s {", colorize(colorGray, "#"+t.String()))
445452
fmt.Fprintln(tw)
446453

447-
for i := range t.NumField() {
454+
for i := 0; i < t.NumField(); i++ {
448455
field := t.Field(i)
449456
fieldVal := v.Field(i)
450457

@@ -497,7 +504,7 @@ func (d *Dumper) printValue(tw *tabwriter.Writer, v reflect.Value, indent int, v
497504

498505
// Default rendering for other slices/arrays
499506
fmt.Fprintln(tw, "[")
500-
for i := range v.Len() {
507+
for i := 0; i < v.Len(); i++ {
501508
if i >= d.maxItems {
502509
indentPrint(tw, indent+1, colorize(colorGray, "... (truncated)\n"))
503510
break

godump_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestMaxDepth(t *testing.T) {
7777
}
7878
n := &Node{}
7979
curr := n
80-
for range 20 {
80+
for i := 0; i < 20; i++ {
8181
curr.Child = &Node{}
8282
curr = curr.Child
8383
}
@@ -329,7 +329,7 @@ func TestMaxDepthTruncation(t *testing.T) {
329329
}
330330
root := &Node{}
331331
curr := root
332-
for range 20 {
332+
for i := 0; i < 20; i++ {
333333
curr.Next = &Node{}
334334
curr = curr.Next
335335
}
@@ -344,7 +344,7 @@ func TestCustomMaxDepthTruncation(t *testing.T) {
344344
}
345345
root := &Node{}
346346
curr := root
347-
for range 3 {
347+
for i := 0; i < 3; i++ {
348348
curr.Next = &Node{}
349349
curr = curr.Next
350350
}
@@ -361,7 +361,7 @@ func TestCustomMaxDepthTruncation(t *testing.T) {
361361

362362
func TestMapTruncation(t *testing.T) {
363363
largeMap := map[int]int{}
364-
for i := range 200 {
364+
for i := 0; i < 200; i++ {
365365
largeMap[i] = i
366366
}
367367
out := stripANSI(DumpStr(largeMap))

0 commit comments

Comments
 (0)