mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
catch incomplete rows and fill them with empty string[s]
This commit is contained in:
@@ -105,6 +105,12 @@ func parseFile(input io.Reader, pattern string) (Tabdata, error) {
|
||||
|
||||
idx++
|
||||
}
|
||||
|
||||
// fill up missing fields, if any
|
||||
for i := len(values); i < len(data.headers); i++ {
|
||||
values = append(values, "")
|
||||
}
|
||||
|
||||
data.entries = append(data.entries, values)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,3 +110,41 @@ asd igig cxxxncnc
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParserIncompleteRows(t *testing.T) {
|
||||
data := Tabdata{
|
||||
maxwidthHeader: 5,
|
||||
maxwidthPerCol: []int{
|
||||
5, 5, 1,
|
||||
},
|
||||
columns: 3,
|
||||
headers: []string{
|
||||
"ONE", "TWO", "THREE",
|
||||
},
|
||||
entries: [][]string{
|
||||
{
|
||||
"asd", "igig", "",
|
||||
},
|
||||
{
|
||||
"19191", "EDD 1", "X",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
table := `ONE TWO THREE
|
||||
asd igig
|
||||
19191 EDD 1 X`
|
||||
|
||||
readFd := strings.NewReader(table)
|
||||
gotdata, err := parseFile(readFd, "")
|
||||
Separator = DefaultSeparator
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Parser returned error: %s\nData processed so far: %+v", err, gotdata)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(data, gotdata) {
|
||||
t.Errorf("Parser returned invalid data, Regex: %s\nExp: %+v\nGot: %+v\n",
|
||||
Separator, data, gotdata)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user