Exemple #1
0
func TestSplitNMerged(t *testing.T) {
	t.Parallel()

	var got, want []string

	want = []string{"1", "2", "3"}
	got = SplitNMerged("1 2 3", " ", -1)
	if !myoperators.EqualSlicesOfString(want, got) {
		t.Errorf("SplitNMerged(): want %v, got %v", want, got)
	}

	want = []string{"1", "2", "3"}
	got = SplitNMerged("1 2   3", " ", -1)
	if !myoperators.EqualSlicesOfString(want, got) {
		t.Errorf("SplitNMerged(): want %v, got %v", want, got)
	}

	want = []string{}
	got = SplitNMerged("", " ", -1)
	if !myoperators.EqualSlicesOfString(want, got) {
		t.Errorf("SplitNMerged(): want %v, got %v", want, got)
	}
}
Exemple #2
0
func TestSplitRow(t *testing.T) {
	var (
		s string
		c []string
	)

	ifs := " "
	cols := 0
	tc := TableConfig{commentPrefix: "#", ignoreComments: true}

	s = "1 2 3"
	c = splitRow(s, ifs, cols, &tc)
	if !myoperators.EqualSlicesOfString(c, []string{"1", "2", "3"}) {
		t.Errorf("splitRow('%v', '%v', %v) => %v", s, ifs, cols, c)
	}

	s = "# comment line"
	if l := len(splitRow(s, ifs, cols, &tc)); l != 1 {
		t.Errorf("splitRow('%v', '%v', %v): len %v", s, ifs, cols, l)
	}
}