Skip to content

Commit a95ddc1

Browse files
committed
Trim line endings properly on Windows for LineIter
1 parent e26c2ae commit a95ddc1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

internal/assert/assert.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,46 @@ package assert
33
import "testing"
44

55
func Equal[T comparable](t *testing.T, a, b T) {
6+
t.Helper()
7+
68
if a != b {
79
t.Errorf("expected `%v` to equal `%v`", a, b)
810
}
911
}
1012

1113
func True(t *testing.T, b bool) {
14+
t.Helper()
15+
1216
if !b {
1317
t.Error("expected `false` to be `true`")
1418
}
1519
}
1620

1721
func False(t *testing.T, b bool) {
22+
t.Helper()
23+
1824
if b {
1925
t.Error("expected `true` to be `false`")
2026
}
2127
}
2228

2329
func Nil(t *testing.T, v interface{}) {
30+
t.Helper()
31+
2432
Equal(t, v, nil)
2533
}
2634

2735
func NotNil(t *testing.T, v interface{}) {
36+
t.Helper()
37+
2838
if v == nil {
2939
t.Error("expected `nil` not to equal `nil`")
3040
}
3141
}
3242

3343
func SliceEqual[T comparable](t *testing.T, a, b []T) {
44+
t.Helper()
45+
3446
if len(a) != len(b) {
3547
t.Errorf("expected `%v` to equal `%v` but lengths differ", a, b)
3648
return
@@ -44,6 +56,8 @@ func SliceEqual[T comparable](t *testing.T, a, b []T) {
4456
}
4557

4658
func Empty[T any](t *testing.T, items []T) {
59+
t.Helper()
60+
4761
if len(items) != 0 {
4862
t.Errorf("expected `%v` to be empty", items)
4963
}

iter/lines.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package iter
22

33
import (
44
"bufio"
5+
"bytes"
56
"fmt"
67
"io"
78

@@ -44,7 +45,7 @@ func (iter *LinesIter) Next() option.Option[result.Result[[]byte]] {
4445
return option.Some(result.Err[[]byte](fmt.Errorf(`read line: %w`, err)))
4546
}
4647

47-
return option.Some(result.Ok(content[:len(content)-1]))
48+
return option.Some(result.Ok(bytes.TrimRight(content, "\r\n")))
4849
}
4950

5051
var _ Iterator[result.Result[[]byte]] = new(LinesIter)

0 commit comments

Comments
 (0)