diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 89fbcd143..3548fe881 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -25,9 +25,19 @@ import ( func Create(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph, newKey string, err error) { defer xdefer.Errorf(&err, "failed to create %#v", key) - boardG := GetBoardGraph(g, boardPath) - if boardG == nil { - return nil, "", fmt.Errorf("board %v not found", boardPath) + boardG := g + baseBoardG := g + + if len(boardPath) > 0 { + boardG = GetBoardGraph(g, boardPath) + if boardG == nil { + return nil, "", fmt.Errorf("board %v not found", boardPath) + } + + baseBoardG, err = recompile(g, boardG.BaseAST) + if err != nil { + return nil, "", err + } } newKey, edge, err := generateUniqueKey(boardG, key, nil, nil) @@ -36,15 +46,22 @@ func Create(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph, } if edge { - err = _set(boardG, key, nil, nil) + err = _set(boardG, baseBoardG, key, nil, nil) } else { - err = _set(boardG, newKey, nil, nil) + err = _set(boardG, baseBoardG, newKey, nil, nil) } - println(d2format.Format(boardG.AST)) + + if len(boardPath) > 0 { + replaced := ReplaceBoardNode(g.AST, baseBoardG.AST, boardPath) + if !replaced { + return nil, "", fmt.Errorf("board %v AST not found", boardPath) + } + } + if err != nil { return nil, "", err } - g, err = recompile(g) + g, err = recompile(g, g.AST) if err != nil { return nil, "", err } @@ -66,12 +83,12 @@ func Set(g *d2graph.Graph, key string, tag, value *string) (_ *d2graph.Graph, er defer xdefer.Errorf(&err, "failed to set %#v to %#v", key, valueHelp) } - err = _set(g, key, tag, value) + err = _set(g, g, key, tag, value) if err != nil { return nil, err } - return recompile(g) + return recompile(g, g.AST) } func ReconnectEdge(g *d2graph.Graph, edgeKey string, srcKey, dstKey *string) (_ *d2graph.Graph, err error) { @@ -208,7 +225,7 @@ func ReconnectEdge(g *d2graph.Graph, edgeKey string, srcKey, dstKey *string) (_ } } - return recompile(g) + return recompile(g, g.AST) } func pathFromScopeKey(g *d2graph.Graph, key *d2ast.Key, scopeak []string) ([]*d2ast.StringBox, error) { @@ -240,9 +257,9 @@ func pathFromScopeObj(g *d2graph.Graph, key *d2ast.Key, fromScope *d2graph.Objec return pathFromScopeKey(g, key, scopeak) } -func recompile(g *d2graph.Graph) (*d2graph.Graph, error) { - s := d2format.Format(g.AST) - g, err := d2compiler.Compile(g.AST.Range.Path, strings.NewReader(s), nil) +func recompile(g *d2graph.Graph, ast *d2ast.Map) (*d2graph.Graph, error) { + s := d2format.Format(ast) + g, err := d2compiler.Compile(ast.Range.Path, strings.NewReader(s), nil) if err != nil { return nil, fmt.Errorf("failed to recompile:\n%s\n%w", s, err) } @@ -250,7 +267,7 @@ func recompile(g *d2graph.Graph) (*d2graph.Graph, error) { } // TODO merge flat styles -func _set(g *d2graph.Graph, key string, tag, value *string) error { +func _set(g, baseG *d2graph.Graph, key string, tag, value *string) error { if tag != nil { if hasSpace(*tag) { return fmt.Errorf("spaces are not allowed in blockstring tags") @@ -278,7 +295,7 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { }) } - scope := g.AST + scope := baseG.AST edgeTrimCommon(mk) obj := g.Root toSkip := 1 @@ -758,10 +775,10 @@ func Delete(g *d2graph.Graph, key string) (_ *d2graph.Graph, err error) { } } } - return recompile(g) + return recompile(g, g.AST) } - prevG, _ := recompile(g) + prevG, _ := recompile(g, g.AST) g, err = renameConflictsToParent(g, mk.Key) if err != nil { @@ -782,7 +799,7 @@ func Delete(g *d2graph.Graph, key string) (_ *d2graph.Graph, err error) { return nil, err } - return recompile(g) + return recompile(g, g.AST) } func bumpChildrenUnderscores(m *d2ast.Map) { @@ -1021,7 +1038,7 @@ func deleteReserved(g *d2graph.Graph, mk *d2ast.Key) (*d2graph.Graph, error) { if err := deleteEdgeField(g, e, targetKey.Path[len(targetKey.Path)-1].Unbox().ScalarString()); err != nil { return nil, err } - return recompile(g) + return recompile(g, g.AST) } isStyleKey := false @@ -1060,7 +1077,7 @@ func deleteReserved(g *d2graph.Graph, mk *d2ast.Key) (*d2graph.Graph, error) { } } - return recompile(g) + return recompile(g, g.AST) } func deleteMapField(m *d2ast.Map, field string) { @@ -1124,7 +1141,7 @@ func deleteObjField(g *d2graph.Graph, obj *d2graph.Object, field string) error { copy(tmpNodes, ref.Scope.Nodes) // If I delete this, will the object still exist? deleteFromMap(ref.Scope, ref.MapKey) - g2, err := recompile(g) + g2, err := recompile(g, g.AST) if err != nil { return err } @@ -1419,10 +1436,10 @@ func move(g *d2graph.Graph, key, newKey string, includeDescendants bool) (*d2gra ref.MapKey.Edges[ref.MapKeyEdgeIndex].SrcArrow = mk2.Edges[0].SrcArrow ref.MapKey.Edges[ref.MapKeyEdgeIndex].DstArrow = mk2.Edges[0].DstArrow } - return recompile(g) + return recompile(g, g.AST) } - prevG, _ := recompile(g) + prevG, _ := recompile(g, g.AST) ak := d2graph.Key(mk.Key) ak2 := d2graph.Key(mk2.Key) @@ -1828,7 +1845,7 @@ func move(g *d2graph.Graph, key, newKey string, includeDescendants bool) (*d2gra return nil, err } - return recompile(g) + return recompile(g, g.AST) } // filterReserved takes a Value and splits it into 2 @@ -1940,7 +1957,7 @@ func updateNear(prevG, g *d2graph.Graph, from, to *string, includeDescendants bo if err != nil { return err } - tmpG, _ := recompile(prevG) + tmpG, _ := recompile(prevG, prevG.AST) appendMapKey(tmpG.AST, valueMK) if to == nil { deltas, err := DeleteIDDeltas(tmpG, *from) @@ -1985,7 +2002,7 @@ func updateNear(prevG, g *d2graph.Graph, from, to *string, includeDescendants bo if err != nil { return err } - tmpG, _ := recompile(prevG) + tmpG, _ := recompile(prevG, prevG.AST) appendMapKey(tmpG.AST, valueMK) if to == nil { deltas, err := DeleteIDDeltas(tmpG, *from) diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index f582aa306..b01e0f80a 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -479,6 +479,56 @@ layers: { b } } +`, + }, + { + name: "scenarios-basic", + + text: `a +b +scenarios: { + x: { + a + } +} +`, + key: `c`, + boardPath: []string{"root", "scenarios", "x"}, + + expKey: `c`, + exp: `a +b +scenarios: { + x: { + a + c + } +} +`, + }, + { + name: "steps-basic", + + text: `a +d +steps: { + x: { + b + } +} +`, + key: `c`, + boardPath: []string{"root", "steps", "x"}, + + expKey: `c`, + exp: `a +d +steps: { + x: { + b + c + } +} `, }, } diff --git a/d2oracle/get.go b/d2oracle/get.go index c2bce9596..c17bbbb54 100644 --- a/d2oracle/get.go +++ b/d2oracle/get.go @@ -51,6 +51,55 @@ func GetBoardGraph(g *d2graph.Graph, boardPath []string) *d2graph.Graph { return nil } +func ReplaceBoardNode(ast, ast2 *d2ast.Map, boardPath []string) bool { + if len(boardPath) == 0 { + return false + } + switch boardPath[0] { + case "root": + return ReplaceBoardNode(ast, ast2, boardPath[1:]) + case "layers": + if len(boardPath) < 2 { + return false + } + for _, n := range ast.Nodes { + if n.MapKey != nil && n.MapKey.Key != nil && n.MapKey.Key.Path[0].Unbox().ScalarString() == "layers" { + return ReplaceBoardNode(n.MapKey.Value.Map, ast2, boardPath[1:]) + } + } + case "scenarios": + if len(boardPath) < 2 { + return false + } + for _, n := range ast.Nodes { + if n.MapKey != nil && n.MapKey.Key != nil && n.MapKey.Key.Path[0].Unbox().ScalarString() == "scenarios" { + return ReplaceBoardNode(n.MapKey.Value.Map, ast2, boardPath[1:]) + } + } + case "steps": + if len(boardPath) < 2 { + return false + } + for _, n := range ast.Nodes { + if n.MapKey != nil && n.MapKey.Key != nil && n.MapKey.Key.Path[0].Unbox().ScalarString() == "steps" { + return ReplaceBoardNode(n.MapKey.Value.Map, ast2, boardPath[1:]) + } + } + default: + for _, n := range ast.Nodes { + if n.MapKey != nil && n.MapKey.Key != nil && n.MapKey.Key.Path[0].Unbox().ScalarString() == boardPath[0] { + if len(boardPath) == 1 { + n.MapKey.Value.Map.Nodes = ast2.Nodes + return true + } + return ReplaceBoardNode(n.MapKey.Value.Map, ast2, boardPath[1:]) + } + } + } + + return false +} + func GetChildrenIDs(g *d2graph.Graph, absID string) (ids []string, _ error) { mk, err := d2parser.ParseMapKey(absID) if err != nil { diff --git a/testdata/d2oracle/TestCreate/layers-basic.exp.json b/testdata/d2oracle/TestCreate/layers-basic.exp.json new file mode 100644 index 000000000..4fe04884d --- /dev/null +++ b/testdata/d2oracle/TestCreate/layers-basic.exp.json @@ -0,0 +1,430 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,0:0:0-7:0:37", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,0:0:0-0:1:1", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,1:0:2-6:1:36", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,1:0:2-1:6:8", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,1:0:2-1:6:8", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,1:8:10-6:1:36", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,2:2:14-5:3:34", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,2:2:14-2:3:15", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,2:2:14-2:3:15", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,2:5:17-5:3:34", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,3:4:23-3:5:24", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,3:4:23-3:5:24", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,3:4:23-3:5:24", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,4:4:29-4:5:30", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,4:4:29-4:5:30", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,4:4:29-4:5:30", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "layers": [ + { + "name": "x", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "baseAST": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,3:4:23-3:5:24", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,3:4:23-3:5:24", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,4:4:29-4:5:30", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/layers-basic.d2,4:4:29-4:5:30", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestCreate/scenarios-basic.exp.json b/testdata/d2oracle/TestCreate/scenarios-basic.exp.json new file mode 100644 index 000000000..539a60b79 --- /dev/null +++ b/testdata/d2oracle/TestCreate/scenarios-basic.exp.json @@ -0,0 +1,585 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,0:0:0-8:0:42", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,0:0:0-0:1:1", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,1:0:2-1:1:3", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,1:0:2-1:1:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,1:0:2-1:1:3", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,2:0:4-7:1:41", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,2:0:4-2:9:13", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,2:0:4-2:9:13", + "value": [ + { + "string": "scenarios", + "raw_string": "scenarios" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,2:11:15-7:1:41", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,3:2:19-6:3:39", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,3:2:19-3:3:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,3:2:19-3:3:20", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,3:5:22-6:3:39", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,4:4:28-4:5:29", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,4:4:28-4:5:29", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,4:4:28-4:5:29", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,5:4:34-5:5:35", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,5:4:34-5:5:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,5:4:34-5:5:35", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,1:0:2-1:1:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,1:0:2-1:1:3", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "scenarios": [ + { + "name": "x", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "c" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "baseAST": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "c" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,4:4:28-4:5:29", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,4:4:28-4:5:29", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,1:0:2-1:1:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,1:0:2-1:1:3", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "c", + "id_val": "c", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,5:4:34-5:5:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/scenarios-basic.d2,5:4:34-5:5:35", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestCreate/steps-basic.exp.json b/testdata/d2oracle/TestCreate/steps-basic.exp.json new file mode 100644 index 000000000..72578651c --- /dev/null +++ b/testdata/d2oracle/TestCreate/steps-basic.exp.json @@ -0,0 +1,632 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,0:0:0-8:0:38", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,0:0:0-0:1:1", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,1:0:2-1:1:3", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,1:0:2-1:1:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,1:0:2-1:1:3", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,2:0:4-7:1:37", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,2:0:4-2:5:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,2:0:4-2:5:9", + "value": [ + { + "string": "steps", + "raw_string": "steps" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,2:7:11-7:1:37", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,3:2:15-6:3:35", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,3:2:15-3:3:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,3:2:15-3:3:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,3:5:18-6:3:35", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,4:4:24-4:5:25", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,4:4:24-4:5:25", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,4:4:24-4:5:25", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,5:4:30-5:5:31", + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,5:4:30-5:5:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,5:4:30-5:5:31", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "d", + "id_val": "d", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,1:0:2-1:1:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,1:0:2-1:1:3", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "d" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "steps": [ + { + "name": "x", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "d" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "c" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "baseAST": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "c" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "d", + "id_val": "d", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,1:0:2-1:1:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,1:0:2-1:1:3", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "d" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,4:4:24-4:5:25", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,4:4:24-4:5:25", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "c", + "id_val": "c", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,5:4:30-5:5:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestCreate/steps-basic.d2,5:4:30-5:5:31", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": "" +}