Skip to content

Commit

Permalink
Test for readArrays
Browse files Browse the repository at this point in the history
  • Loading branch information
wodesuck committed Apr 7, 2024
1 parent 92e5e26 commit 2218235
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,27 @@ func TestSplitWord(t *testing.T) {
}
}

func TestReadPairs(t *testing.T) {
func TestReadArrays(t *testing.T) {
tests := []struct {
s string
exp [][]string
s string
min_cols int
max_cols int
exp [][]string
}{
{"foo bar", [][]string{{"foo", "bar"}}},
{"foo bar ", [][]string{{"foo", "bar"}}},
{" foo bar", [][]string{{"foo", "bar"}}},
{" foo bar ", [][]string{{"foo", "bar"}}},
{"foo bar#baz", [][]string{{"foo", "bar"}}},
{"foo bar #baz", [][]string{{"foo", "bar"}}},
{`'foo#baz' bar`, [][]string{{"foo#baz", "bar"}}},
{`"foo#baz" bar`, [][]string{{"foo#baz", "bar"}}},
{"foo bar", 2, 2, [][]string{{"foo", "bar"}}},
{"foo bar ", 2, 2, [][]string{{"foo", "bar"}}},
{" foo bar", 2, 2, [][]string{{"foo", "bar"}}},
{" foo bar ", 2, 2, [][]string{{"foo", "bar"}}},
{"foo bar#baz", 2, 2, [][]string{{"foo", "bar"}}},
{"foo bar #baz", 2, 2, [][]string{{"foo", "bar"}}},
{`'foo#baz' bar`, 2, 2, [][]string{{"foo#baz", "bar"}}},
{`"foo#baz" bar`, 2, 2, [][]string{{"foo#baz", "bar"}}},
{"foo bar baz", 3, 3, [][]string{{"foo", "bar", "baz"}}},
{`"foo bar baz"`, 1, 1, [][]string{{"foo bar baz"}}},
}

for _, test := range tests {
if got, _ := readPairs(strings.NewReader(test.s)); !reflect.DeepEqual(got, test.exp) {
if got, _ := readArrays(strings.NewReader(test.s), test.min_cols, test.max_cols); !reflect.DeepEqual(got, test.exp) {
t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
}
}
Expand Down

0 comments on commit 2218235

Please sign in to comment.