mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Handles keys that dont exit
This commit is contained in:
parent
d1c545cca0
commit
690442d02e
@ -30,6 +30,8 @@ func recurse(value interface{}, head string, tail []string) interface{} {
|
|||||||
log.Fatalf("Error accessing array: %v", err)
|
log.Fatalf("Error accessing array: %v", err)
|
||||||
}
|
}
|
||||||
return readArray(value.([]interface{}), index, tail)
|
return readArray(value.([]interface{}), index, tail)
|
||||||
|
case nil:
|
||||||
|
return nil
|
||||||
default:
|
default:
|
||||||
return readMap(value.(map[interface{}]interface{}), head, tail)
|
return readMap(value.(map[interface{}]interface{}), head, tail)
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,15 @@ func TestReadMap_simple(t *testing.T) {
|
|||||||
assertResult(t, 2, readMap(parsedData, "b", []string{"c"}))
|
assertResult(t, 2, readMap(parsedData, "b", []string{"c"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadMap_array(t *testing.T) {
|
func TestReadMap_key_doesnt_exist(t *testing.T) {
|
||||||
|
assertResult(t, nil, readMap(parsedData, "b.x.f", []string{"c"}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadMap_with_array(t *testing.T) {
|
||||||
assertResult(t, 4, readMap(parsedData, "b", []string{"d", "1"}))
|
assertResult(t, 4, readMap(parsedData, "b", []string{"d", "1"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadMap_array_out_of_bounds(t *testing.T) {
|
func TestReadMap_with_array_out_of_bounds(t *testing.T) {
|
||||||
assertResult(t, nil, readMap(parsedData, "b", []string{"d", "3"}))
|
assertResult(t, nil, readMap(parsedData, "b", []string{"d", "3"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user