d2ir: Make double globs work sanely across boards
See test.
This commit is contained in:
parent
9c37d6dcfb
commit
6fdf4b07a5
6 changed files with 5284 additions and 3 deletions
|
|
@ -747,6 +747,15 @@ func (kp *KeyPath) Copy() *KeyPath {
|
||||||
return &kp2
|
return &kp2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (kp *KeyPath) HasDoubleGlob() bool {
|
||||||
|
for _, el := range kp.Path {
|
||||||
|
if el.ScalarString() == "**" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
type Edge struct {
|
type Edge struct {
|
||||||
Range Range `json:"range"`
|
Range Range `json:"range"`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1084,11 +1084,15 @@ func (m *Map) createEdge(eid *EdgeID, refctx *RefContext, ea *[]*Edge) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// If either has a double glob at the end we only select leafs, those without children.
|
if srcKP.HasDoubleGlob() || dstKP.HasDoubleGlob() {
|
||||||
if srcKP.Path[len(srcKP.Path)-1].ScalarString() == "**" || dstKP.Path[len(dstKP.Path)-1].ScalarString() == "**" {
|
// If either has a double glob we only select leafs, those without children.
|
||||||
if src.Map().IsContainer() || dst.Map().IsContainer() {
|
if src.Map().IsContainer() || dst.Map().IsContainer() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// If either has a double glob we ignore connections across boards
|
||||||
|
if ParentBoard(src) != ParentBoard(dst) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eid2 := eid.Copy()
|
eid2 := eid.Copy()
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,9 @@ func (m *Map) doubleGlob(pattern []string) ([]*Field, bool) {
|
||||||
func (m *Map) _doubleGlob(fa *[]*Field) {
|
func (m *Map) _doubleGlob(fa *[]*Field) {
|
||||||
for _, f := range m.Fields {
|
for _, f := range m.Fields {
|
||||||
if _, ok := d2graph.ReservedKeywords[f.Name]; ok {
|
if _, ok := d2graph.ReservedKeywords[f.Name]; ok {
|
||||||
continue
|
if _, ok := d2graph.BoardKeywords[f.Name]; !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*fa = append(*fa, f)
|
*fa = append(*fa, f)
|
||||||
if f.Map() != nil {
|
if f.Map() != nil {
|
||||||
|
|
|
||||||
|
|
@ -257,6 +257,34 @@ Spiderman 3
|
||||||
assertQuery(t, m, 0, 0, "arrow", "(* -> *)[*]")
|
assertQuery(t, m, 0, 0, "arrow", "(* -> *)[*]")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "scenarios",
|
||||||
|
run: func(t testing.TB) {
|
||||||
|
m, err := compile(t, `
|
||||||
|
|
||||||
|
scenarios: {
|
||||||
|
meow: {
|
||||||
|
e
|
||||||
|
f
|
||||||
|
g
|
||||||
|
h
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
d
|
||||||
|
|
||||||
|
**: something
|
||||||
|
** -> **
|
||||||
|
`)
|
||||||
|
assert.Success(t, err)
|
||||||
|
assertQuery(t, m, 10, 24, nil, "")
|
||||||
|
assertQuery(t, m, 0, 0, "something", "**")
|
||||||
|
assertQuery(t, m, 0, 0, nil, "(* -> *)[*]")
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
runa(t, tca)
|
runa(t, tca)
|
||||||
|
|
|
||||||
1375
testdata/d2ir/TestCompile/layers/errs/3/bad_edge.exp.json
generated
vendored
Normal file
1375
testdata/d2ir/TestCompile/layers/errs/3/bad_edge.exp.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
3863
testdata/d2ir/TestCompile/patterns/scenarios.exp.json
generated
vendored
Normal file
3863
testdata/d2ir/TestCompile/patterns/scenarios.exp.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue