From 42358c2b081d43e64ddddbdf1423a016d80c033b Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 29 Apr 2025 09:40:45 -0600 Subject: [PATCH] d2oracle: UpdateImport --- d2oracle/edit.go | 103 +++++ d2oracle/edit_test.go | 201 +++++++++ .../TestUpdateImport/mixed_imports.exp.json | 397 +++++++++++++++++ .../multiple_imports.exp.json | 416 ++++++++++++++++++ .../TestUpdateImport/nested_import.exp.json | 337 ++++++++++++++ .../no_matching_import.exp.json | 262 +++++++++++ .../TestUpdateImport/remove_import.exp.json | 177 ++++++++ .../remove_nested_import.exp.json | 252 +++++++++++ .../remove_spread_import.exp.json | 177 ++++++++ .../TestUpdateImport/update_import.exp.json | 262 +++++++++++ .../update_import_with_dir.exp.json | 262 +++++++++++ .../update_spread_import.exp.json | 243 ++++++++++ 12 files changed, 3089 insertions(+) create mode 100644 testdata/d2oracle/TestUpdateImport/mixed_imports.exp.json create mode 100644 testdata/d2oracle/TestUpdateImport/multiple_imports.exp.json create mode 100644 testdata/d2oracle/TestUpdateImport/nested_import.exp.json create mode 100644 testdata/d2oracle/TestUpdateImport/no_matching_import.exp.json create mode 100644 testdata/d2oracle/TestUpdateImport/remove_import.exp.json create mode 100644 testdata/d2oracle/TestUpdateImport/remove_nested_import.exp.json create mode 100644 testdata/d2oracle/TestUpdateImport/remove_spread_import.exp.json create mode 100644 testdata/d2oracle/TestUpdateImport/update_import.exp.json create mode 100644 testdata/d2oracle/TestUpdateImport/update_import_with_dir.exp.json create mode 100644 testdata/d2oracle/TestUpdateImport/update_spread_import.exp.json diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 6256403d4..18447fed9 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -3324,3 +3324,106 @@ func filterReservedPath(path []*d2ast.StringBox) (filtered []*d2ast.StringBox) { } return } + +func UpdateImport(g *d2graph.Graph, boardPath []string, path string, newPath *string) (_ *d2graph.Graph, err error) { + if newPath == nil { + defer xdefer.Errorf(&err, "failed to remove import %#v", path) + } else { + defer xdefer.Errorf(&err, "failed to update import from %#v to %#v", path, *newPath) + } + + boardG := g + baseAST := g.AST + + if len(boardPath) > 0 { + // When compiling a nested board, we can read from boardG but only write to baseBoardG + boardG = GetBoardGraph(g, boardPath) + if boardG == nil { + return nil, fmt.Errorf("board %v not found", boardPath) + } + // TODO beter name + baseAST = boardG.BaseAST + if baseAST == nil { + return nil, fmt.Errorf("board %v cannot be modified through this file", boardPath) + } + } + + _updateImport(boardG, baseAST, path, newPath) + + if len(boardPath) > 0 { + replaced := ReplaceBoardNode(g.AST, baseAST, boardPath) + if !replaced { + return nil, fmt.Errorf("board %v AST not found", boardPath) + } + } + + return recompile(g) +} + +func _updateImport(g *d2graph.Graph, m *d2ast.Map, oldPath string, newPath *string) { + for i := 0; i < len(m.Nodes); i++ { + node := m.Nodes[i] + + if node.Import != nil { + if node.Import.PathWithPre() == oldPath { + if newPath == nil { + if node.Import.Spread { + m.Nodes = append(m.Nodes[:i], m.Nodes[i+1:]...) + i-- + } else { + node.Import = nil + } + } else { + updateImportPath(node.Import, *newPath) + } + continue + } + } + + if node.MapKey != nil { + if node.MapKey.Value.Import != nil { + if node.MapKey.Value.Import.PathWithPre() == oldPath { + if newPath == nil { + if node.MapKey.Value.Import.Spread && node.MapKey.Value.Map == nil { + m.Nodes = append(m.Nodes[:i], m.Nodes[i+1:]...) + i-- + } else { + node.MapKey.Value.Import = nil + } + } else { + updateImportPath(node.MapKey.Value.Import, *newPath) + } + } + } + + primaryImport := node.MapKey.Primary.Unbox() + if primaryImport != nil { + value, ok := primaryImport.(d2ast.Value) + if ok { + importBox := d2ast.MakeValueBox(value) + if importBox.Import != nil && importBox.Import.PathWithPre() == oldPath { + if newPath == nil { + node.MapKey.Primary = d2ast.ScalarBox{} + } else { + updateImportPath(importBox.Import, *newPath) + } + } + } + } + + if node.MapKey.Value.Map != nil { + _updateImport(g, node.MapKey.Value.Map, oldPath, newPath) + } + } + } +} + +func updateImportPath(imp *d2ast.Import, newPath string) { + if len(imp.Path) > 0 { + imp.Path[0] = d2ast.MakeValueBox(d2ast.RawString(newPath, true)).StringBox() + } else { + imp.Path = []*d2ast.StringBox{ + d2ast.MakeValueBox(d2ast.RawString(newPath, true)).StringBox(), + } + } +} diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index 94d103615..e860d558c 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -9597,3 +9597,204 @@ scenarios: { }) } } + +func TestUpdateImport(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + boardPath []string + text string + fsTexts map[string]string + path string + newPath *string + + expErr string + exp string + assertions func(t *testing.T, g *d2graph.Graph) + }{ + { + name: "remove_import", + text: `x: @meow +y +`, + fsTexts: map[string]string{ + "meow.d2": "k", + }, + path: "meow", + newPath: nil, + exp: `x +y +`, + }, + { + name: "remove_spread_import", + text: `x +...@meow +y`, + fsTexts: map[string]string{ + "meow.d2": "k", + }, + path: "meow", + newPath: nil, + exp: `x + +y +`, + }, + { + name: "update_import", + text: `x: @meow +y +`, + fsTexts: map[string]string{ + "meow.d2": "k", + "woof.d2": "k", + }, + path: "meow", + newPath: go2.Pointer("woof"), + exp: `x: @woof +y +`, + }, + { + name: "update_import_with_dir", + text: `x: @foo/meow +y +`, + fsTexts: map[string]string{ + "foo/meow.d2": "k", + "bar/woof.d2": "k", + }, + path: "foo/meow", + newPath: go2.Pointer("bar/woof"), + exp: `x: @bar/woof +y +`, + }, + { + name: "update_spread_import", + text: `x +...@meow +y +`, + fsTexts: map[string]string{ + "meow.d2": "k", + "woof.d2": "k", + }, + path: "meow", + newPath: go2.Pointer("woof"), + exp: `x +...@woof +y +`, + }, + { + name: "no_matching_import", + text: `x: @cat +y +`, + fsTexts: map[string]string{ + "cat.d2": "k", + }, + path: "meow", + newPath: go2.Pointer("woof"), + exp: `x: @cat +y +`, + }, + { + name: "nested_import", + text: `container: { + x: @meow + y +} +`, + fsTexts: map[string]string{ + "meow.d2": "k", + "woof.d2": "k", + }, + path: "meow", + newPath: go2.Pointer("woof"), + exp: `container: { + x: @woof + y +} +`, + }, + { + name: "remove_nested_import", + text: `container: { + x: @meow + y +} +`, + fsTexts: map[string]string{ + "meow.d2": "k", + }, + path: "meow", + newPath: nil, + exp: `container: { + x + y +} +`, + }, + { + name: "multiple_imports", + text: `x: @meow +y: @meow +z +`, + fsTexts: map[string]string{ + "meow.d2": "k", + "woof.d2": "k", + }, + path: "meow", + newPath: go2.Pointer("woof"), + exp: `x: @woof +y: @woof +z +`, + }, + { + name: "mixed_imports", + text: `x: @meow +y +...@meow +z +`, + fsTexts: map[string]string{ + "meow.d2": "k", + "woof.d2": "k", + }, + path: "meow", + newPath: go2.Pointer("woof"), + exp: `x: @woof +y +...@woof +z +`, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + et := editTest{ + text: tc.text, + fsTexts: tc.fsTexts, + testFunc: func(g *d2graph.Graph) (*d2graph.Graph, error) { + return d2oracle.UpdateImport(g, tc.boardPath, tc.path, tc.newPath) + }, + + exp: tc.exp, + expErr: tc.expErr, + assertions: tc.assertions, + } + et.run(t) + }) + } +} diff --git a/testdata/d2oracle/TestUpdateImport/mixed_imports.exp.json b/testdata/d2oracle/TestUpdateImport/mixed_imports.exp.json new file mode 100644 index 000000000..89ddf2f9f --- /dev/null +++ b/testdata/d2oracle/TestUpdateImport/mixed_imports.exp.json @@ -0,0 +1,397 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "index.d2,0:0:0-4:0:22", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:0:0-0:8:8", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:3:3-0:8:8", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:4:4-0:8:8", + "value": [ + { + "string": "woof", + "raw_string": "woof" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "index.d2,1:0:9-1:1:10", + "key": { + "range": "index.d2,1:0:9-1:1:10", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:9-1:1:10", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "import": { + "range": "index.d2,2:0:11-2:8:19", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:4:15-2:8:19", + "value": [ + { + "string": "woof", + "raw_string": "woof" + } + ] + } + } + ] + } + }, + { + "map_key": { + "range": "index.d2,3:0:20-3:1:21", + "key": { + "range": "index.d2,3:0:20-3:1:21", + "path": [ + { + "unquoted_string": { + "range": "index.d2,3:0:20-3:1:21", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "woof.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "woof.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "woof.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "woof.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "index.d2,1:0:9-1:1:10", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:9-1:1:10", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "z", + "id_val": "z", + "references": [ + { + "key": { + "range": "index.d2,3:0:20-3:1:21", + "path": [ + { + "unquoted_string": { + "range": "index.d2,3:0:20-3:1:21", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "z" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestUpdateImport/multiple_imports.exp.json b/testdata/d2oracle/TestUpdateImport/multiple_imports.exp.json new file mode 100644 index 000000000..837aae868 --- /dev/null +++ b/testdata/d2oracle/TestUpdateImport/multiple_imports.exp.json @@ -0,0 +1,416 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "index.d2,0:0:0-3:0:20", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:0:0-0:8:8", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:3:3-0:8:8", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:4:4-0:8:8", + "value": [ + { + "string": "woof", + "raw_string": "woof" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "index.d2,1:0:9-1:8:17", + "key": { + "range": "index.d2,1:0:9-1:1:10", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:9-1:1:10", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,1:3:12-1:8:17", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:4:13-1:8:17", + "value": [ + { + "string": "woof", + "raw_string": "woof" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "index.d2,2:0:18-2:1:19", + "key": { + "range": "index.d2,2:0:18-2:1:19", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:0:18-2:1:19", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "woof.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "woof.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "woof.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "woof.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "index.d2,1:0:9-1:1:10", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:9-1:1:10", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "index.d2,1:0:9-1:1:10", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:9-1:1:10", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "z", + "id_val": "z", + "references": [ + { + "key": { + "range": "index.d2,2:0:18-2:1:19", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:0:18-2:1:19", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "z" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestUpdateImport/nested_import.exp.json b/testdata/d2oracle/TestUpdateImport/nested_import.exp.json new file mode 100644 index 000000000..e4b2e89a8 --- /dev/null +++ b/testdata/d2oracle/TestUpdateImport/nested_import.exp.json @@ -0,0 +1,337 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "index.d2,0:0:0-4:0:30", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:0:0-3:1:29", + "key": { + "range": "index.d2,0:0:0-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:9:9", + "value": [ + { + "string": "container", + "raw_string": "container" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "index.d2,0:11:11-3:1:29", + "nodes": [ + { + "map_key": { + "range": "index.d2,1:2:15-1:10:23", + "key": { + "range": "index.d2,1:2:15-1:3:16", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:2:15-1:3:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,1:5:18-1:10:23", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:6:19-1:10:23", + "value": [ + { + "string": "woof", + "raw_string": "woof" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "index.d2,2:2:26-2:3:27", + "key": { + "range": "index.d2,2:2:26-2:3:27", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:2:26-2:3:27", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "container", + "id_val": "container", + "references": [ + { + "key": { + "range": "index.d2,0:0:0-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:9:9", + "value": [ + { + "string": "container", + "raw_string": "container" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "container" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "woof.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "woof.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "index.d2,1:2:15-1:3:16", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:2:15-1:3:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "index.d2,1:2:15-1:3:16", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:2:15-1:3:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "index.d2,2:2:26-2:3:27", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:2:26-2:3:27", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestUpdateImport/no_matching_import.exp.json b/testdata/d2oracle/TestUpdateImport/no_matching_import.exp.json new file mode 100644 index 000000000..2acfaef4d --- /dev/null +++ b/testdata/d2oracle/TestUpdateImport/no_matching_import.exp.json @@ -0,0 +1,262 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "index.d2,0:0:0-2:0:10", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:0:0-0:7:7", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:3:3-0:7:7", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:4:4-0:7:7", + "value": [ + { + "string": "cat", + "raw_string": "cat" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "index.d2,1:0:8-1:1:9", + "key": { + "range": "index.d2,1:0:8-1:1:9", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:8-1:1:9", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "cat.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "cat.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "index.d2,1:0:8-1:1:9", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:8-1:1:9", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestUpdateImport/remove_import.exp.json b/testdata/d2oracle/TestUpdateImport/remove_import.exp.json new file mode 100644 index 000000000..be88e94da --- /dev/null +++ b/testdata/d2oracle/TestUpdateImport/remove_import.exp.json @@ -0,0 +1,177 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "index.d2,0:0:0-2:0:4", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:0:0-0:1:1", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "index.d2,1:0:2-1:1:3", + "key": { + "range": "index.d2,1:0:2-1:1:3", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:2-1:1:3", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "index.d2,1:0:2-1:1:3", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:2-1:1:3", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestUpdateImport/remove_nested_import.exp.json b/testdata/d2oracle/TestUpdateImport/remove_nested_import.exp.json new file mode 100644 index 000000000..6c4cb9a55 --- /dev/null +++ b/testdata/d2oracle/TestUpdateImport/remove_nested_import.exp.json @@ -0,0 +1,252 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "index.d2,0:0:0-4:0:23", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:0:0-3:1:22", + "key": { + "range": "index.d2,0:0:0-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:9:9", + "value": [ + { + "string": "container", + "raw_string": "container" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "index.d2,0:11:11-3:1:22", + "nodes": [ + { + "map_key": { + "range": "index.d2,1:2:15-1:3:16", + "key": { + "range": "index.d2,1:2:15-1:3:16", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:2:15-1:3:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "index.d2,2:2:19-2:3:20", + "key": { + "range": "index.d2,2:2:19-2:3:20", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:2:19-2:3:20", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "container", + "id_val": "container", + "references": [ + { + "key": { + "range": "index.d2,0:0:0-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:9:9", + "value": [ + { + "string": "container", + "raw_string": "container" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "container" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "index.d2,1:2:15-1:3:16", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:2:15-1:3:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "index.d2,2:2:19-2:3:20", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:2:19-2:3:20", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestUpdateImport/remove_spread_import.exp.json b/testdata/d2oracle/TestUpdateImport/remove_spread_import.exp.json new file mode 100644 index 000000000..24487fde6 --- /dev/null +++ b/testdata/d2oracle/TestUpdateImport/remove_spread_import.exp.json @@ -0,0 +1,177 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "index.d2,0:0:0-3:0:5", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:0:0-0:1:1", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "index.d2,2:0:3-2:1:4", + "key": { + "range": "index.d2,2:0:3-2:1:4", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:0:3-2:1:4", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "index.d2,2:0:3-2:1:4", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:0:3-2:1:4", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestUpdateImport/update_import.exp.json b/testdata/d2oracle/TestUpdateImport/update_import.exp.json new file mode 100644 index 000000000..69194c8b0 --- /dev/null +++ b/testdata/d2oracle/TestUpdateImport/update_import.exp.json @@ -0,0 +1,262 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "index.d2,0:0:0-2:0:11", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:0:0-0:8:8", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:3:3-0:8:8", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:4:4-0:8:8", + "value": [ + { + "string": "woof", + "raw_string": "woof" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "index.d2,1:0:9-1:1:10", + "key": { + "range": "index.d2,1:0:9-1:1:10", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:9-1:1:10", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "woof.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "woof.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "index.d2,1:0:9-1:1:10", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:9-1:1:10", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestUpdateImport/update_import_with_dir.exp.json b/testdata/d2oracle/TestUpdateImport/update_import_with_dir.exp.json new file mode 100644 index 000000000..ef6720216 --- /dev/null +++ b/testdata/d2oracle/TestUpdateImport/update_import_with_dir.exp.json @@ -0,0 +1,262 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "index.d2,0:0:0-2:0:15", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:0:0-0:12:12", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:3:3-0:12:12", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:4:4-0:12:12", + "value": [ + { + "string": "bar/woof", + "raw_string": "bar/woof" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "index.d2,1:0:13-1:1:14", + "key": { + "range": "index.d2,1:0:13-1:1:14", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:13-1:1:14", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "bar/woof.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "bar/woof.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "index.d2,1:0:13-1:1:14", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:13-1:1:14", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestUpdateImport/update_spread_import.exp.json b/testdata/d2oracle/TestUpdateImport/update_spread_import.exp.json new file mode 100644 index 000000000..daec0b4aa --- /dev/null +++ b/testdata/d2oracle/TestUpdateImport/update_spread_import.exp.json @@ -0,0 +1,243 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "index.d2,0:0:0-3:0:13", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:0:0-0:1:1", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "import": { + "range": "index.d2,1:0:2-1:8:10", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:4:6-1:8:10", + "value": [ + { + "string": "woof", + "raw_string": "woof" + } + ] + } + } + ] + } + }, + { + "map_key": { + "range": "index.d2,2:0:11-2:1:12", + "key": { + "range": "index.d2,2:0:11-2:1:12", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:0:11-2:1:12", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "woof.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "woof.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "index.d2,2:0:11-2:1:12", + "path": [ + { + "unquoted_string": { + "range": "index.d2,2:0:11-2:1:12", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": "" +}