95 lines
2.1 KiB
Go
95 lines
2.1 KiB
Go
|
|
package d2ir_test
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"oss.terrastruct.com/util-go/assert"
|
||
|
|
)
|
||
|
|
|
||
|
|
func testCompilePatterns(t *testing.T) {
|
||
|
|
t.Parallel()
|
||
|
|
|
||
|
|
tca := []testCase{
|
||
|
|
{
|
||
|
|
name: "prefix",
|
||
|
|
run: func(t testing.TB) {
|
||
|
|
m, err := compile(t, `animal: meow
|
||
|
|
action: yes
|
||
|
|
a*: globbed`)
|
||
|
|
assert.Success(t, err)
|
||
|
|
assertQuery(t, m, 2, 0, nil, "")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", "animal")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", "action")
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "suffix",
|
||
|
|
run: func(t testing.TB) {
|
||
|
|
m, err := compile(t, `animal: meow
|
||
|
|
jingle: loud
|
||
|
|
*l: globbed`)
|
||
|
|
assert.Success(t, err)
|
||
|
|
assertQuery(t, m, 2, 0, nil, "")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", "animal")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", "jingle")
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "prefix-suffix",
|
||
|
|
run: func(t testing.TB) {
|
||
|
|
m, err := compile(t, `tinker: meow
|
||
|
|
thinker: yes
|
||
|
|
t*r: globbed`)
|
||
|
|
assert.Success(t, err)
|
||
|
|
assertQuery(t, m, 2, 0, nil, "")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", "tinker")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", "thinker")
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "prefix-suffix/2",
|
||
|
|
run: func(t testing.TB) {
|
||
|
|
m, err := compile(t, `tinker: meow
|
||
|
|
thinker: yes
|
||
|
|
t*ink*r: globbed`)
|
||
|
|
assert.Success(t, err)
|
||
|
|
assertQuery(t, m, 2, 0, nil, "")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", "tinker")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", "thinker")
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "prefix-suffix/3",
|
||
|
|
run: func(t testing.TB) {
|
||
|
|
m, err := compile(t, `tinkertinker: meow
|
||
|
|
thinkerthinker: yes
|
||
|
|
t*ink*r*t*inke*: globbed`)
|
||
|
|
assert.Success(t, err)
|
||
|
|
assertQuery(t, m, 2, 0, nil, "")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", "tinkertinker")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", "thinkerthinker")
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "escaped",
|
||
|
|
run: func(t testing.TB) {
|
||
|
|
m, err := compile(t, `animal: meow
|
||
|
|
action: yes
|
||
|
|
a\*: globbed`)
|
||
|
|
assert.Success(t, err)
|
||
|
|
assertQuery(t, m, 3, 0, nil, "")
|
||
|
|
assertQuery(t, m, 0, 0, "meow", "animal")
|
||
|
|
assertQuery(t, m, 0, 0, "yes", "action")
|
||
|
|
assertQuery(t, m, 0, 0, "globbed", `a\*`)
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
runa(t, tca)
|
||
|
|
|
||
|
|
t.Run("errors", func(t *testing.T) {
|
||
|
|
tca := []testCase{}
|
||
|
|
runa(t, tca)
|
||
|
|
})
|
||
|
|
}
|