2023-07-29 22:09:29 +00:00
|
|
|
package d2ir_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"oss.terrastruct.com/util-go/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func testCompileFilters(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
tca := []testCase{
|
|
|
|
|
{
|
2023-07-29 23:32:30 +00:00
|
|
|
name: "base",
|
2023-07-29 22:09:29 +00:00
|
|
|
run: func(t testing.TB) {
|
|
|
|
|
m, err := compile(t, `jacob: {
|
|
|
|
|
shape: circle
|
|
|
|
|
}
|
|
|
|
|
jeremy: {
|
|
|
|
|
shape: rectangle
|
|
|
|
|
}
|
|
|
|
|
*: {
|
|
|
|
|
&shape: rectangle
|
|
|
|
|
label: I'm a rectangle
|
|
|
|
|
}`)
|
|
|
|
|
assert.Success(t, err)
|
|
|
|
|
assertQuery(t, m, 1, 0, nil, "jacob")
|
2023-07-29 23:32:30 +00:00
|
|
|
assertQuery(t, m, 2, 0, nil, "jeremy")
|
|
|
|
|
assertQuery(t, m, 0, 0, "I'm a rectangle", "jeremy.label")
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "order",
|
|
|
|
|
run: func(t testing.TB) {
|
|
|
|
|
m, err := compile(t, `jacob: {
|
|
|
|
|
shape: circle
|
|
|
|
|
}
|
|
|
|
|
jeremy: {
|
|
|
|
|
shape: rectangle
|
|
|
|
|
}
|
|
|
|
|
*: {
|
|
|
|
|
label: I'm a rectangle
|
|
|
|
|
&shape: rectangle
|
|
|
|
|
}`)
|
|
|
|
|
assert.Success(t, err)
|
|
|
|
|
assertQuery(t, m, 1, 0, nil, "jacob")
|
|
|
|
|
assertQuery(t, m, 2, 0, nil, "jeremy")
|
2023-07-29 22:09:29 +00:00
|
|
|
assertQuery(t, m, 0, 0, "I'm a rectangle", "jeremy.label")
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runa(t, tca)
|
|
|
|
|
}
|