diff --git a/d2chaos/d2chaos.go b/d2chaos/d2chaos.go index 42445a974..337ac24ae 100644 --- a/d2chaos/d2chaos.go +++ b/d2chaos/d2chaos.go @@ -269,7 +269,7 @@ func (gs *dslGenState) randStr(n int, inKey bool) string { func (gs *dslGenState) randShape() string { for { s := shapes[gs.rand.Intn(len(shapes))] - if s != d2target.ShapeImage { + if s != d2target.ShapeImage && s != d2target.ShapeText { return s } } diff --git a/d2ir/compile.go b/d2ir/compile.go index 273637a9d..c147daf36 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -991,7 +991,7 @@ func (c *compiler) compileEdges(refctx *RefContext) { func (c *compiler) _compileEdges(refctx *RefContext) { eida := NewEdgeIDs(refctx.Key) for i, eid := range eida { - if refctx.Key != nil && refctx.Key.Value.Null != nil { + if !eid.Glob && (refctx.Key.Primary.Null != nil || refctx.Key.Value.Null != nil) { refctx.ScopeMap.DeleteEdge(eid) continue } @@ -1009,6 +1009,10 @@ func (c *compiler) _compileEdges(refctx *RefContext) { continue } for _, e := range ea { + if refctx.Key.Primary.Null != nil || refctx.Key.Value.Null != nil { + refctx.ScopeMap.DeleteEdge(e.ID) + continue + } e.References = append(e.References, &EdgeReference{ Context_: refctx, DueToGlob_: len(c.globRefContextStack) > 0, diff --git a/d2ir/pattern_test.go b/d2ir/pattern_test.go index 941db0785..a8a835f2c 100644 --- a/d2ir/pattern_test.go +++ b/d2ir/pattern_test.go @@ -310,6 +310,18 @@ layers.x: { wrapper.p } assertQuery(t, m, 0, 0, nil, "layers.x.wrapper.p") }, }, + { + name: "edge-glob-null", + run: func(t testing.TB) { + m, err := compile(t, `a -> b +(* -> *)[*]: null +x -> y +`) + assert.Success(t, err) + // 4 fields and 0 edges + assertQuery(t, m, 4, 0, nil, "") + }, + }, { name: "double-glob/edge/1", run: func(t testing.TB) { diff --git a/testdata/d2ir/TestCompile/patterns/edge-glob-null.exp.json b/testdata/d2ir/TestCompile/patterns/edge-glob-null.exp.json new file mode 100644 index 000000000..a61325deb --- /dev/null +++ b/testdata/d2ir/TestCompile/patterns/edge-glob-null.exp.json @@ -0,0 +1,473 @@ +{ + "fields": [ + { + "name": "a", + "references": [ + { + "string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + }, + "key_path": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "context": { + "edge": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + }, + "key": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "edges": [ + { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": "b", + "references": [ + { + "string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + }, + "key_path": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "context": { + "edge": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + }, + "key": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "edges": [ + { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": "x", + "references": [ + { + "string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + }, + "key": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "edges": [ + { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": "y", + "references": [ + { + "string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + }, + "key_path": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "context": { + "edge": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + }, + "key": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "edges": [ + { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + } + ], + "edges": [] +}