Skip to content

Commit

Permalink
record: tests that arrays and objects are correctly parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
vrischmann committed Dec 28, 2016
1 parent 7c486a6 commit 6ca5d84
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions record/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,30 @@ func TestFindUnexistingField(t *testing.T) {
assert.NotNil(t, err)
}

func TestFindNotAConstField(t *testing.T) {
func TestFindArrayField(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)
c, err := r.Find(ch.NewField("a"))
require.Nil(t, err)
require.NotNil(t, c)

_, err = r.Find(ch.NewField("a"))
assert.NotNil(t, err)
require.True(t, c.IsString())
require.Equal(t, `[]`, c.AsString())
}

func TestFindObjectField(t *testing.T) {
r, err := NewJSONRecordFromDecoder(testJSONDecoder())
require.Nil(t, err)
require.NotNil(t, r)

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

require.True(t, c.IsString())
require.Equal(t, `{"need": {"to": {"go": {"deeper": 1, "a": "d"}}}}`, c.AsString())
}

func TestFindTopLevelStringField(t *testing.T) {
Expand Down

0 comments on commit 6ca5d84

Please sign in to comment.