Esempio n. 1
0
func TestReaderToColumns(t *testing.T) {
	reader := &dsv.Reader{}

	e := dsv.ConfigParse(reader, []byte(jsonSample[4]))
	if nil != e {
		t.Fatal(e)
	}

	e = reader.Init("", nil)
	if nil != e {
		t.Fatal(e)
	}

	reader.SetDatasetMode(dsv.DatasetModeCOLUMNS)

	var n, i int
	for {
		n, e = dsv.Read(reader)

		if n > 0 {
			ds := reader.GetDataset().(tabula.DatasetInterface)
			ds.TransposeToRows()

			r := fmt.Sprint(ds.GetData())

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

			i++
		} else if e == io.EOF {
			// EOF
			break
		}
	}
}
Esempio n. 2
0
/*
TestConfigParse test parsing metadata.
*/
func TestConfigParse(t *testing.T) {
	cases := []struct {
		in  string
		out *dsv.Reader
	}{
		{
			jsonSample[1],
			readers[1],
		},
		{
			jsonSample[3],
			readers[3],
		},
	}

	dsvReader := &dsv.Reader{}

	for _, c := range cases {
		e := dsv.ConfigParse(dsvReader, []byte(c.in))

		if e != nil {
			t.Fatal(e)
		}
		if !dsvReader.IsEqual(c.out) {
			t.Fatal("Test failed on ", c.in)
		}
	}
}
Esempio n. 3
0
/*
TestReaderNoInput will print error that the input is not defined.
*/
func TestReaderNoInput(t *testing.T) {
	dsvReader := &dsv.Reader{}

	e := dsv.ConfigParse(dsvReader, []byte(jsonSample[0]))

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

	e = dsvReader.Init("", nil)

	if nil == e {
		t.Fatal("TestReaderNoInput: failed, should return non nil!")
	}
}
Esempio n. 4
0
func TestDatasetMode(t *testing.T) {
	var e error
	var config = []string{`{
		"Input"		:"testdata/input.dat"
	,	"DatasetMode"	:"row"
	}`, `{
		"Input"		:"testdata/input.dat"
	,	"DatasetMode"	:"rows"
	}`, `{
		"Input"		:"testdata/input.dat"
	,	"DatasetMode"	:"columns"
	}`}

	var exps = []struct {
		status bool
		value  string
	}{{
		false,
		string(config[0]),
	}, {
		true,
		string(config[1]),
	}, {
		true,
		string(config[2]),
	}}

	reader := &dsv.Reader{}

	for k, v := range exps {
		e = dsv.ConfigParse(reader, []byte(config[k]))

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

		e = reader.Init("", nil)
		if e != nil {
			if v.status == true {
				t.Fatal(e)
			}
		}
	}
}
Esempio n. 5
0
/*
TestReader test reading.
*/
func TestReaderRead(t *testing.T) {
	dsvReader := &dsv.Reader{}

	e := dsv.ConfigParse(dsvReader, []byte(jsonSample[4]))

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

	e = dsvReader.Init("", nil)
	if nil != e {
		t.Fatal(e)
	}

	doRead(t, dsvReader, expectation)

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