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:
6
TODO.md
6
TODO.md
@@ -1,17 +1,11 @@
|
|||||||
## Fixes to be implemented
|
## Fixes to be implemented
|
||||||
|
|
||||||
- catch rows with less fields as headers and fill them up to avoid
|
|
||||||
a panic
|
|
||||||
|
|
||||||
## Features to be implemented
|
## Features to be implemented
|
||||||
|
|
||||||
- ability to change sort order (ascending vs descending)
|
- ability to change sort order (ascending vs descending)
|
||||||
|
|
||||||
- sorting by: numerical, time, duration, string(default)
|
- sorting by: numerical, time, duration, string(default)
|
||||||
|
|
||||||
- allow regexp in -c like: `-c N.*,ST,8` which means, match "NAME",
|
|
||||||
"NAMESPACE", "STATUS", 8th Header
|
|
||||||
|
|
||||||
- add output modes yaml and csv
|
- add output modes yaml and csv
|
||||||
|
|
||||||
- add --no-headers option
|
- add --no-headers option
|
||||||
|
|||||||
@@ -105,6 +105,12 @@ func parseFile(input io.Reader, pattern string) (Tabdata, error) {
|
|||||||
|
|
||||||
idx++
|
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)
|
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