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) }
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()) }
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()) }
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()) }
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) }
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) }
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()) }
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()) }
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()) }
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()) }
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()) }
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()) }
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()) }
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()) }