Exemplo n.º 1
0
func TestFindNotAConstField(t *testing.T) {
	r, err := NewJSONRecordFromDecoder(testJSONDecoder())
	require.Nil(t, err)
	require.NotNil(t, r)

	_, err = r.Find(ch.NewField("we"))
	assert.NotNil(t, err)

	_, err = r.Find(ch.NewField("a"))
	assert.NotNil(t, err)
}
Exemplo n.º 2
0
func TestJSONRecordTopLevelSoftFind(t *testing.T) {
	rec, err := NewJSONRecordFromDecoder(json.NewDecoder(strings.NewReader(`{"foo":42}`)))
	require.Nil(t, err)
	require.NotNil(t, rec)

	_, err = rec.Find(ch.NewField("yo"))
	assert.NotNil(t, err)

	rec.SoftMatching = true
	v, err := rec.Find(ch.NewField("yo"))
	assert.Nil(t, err)
	assert.True(t, v.IsNull())
}
Exemplo n.º 3
0
func TestFindColumnName(t *testing.T) {
	c := NewCSVRecordWithHeader([]string{"a", "b", "c"}, []string{"id", "x", "y"})
	require.NotNil(t, c)

	_, err := c.Find(ch.NewField("yo"))
	assert.NotNil(t, err)

	_, err = c.Find(ch.NewField("xy"))
	assert.NotNil(t, err)

	v, err := c.Find(ch.NewField("y"))
	assert.Nil(t, err)
	assert.Equal(t, "c", v.AsString())
}
Exemplo n.º 4
0
func TestFindColumnIndex(t *testing.T) {
	c := NewCSVRecord([]string{"a", "b", "c"})
	require.NotNil(t, c)

	_, err := c.Find(ch.NewField("$-1"))
	assert.NotNil(t, err)

	_, err = c.Find(ch.NewField("$42"))
	assert.NotNil(t, err)

	v, err := c.Find(ch.NewField("$1"))
	assert.Nil(t, err)
	assert.True(t, v.IsString())
	assert.Equal(t, "b", v.AsString())
}
Exemplo n.º 5
0
func TestFindNameWithoutHeader(t *testing.T) {
	c := NewCSVRecord([]string{"a", "b", "c"})
	require.NotNil(t, c)

	_, err := c.Find(ch.NewField("foo"))
	assert.NotNil(t, err)
}
Exemplo n.º 6
0
func TestFindUnexistingField(t *testing.T) {
	r, err := NewJSONRecordFromDecoder(testJSONDecoder())
	require.Nil(t, err)
	require.NotNil(t, r)

	_, err = r.Find(ch.NewField("yolo"))
	assert.NotNil(t, err)
}
Exemplo n.º 7
0
func TestFindStar(t *testing.T) {
	c := NewCSVRecord([]string{"x", "y", "z"})
	require.NotNil(t, c)

	v, err := c.Find(ch.NewField("*"))
	assert.Nil(t, err)
	assert.True(t, v.IsString())
	assert.Equal(t, "[x y z]", v.AsString())
}
Exemplo n.º 8
0
func TestFindTopLevelNullField(t *testing.T) {
	r, err := NewJSONRecordFromDecoder(testJSONDecoder())
	require.Nil(t, err)
	require.NotNil(t, r)

	c, err := r.Find(ch.NewField("n"))
	require.Nil(t, err)
	require.NotNil(t, c)

	assert.True(t, c.IsNull())
}
Exemplo n.º 9
0
func TestFindTopLevelEmptyStringField(t *testing.T) {
	r, err := NewJSONRecordFromDecoder(json.NewDecoder(strings.NewReader(`{"foo": ""}`)))
	require.Nil(t, err)
	require.NotNil(t, r)

	c, err := r.Find(ch.NewField("foo"))
	require.Nil(t, err)
	require.NotNil(t, c)

	assert.False(t, c.IsNull())
	assert.True(t, c.IsString())
}
Exemplo n.º 10
0
func TestFindTopLevelBoolField(t *testing.T) {
	r, err := NewJSONRecordFromDecoder(testJSONDecoder())
	require.Nil(t, err)
	require.NotNil(t, r)

	c, err := r.Find(ch.NewField("b"))
	require.Nil(t, err)
	require.NotNil(t, c)

	assert.True(t, c.IsBool())
	assert.Equal(t, true, c.AsBool())
}
Exemplo n.º 11
0
func TestFindTopLevelIntField(t *testing.T) {
	r, err := NewJSONRecordFromDecoder(testJSONDecoder())
	require.Nil(t, err)
	require.NotNil(t, r)

	c, err := r.Find(ch.NewField("age"))
	require.Nil(t, err)
	require.NotNil(t, c)

	assert.True(t, c.IsNumeric())
	assert.Equal(t, int64(92), c.AsInt())
}
Exemplo n.º 12
0
func TestFindTopLevelStringField(t *testing.T) {
	r, err := NewJSONRecordFromDecoder(testJSONDecoder())
	require.Nil(t, err)
	require.NotNil(t, r)

	c, err := r.Find(ch.NewField("name"))
	require.Nil(t, err)
	require.NotNil(t, c)

	assert.True(t, c.IsString())
	assert.Equal(t, "Michel", c.AsString())
}
Exemplo n.º 13
0
func TestFindDeepStringField(t *testing.T) {
	r, err := NewJSONRecordFromDecoder(testJSONDecoder())
	require.Nil(t, err)
	require.NotNil(t, r)

	c, err := r.Find(ch.NewField("we.need.to.go.deeper"))
	require.Nil(t, err)
	require.NotNil(t, c)

	assert.True(t, c.IsNumeric())
	assert.Equal(t, int64(1), c.AsInt())
}
Exemplo n.º 14
0
func TestJSONRecordSelectStar(t *testing.T) {
	r := json.NewDecoder(strings.NewReader(`{"foo": 42}`))
	require.NotNil(t, r)

	rec, err := NewJSONRecordFromDecoder(r)
	require.Nil(t, err)
	require.NotNil(t, rec)

	all, err := rec.Find(ch.NewField("*"))
	require.Nil(t, err)
	require.NotNil(t, all)

	require.True(t, all.IsString())
	require.Equal(t, `{"foo":42}`, all.AsString())
}