diff --git a/test/cases/testdata/subset/test-subset.yaml b/test/cases/testdata/subset/test-subset.yaml index 91c15b3ea3..336db7c971 100644 --- a/test/cases/testdata/subset/test-subset.yaml +++ b/test/cases/testdata/subset/test-subset.yaml @@ -384,5 +384,55 @@ cases: note: subset/array and set 2 query: data.test.test_result = x + want_result: + - x: true + + - data: + modules: + - | + package test + + A := [1,2,3,4,5,6] + B := [4,5,6,8] + + AsubB := object.subset(A, B) + BsubA := object.subset(B, A) + + # Notice that there isn't really a well-defined way to "match" the two + # nested sets to one another, so we B is not a subset of A in this + # case. + + test_result { + not AsubB # B is not a subset of A + not BsubA # A is not a subset of B + } + + note: subset/arrays 5 + query: data.test.test_result = x + want_result: + - x: true + + - data: + modules: + - | + package test + + A := [1,2,3,4,5,6] + B := [8,9,10] + + AsubB := object.subset(A, B) + BsubA := object.subset(B, A) + + # Notice that there isn't really a well-defined way to "match" the two + # nested sets to one another, so we B is not a subset of A in this + # case. + + test_result { + not AsubB # B is not a subset of A + not BsubA # A is not a subset of B + } + + note: subset/arrays 6 + query: data.test.test_result = x want_result: - x: true \ No newline at end of file diff --git a/topdown/subset.go b/topdown/subset.go index 19c6571c02..7b152a5ef9 100644 --- a/topdown/subset.go +++ b/topdown/subset.go @@ -193,12 +193,12 @@ func arraySubset(super, sub *ast.Array) bool { return true } - if superCursor == super.Len() { + if superCursor+subCursor == super.Len() { return false } subElem := sub.Elem(subCursor) - superElem := sub.Elem(superCursor + subCursor) + superElem := super.Elem(superCursor + subCursor) if superElem == nil { return false }