Esempio n. 1
0
/*
doReadWrite test reading and writing the DSV data.
*/
func doReadWrite(t *testing.T, dsvReader *dsv.Reader, dsvWriter *dsv.Writer,
	expectation []string, check bool) {
	var got string
	i := 0

	for {
		n, e := dsv.Read(dsvReader)

		if e == io.EOF {
			_, e = dsvWriter.Write(dsvReader)
			if e != nil {
				t.Fatal(e)
			}

			break
		}

		if e != nil {
			continue
		}

		if n > 0 {
			if check {
				ds := dsvReader.GetDataset().(tabula.DatasetInterface)
				data := ds.GetData()

				switch data.(type) {
				case *tabula.Rows:
					rows := data.(*tabula.Rows)
					got = fmt.Sprint(*rows)
				case *tabula.Columns:
					cols := data.(*tabula.Columns)
					got = fmt.Sprint(*cols)
				case *tabula.Matrix:
					matrix := data.(*tabula.Matrix)
					got = fmt.Sprint(*matrix)
				default:
					fmt.Println("data type unknown")
				}
				assert(t, expectation[i], got, true)
				i++
			}

			_, e = dsvWriter.Write(dsvReader)
			if e != nil {
				t.Fatal(e)
			}
		}
	}

	e := dsvWriter.Flush()
	if e != nil {
		t.Fatal(e)
	}
}
Esempio n. 2
0
/*
doRead test reading the DSV data.
*/
func doRead(t *testing.T, dsvReader *dsv.Reader, exp []string) {
	i := 0
	n := 0
	e := error(nil)

	for {
		n, e = dsv.Read(dsvReader)

		if n > 0 {
			r := fmt.Sprint(dsvReader.
				GetDataset().(tabula.DatasetInterface).
				GetDataAsRows())

			assert(t, exp[i], r, true)

			i++
		} else if e == io.EOF {
			// EOF
			break
		}
	}
}