Skip to content

Commit

Permalink
feat: better formating for a strings.Builder{} with %V
Browse files Browse the repository at this point in the history
  • Loading branch information
tucats committed Jan 1, 2025
1 parent 9da5410 commit 566a715
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions data/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ func Format(element interface{}) string {

return text.String()

case *strings.Builder:
return fmt.Sprintf("strings.Builder{String:\"%s\", Len:%d, Cap: %d}", v.String(), v.Len(), v.Cap())

default:
return formatNativeGoValue(v)
}
Expand Down
7 changes: 7 additions & 0 deletions tests/packages/builders.ego
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@
// Force the capacity to a larger value, and see if it takes.
a.Grow(1200)
@assert a.Cap() >= 1200

// Format a builder for %V, and access the default String() method for %v
a = strings.Builder{}
a.WriteString("test")
a.WriteRune(int32(88))
@assert fmt.Sprintf("%V", a) == `strings.Builder{String:"testX", Len:5, Cap: 8}`
@assert fmt.Sprintf("%v", a) == "testX"
}
2 changes: 1 addition & 1 deletion tools/buildver.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5-1174
1.5-1175

0 comments on commit 566a715

Please sign in to comment.