mirror of
https://github.com/therootcompany/golib.git
synced 2026-11-04 06:55:00 +00:00
fix gsheet reader skip empty records
This commit is contained in:
parent
07d4a2652c
commit
8a928d0e9c
@ -213,6 +213,17 @@ func (r *Reader) Read() ([]string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allEmpty := true
|
||||||
|
for _, field := range record {
|
||||||
|
if field != "" {
|
||||||
|
allEmpty = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if allEmpty {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if r.Comment > 0 {
|
if r.Comment > 0 {
|
||||||
if rv, _ := utf8.DecodeRuneInString(record[0]); rv == r.Comment {
|
if rv, _ := utf8.DecodeRuneInString(record[0]); rv == r.Comment {
|
||||||
last := len(record) - 1
|
last := len(record) - 1
|
||||||
|
|||||||
@ -131,6 +131,23 @@ func TestNewReaderFromURL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadSkipsEmptyRecords(t *testing.T) {
|
||||||
|
reader := NewReader(strings.NewReader("a,b\n,,\n\"\",\"\"\nvalue,\n"))
|
||||||
|
rows, err := reader.ReadAll()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
want := [][]string{{"a", "b"}, {"value", ""}}
|
||||||
|
if len(rows) != len(want) {
|
||||||
|
t.Fatalf("rows = %v, want %v", rows, want)
|
||||||
|
}
|
||||||
|
for i := range want {
|
||||||
|
if !slices.Equal(rows[i], want[i]) {
|
||||||
|
t.Fatalf("rows = %v, want %v", rows, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestRead tests the Read method for comment handling.
|
// TestRead tests the Read method for comment handling.
|
||||||
func TestRead(t *testing.T) {
|
func TestRead(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user