From 3474cd4eee82ac442618391f8bc4a70d7b1cb65a Mon Sep 17 00:00:00 2001 From: hopehook Date: Wed, 11 May 2022 22:42:00 +0800 Subject: 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 Run-TryBot: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov --- src/encoding/csv/reader_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/encoding/csv/reader_test.go') 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 -- cgit v1.3