Skip to content

Commit 3c512bd

Browse files
committed
Fixed bug in Write
1 parent 5d8c92f commit 3c512bd

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- `Write` did not return the correct amount of added characters
12+
913
## [0.6.0] - 2022-12-28
1014

1115
### Added
@@ -14,7 +18,7 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
1418

1519
## [0.5.3] - 2022-12-28
1620

17-
\### Changed
21+
### Changed
1822

1923
- Smaller internal refactorings
2024

stringbuilder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (s *StringBuilder) Replace(oldValue string, newValue string) {
188188
func (s *StringBuilder) Write(p []byte) (int, error) {
189189
before := s.Len()
190190
s.Append(string(p))
191-
delta := before - s.Len()
191+
delta := s.Len() - before
192192

193193
return delta, nil
194194
}

stringbuilder_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ func TestWrite(t *testing.T) {
348348
}
349349
}
350350

351+
func TestWriteReturnsAddedAmount(t *testing.T) {
352+
s := &StringBuilder{}
353+
354+
if got, _ := fmt.Fprintf(s, "%v", "Hello"); got != 5 {
355+
t.Errorf("StringBuilder.Write() = %v, want %v", got, 5)
356+
}
357+
}
358+
351359
func slicesEqual(a []int, b []int) bool {
352360
if len(a) != len(b) {
353361
return false

0 commit comments

Comments
 (0)