Example #1
0
func TestMainOutput(t *testing.T) {
	rw, e := dsv.New(fMainTestDsv, nil)

	if e != nil {
		t.Fatal(e)
	}

	for {
		n, e := dsv.Read(&rw.Reader)

		if e == io.EOF {
			_, e = rw.Write(&rw.Reader)
			break
		}
		if n > 0 {
			_, e = rw.Write(&rw.Reader)

			if e != nil {
				t.Fatal(e)
			}
		}
	}

	e = rw.Writer.Flush()
	if e != nil {
		t.Fatal(e)
	}

	assertFile(t, rw.GetInput(), rw.GetOutput(), true)
}
Example #2
0
/*
doInit create read-write object.
*/
func doInit(t *testing.T, fcfg string) (rw *dsv.ReadWriter, e error) {
	// Initialize dsv
	rw, e = dsv.New(fcfg, nil)

	if nil != e {
		t.Fatal(e)
	}

	return
}
Example #3
0
/*
TestWriterWithSkip test reading and writing DSV with some column in input being
skipped.
*/
func TestWriterWithSkip(t *testing.T) {
	rw, e := dsv.New("testdata/config_skip.dsv", nil)
	if e != nil {
		t.Fatal(e)
	}

	doReadWrite(t, &rw.Reader, &rw.Writer, expSkip, true)

	e = rw.Close()
	if e != nil {
		t.Fatal(e)
	}

	assertFile(t, rw.GetOutput(), "testdata/expected_skip.dat", true)
}
Example #4
0
/*
TestWriterWithColumns test reading and writing DSV with where each row
is saved in DatasetMode = 'columns'.
*/
func TestWriterWithColumns(t *testing.T) {
	rw, e := dsv.New("testdata/config_skip.dsv", nil)
	if e != nil {
		t.Fatal(e)
	}

	rw.SetDatasetMode(dsv.DatasetModeCOLUMNS)

	doReadWrite(t, &rw.Reader, &rw.Writer, expSkipColumns, true)

	e = rw.Close()
	if e != nil {
		t.Fatal(e)
	}

	assertFile(t, "testdata/expected_skip.dat", rw.GetOutput(), true)
}