Table-driven tests define a slice of test cases containing inputs and expected outputs, then iterate over them in a single test function to run multiple scenarios. This pattern reduces code duplication and makes it easy to add new cases.
func TestParseNumeric(t *testing.T) {
vectors := []struct {
in string
want int64
ok bool
}{
{"0000000\x00", 0, true},
{"0123456789", 0, false},
}
for _, v := range vectors {
got, ok := parseNumeric(v.in)
if ok != v.ok || got != v.want {
t.Errorf("parseNumeric(%q): got (%d, %v), want (%d, %v)", v.in, got, ok, v.want, v.ok)
}
}
}