Beispiel #1
0
func TestAddRowShouldSetProperTypeForEachColumnAndAppendValues(t *testing.T) {
	tt := New(TEST_HEADERS...)
	for nrow, data := range TEST_DATA {
		err := tt.AddRow(data...)
		assert.Nil(t, err)
		for ncol, col := range data {
			assert.IsType(t, column.NewForTypeOf(col), tt.Columns[ncol])
			assert.Equal(t, nrow+1, tt.Columns[ncol].Len())
		}
	}
}
Beispiel #2
0
func (tt *TexTable) AddRow(columns ...interface{}) error {
	if len(columns) != len(tt.Headers) {
		return getError(_ERR_INCOR_NUM_VALS, len(columns), len(tt.Headers))
	}

	for k, v := range columns {
		if tt.Columns[k] == nil {
			tt.Columns[k] = column.NewForTypeOf(v)
		}
		if err := tt.Columns[k].Append(v); err != nil {
			return err
		}
	}

	return nil
}