Пример #1
0
func TestValueAtPathSuccess(t *testing.T) {
	assert.Equal(t, []interface{}{"initial"}, awsutil.ValuesAtPath(data, "C"))
	assert.Equal(t, []interface{}{"value1"}, awsutil.ValuesAtPath(data, "A[0].C"))
	assert.Equal(t, []interface{}{"value2"}, awsutil.ValuesAtPath(data, "A[1].C"))
	assert.Equal(t, []interface{}{"value3"}, awsutil.ValuesAtPath(data, "A[2].C"))
	assert.Equal(t, []interface{}{"value3"}, awsutil.ValuesAtAnyPath(data, "a[2].c"))
	assert.Equal(t, []interface{}{"value3"}, awsutil.ValuesAtPath(data, "A[-1].C"))
	assert.Equal(t, []interface{}{"value1", "value2", "value3"}, awsutil.ValuesAtPath(data, "A[].C"))
	assert.Equal(t, []interface{}{"terminal"}, awsutil.ValuesAtPath(data, "B . B . C"))
	assert.Equal(t, []interface{}{"terminal", "terminal2"}, awsutil.ValuesAtPath(data, "B.*.C"))
	assert.Equal(t, []interface{}{"initial"}, awsutil.ValuesAtPath(data, "A.D.X || C"))
}
Пример #2
0
func TestValueAtPathFailure(t *testing.T) {
	assert.Equal(t, []interface{}(nil), awsutil.ValuesAtPath(data, "C.x"))
	assert.Equal(t, []interface{}(nil), awsutil.ValuesAtPath(data, ".x"))
	assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(data, "X.Y.Z"))
	assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(data, "A[100].C"))
	assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(data, "A[3].C"))
	assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(data, "B.B.C.Z"))
	assert.Equal(t, []interface{}(nil), awsutil.ValuesAtPath(data, "z[-1].C"))
	assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(nil, "A.B.C"))
}