aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/csv/reader_test.go
diff options
context:
space:
mode:
authorhopehook <hopehook.com@gmail.com>2022-05-11 22:42:00 +0800
committerGopher Robot <gobot@golang.org>2022-05-14 04:25:13 +0000
commit3474cd4eee82ac442618391f8bc4a70d7b1cb65a (patch)
treed75a58b58e37b4bad2fbeb6f4a9c28ed385dada6 /src/encoding/csv/reader_test.go
parentcb458c05a82aefb253034558b34f16dee8713274 (diff)
downloadgo-3474cd4eee82ac442618391f8bc4a70d7b1cb65a.tar.xz
encoding/csv: add Reader.InputOffset method
Fixes #43401. Change-Id: I2498e77e41d845130d95012bc8623bfb29c0dda1 Reviewed-on: https://go-review.googlesource.com/c/go/+/405675 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'src/encoding/csv/reader_test.go')
-rw-r--r--src/encoding/csv/reader_test.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/encoding/csv/reader_test.go b/src/encoding/csv/reader_test.go
index abe3fdfb39..2e5d62330c 100644
--- a/src/encoding/csv/reader_test.go
+++ b/src/encoding/csv/reader_test.go
@@ -404,7 +404,7 @@ field"`,
}}
func TestRead(t *testing.T) {
- newReader := func(tt readTest) (*Reader, [][][2]int, map[int][2]int) {
+ newReader := func(tt readTest) (*Reader, [][][2]int, map[int][2]int, string) {
positions, errPositions, input := makePositions(tt.Input)
r := NewReader(strings.NewReader(input))
@@ -420,12 +420,12 @@ func TestRead(t *testing.T) {
r.LazyQuotes = tt.LazyQuotes
r.TrimLeadingSpace = tt.TrimLeadingSpace
r.ReuseRecord = tt.ReuseRecord
- return r, positions, errPositions
+ return r, positions, errPositions, input
}
for _, tt := range readTests {
t.Run(tt.Name, func(t *testing.T) {
- r, positions, errPositions := newReader(tt)
+ r, positions, errPositions, input := newReader(tt)
out, err := r.ReadAll()
if wantErr := firstError(tt.Errors, positions, errPositions); wantErr != nil {
if !reflect.DeepEqual(err, wantErr) {
@@ -443,8 +443,15 @@ func TestRead(t *testing.T) {
}
}
+ // Check input offset after call ReadAll()
+ inputByteSize := len(input)
+ inputOffset := r.InputOffset()
+ if err == nil && int64(inputByteSize) != inputOffset {
+ t.Errorf("wrong input offset after call ReadAll():\ngot: %d\nwant: %d\ninput: %s", inputOffset, inputByteSize, input)
+ }
+
// Check field and error positions.
- r, _, _ = newReader(tt)
+ r, _, _, _ = newReader(tt)
for recNum := 0; ; recNum++ {
rec, err := r.Read()
var wantErr error