Merge branch 'master' into container-dimensions

This commit is contained in:
Alexander Wang 2023-02-20 09:07:12 -08:00
commit 5f750f7109
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
15 changed files with 1231 additions and 56 deletions

View file

@ -8,6 +8,8 @@
- Cleaner watch mode logs without timestamps. [#830](https://github.com/terrastruct/d2/pull/830)
- Remove duplicate success logs in watch mode. [#830](https://github.com/terrastruct/d2/pull/830)
- CLI reports when a feature is incompatible with layout engine, instead of silently ignoring. [#845](https://github.com/terrastruct/d2/pull/845)
- `near` key set to direct parent or ancestor throws an appropriate error message. [#851](https://github.com/terrastruct/d2/pull/851)
- Dimensions and positions are able to be set from API. [#853](https://github.com/terrastruct/d2/pull/853)
#### Bugfixes ⛑️

View file

@ -640,21 +640,33 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) {
func (c *compiler) validateNear(g *d2graph.Graph) {
for _, obj := range g.Objects {
if obj.Attributes.NearKey != nil {
_, isKey := g.Root.HasChild(d2graph.Key(obj.Attributes.NearKey))
nearObj, isKey := g.Root.HasChild(d2graph.Key(obj.Attributes.NearKey))
_, isConst := d2graph.NearConstants[d2graph.Key(obj.Attributes.NearKey)[0]]
if !isKey && !isConst {
c.errorf(obj.Attributes.NearKey, "near key %#v must be the absolute path to a shape or one of the following constants: %s", d2format.Format(obj.Attributes.NearKey), strings.Join(d2graph.NearConstantsArray, ", "))
continue
}
if !isKey && isConst && obj.Parent != g.Root {
c.errorf(obj.Attributes.NearKey, "constant near keys can only be set on root level shapes")
continue
}
if !isKey && isConst && len(obj.ChildrenArray) > 0 {
c.errorf(obj.Attributes.NearKey, "constant near keys cannot be set on shapes with children")
continue
}
if !isKey && isConst {
if isKey {
// Doesn't make sense to set near to an ancestor or descendant
nearIsAncestor := false
for curr := obj; curr != nil; curr = curr.Parent {
if curr == nearObj {
nearIsAncestor = true
break
}
}
if nearIsAncestor {
c.errorf(obj.Attributes.NearKey, "near keys cannot be set to an ancestor")
continue
}
nearIsDescendant := false
for curr := nearObj; curr != nil; curr = curr.Parent {
if curr == obj {
nearIsDescendant = true
break
}
}
if nearIsDescendant {
c.errorf(obj.Attributes.NearKey, "near keys cannot be set to an descendant")
continue
}
} else if isConst {
is := false
for _, e := range g.Edges {
if e.Src == obj || e.Dst == obj {
@ -666,6 +678,17 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
c.errorf(obj.Attributes.NearKey, "constant near keys cannot be set on connected shapes")
continue
}
if obj.Parent != g.Root {
c.errorf(obj.Attributes.NearKey, "constant near keys can only be set on root level shapes")
continue
}
if len(obj.ChildrenArray) > 0 {
c.errorf(obj.Attributes.NearKey, "constant near keys cannot be set on shapes with children")
continue
}
} else {
c.errorf(obj.Attributes.NearKey, "near key %#v must be the absolute path to a shape or one of the following constants: %s", d2format.Format(obj.Attributes.NearKey), strings.Join(d2graph.NearConstantsArray, ", "))
continue
}
}
}

View file

@ -1390,6 +1390,29 @@ x -> y: {
text: `x.near: top-center
`,
},
{
name: "near-invalid",
text: `mongodb: MongoDB {
perspective: perspective (View) {
password
}
explanation: |md
perspective.model.js
| {
near: mongodb
}
}
a: {
near: a.b
b
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/near-invalid.d2:9:11: near keys cannot be set to an ancestor
d2/testdata/d2compiler/TestCompile/near-invalid.d2:14:9: near keys cannot be set to an descendant`,
},
{
name: "near_bad_constant",

View file

@ -234,6 +234,26 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error {
attrs.Shape.MapKey.SetScalar(mk.Value.ScalarBox())
return nil
}
case "width":
if attrs.Width != nil && attrs.Width.MapKey != nil {
attrs.Width.MapKey.SetScalar(mk.Value.ScalarBox())
return nil
}
case "height":
if attrs.Height != nil && attrs.Height.MapKey != nil {
attrs.Height.MapKey.SetScalar(mk.Value.ScalarBox())
return nil
}
case "top":
if attrs.Top != nil && attrs.Top.MapKey != nil {
attrs.Top.MapKey.SetScalar(mk.Value.ScalarBox())
return nil
}
case "left":
if attrs.Left != nil && attrs.Left.MapKey != nil {
attrs.Left.MapKey.SetScalar(mk.Value.ScalarBox())
return nil
}
case "style":
if len(mk.Key.Path[reservedIndex:]) != 2 {
return errors.New("malformed style setting, expected 2 part path")
@ -667,6 +687,10 @@ func deleteReserved(g *d2graph.Graph, mk *d2ast.Key) (*d2graph.Graph, error) {
if id == "near" ||
id == "tooltip" ||
id == "icon" ||
id == "width" ||
id == "height" ||
id == "left" ||
id == "top" ||
id == "link" {
err := deleteObjField(g, obj, id)
if err != nil {

View file

@ -695,6 +695,54 @@ square.style.opacity: 0.2
}
},
},
{
name: "set_position",
text: `square
`,
key: `square.top`,
value: go2.Pointer(`200`),
exp: `square: {top: 200}
`,
},
{
name: "replace_position",
text: `square: {
width: 100
top: 32
left: 44
}
`,
key: `square.top`,
value: go2.Pointer(`200`),
exp: `square: {
width: 100
top: 200
left: 44
}
`,
},
{
name: "set_dimensions",
text: `square
`,
key: `square.width`,
value: go2.Pointer(`200`),
exp: `square: {width: 200}
`,
},
{
name: "replace_dimensions",
text: `square: {
width: 100
}
`,
key: `square.width`,
value: go2.Pointer(`200`),
exp: `square: {
width: 200
}
`,
},
{
name: "label_unset",
text: `square: "Always try to do things in chronological order; it's less confusing that way."
@ -2220,7 +2268,7 @@ a.b.c: {
`,
},
{
name: "near",
name: "invalid-near",
text: `x: {
near: y
@ -2234,6 +2282,33 @@ y
near: x.y
y
}
`,
expErr: `failed to move: "y" to "x.y": failed to recompile:
x: {
near: x.y
y
}
d2/testdata/d2oracle/TestMove/invalid-near.d2:2:9: near keys cannot be set to an descendant`,
},
{
name: "near",
text: `x: {
near: y
}
a
y
`,
key: `y`,
newKey: `a.y`,
exp: `x: {
near: a.y
}
a: {
y
}
`,
},
{
@ -4432,6 +4507,30 @@ A -> B: {style.stroke: "#2b50c2"}
exp: `A: {style.stroke: "#000e3d"}
B
A -> B
`,
},
{
name: "width",
text: `x: {
width: 200
}
`,
key: `x.width`,
exp: `x
`,
},
{
name: "left",
text: `x: {
left: 200
}
`,
key: `x.left`,
exp: `x
`,
},
}

View file

@ -1,8 +1,8 @@
# Contributing
<!-- toc -->
- <a href="#welcome" id="toc-welcome">Welcome</a>
- <a href="#ci" id="toc-ci">CI</a>
- <a href="#flow" id="toc-flow">Flow</a>
- <a href="#logistics" id="toc-logistics">Logistics</a>
- <a href="#dev" id="toc-dev">Dev</a>
- <a href="#content" id="toc-content">Content</a>
@ -10,42 +10,68 @@
- <a href="#documentation" id="toc-documentation">Documentation</a>
- <a href="#questions" id="toc-questions">Questions</a>
## Welcome
D2's [long-term mission](https://d2lang.com/tour/future/) is to significantly reduce the
amount of time and effort it takes to create and maintain high-quality diagrams for every
software team. We started this because we love the idea of creating diagrams with text --
but it was clear the existing solutions were inadequete in their state and speed of
execution for this idea to be widely usable.
We've tried our best to avoid the mistakes of the past and take inspiration from the most
successful modern programming and configuration languages. D2 has built up each step of
the text-to-diagram pipeline from scratch, rethinking each one from first principles, from
the dead simple syntax, to the readable compiler, our own SVG renderer, etc.
D2 is committed to making something people want to use. That means contributions don't
only have to be in the form of pull requests. Your bug reports, plugins, examples,
discussions of new ideas, help a great deal.
If you'd like to get involved, we're also committed to helping you merge that first pull
request. You should be able to freely pick up Issues tagged as "good first issue". If you
need help getting started, please don't hesitate to pop into Discord -- as long as you
want to help, we'll find the perfect task (complexity matches your appetite and
programming experience, in an area you're interested in, etc).
## CI
Most of D2's CI is open sourced in its own
[repository](https://github.com/terrastruct/ci). You can find commands in the Github
workflows. E.g. run `./make.sh fmt` to run the formatter. Please make sure all CI is
passing for any PRs.
Most of the CI scripts rely on a submodule shared between many D2 repositories:
[https://github.com/terrastruct/ci](https://github.com/terrastruct/ci). You should fetch
the submodule whenever it differs:
```sh
git submodule update --recursive
```
If running for the first time for a repo (e.g. new clone), add `--init`:
[repository](https://github.com/terrastruct/ci), included as a submodule. After you clone
D2, make sure you initialize the submodules:
```sh
git submodule update --init --recursive
```
## Flow
`./make.sh` runs everything. Subcommands to run individual parts of the CI:
The simplified D2 flow at a package level looks like:
- `./make.sh fmt`
- `./make.sh lint`
- `./make.sh test`
- `./make.sh race`
- `./make.sh build`
<img src="./assets/flow.svg" alt="D2 flow" height="700" />
Here's what a successful run should look like:
<img width="1582" alt="Screen Shot 2023-02-19 at 7 46 34 PM" src="https://user-images.githubusercontent.com/3120367/220004975-7a218b82-c5c1-4a71-b2bb-8695bbfd600c.png">
Please make sure CI is passing for any PRs submitted for review.
Be sure to update the submodule whenever there are changes:
```sh
git submodule update --recursive
```
## Logistics
- Use Go 1.18. Go 1.19's autofmt inexplicably strips spacing from ASCII art in comments.
We're working on it.
- Please sign your commits
([https://github.com/terrastruct/d2/pull/557#issuecomment-1367468730](https://github.com/terrastruct/d2/pull/557#issuecomment-1367468730)).
- D2 uses Issues as TODOs. No auto-closing on staleness.
- Branch off `master`.
- Prefix pull request titles with a short descriptor of the domain, e.g. `d2renderer: Add
x`.
- If there's an Issue related, include it by adding "[one-word] #[issue]", e.g. "Fixes
#123" somewhere in the description.
- Whenever possible and relevant, include a screenshot or screen-recording.
@ -54,25 +80,37 @@ The simplified D2 flow at a package level looks like:
### Content
Please choose an Issue with a "TODO" label. If you'd like to propose new functionality or
change to current functionality, please create an Issue first with a proposal. When you
start work on an Issue, please leave a comment so others know that it's being worked on.
Unless you've contributed before, it's safest to choose an Issue with a "good first issue"
label. If you'd like to propose new functionality or change to current functionality,
please create an Issue first with a proposal. When you start work on an Issue, please
leave a comment so others know that it's being worked on.
### Tests
All code changes must include tests. D2 mostly has functional tests, and uses
[diff](https://github.com/terrastruct/diff) as a framework that gives Git-style
comparisons of expected vs actual output for each stage. There are ample examples in each
package of this -- try changing some test and run it to see.
D2 has extensive tests, and all code changes must include tests.
With the exception of changes to the renderer, all code should include a package-specific
test. If it's a visual change, an e2e test should accompany.
test. If it's a visual change, an end-to-end (e2e) test should accompany.
Let's say I make some code changes. I can easily see how this affects the end result by
running:
```
./ci/e2ereport.sh -delta
```
This gives me a nice HMTL output of what the test expected vs what it got (this was a PR
fixing multi-byte character labels):
![screencapture-file-Users-alexanderwang-dev-alixander-d2-e2etests-out-e2e-report-html-2023-02-14-10_15_07](https://user-images.githubusercontent.com/3120367/218822836-bcc517f2-ae3e-4e0d-83f6-2cbaa2fd9275.png)
Run `./ci/e2ereport.sh -help` for flags, including how to get deltas for a single test.
If you're testing labels and strings, it's encouraged to use 1-letter strings (`x`) in small
functional tests to minimally pinpoint issues. If you are testing something that exercises
variations in strings, or want to mimic more realistic diagram text, it's encouraged you
generate random strings and words from `fortune`. It gives a good range of the English
language. Sometimes it gives controversial sentences -- don't use those.
language. (Sometimes it gives controversial sentences -- don't use those.)
Script to generate one line of random text:
```

16
testdata/d2compiler/TestCompile/near-invalid.exp.json generated vendored Normal file
View file

@ -0,0 +1,16 @@
{
"graph": null,
"err": {
"ioerr": null,
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/near-invalid.d2,8:10:133-8:17:140",
"errmsg": "d2/testdata/d2compiler/TestCompile/near-invalid.d2:9:11: near keys cannot be set to an ancestor"
},
{
"range": "d2/testdata/d2compiler/TestCompile/near-invalid.d2,13:8:161-13:11:164",
"errmsg": "d2/testdata/d2compiler/TestCompile/near-invalid.d2:14:9: near keys cannot be set to an descendant"
}
]
}
}

109
testdata/d2oracle/TestDelete/left.exp.json generated vendored Normal file
View file

@ -0,0 +1,109 @@
{
"graph": {
"name": "",
"ast": {
"range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-1:0:2",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-0:1:1",
"key": {
"range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "x",
"id_val": "x",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestDelete/left.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"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": "<nil>"
}

109
testdata/d2oracle/TestDelete/width.exp.json generated vendored Normal file
View file

@ -0,0 +1,109 @@
{
"graph": {
"name": "",
"ast": {
"range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-1:0:2",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-0:1:1",
"key": {
"range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "x",
"id_val": "x",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestDelete/width.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"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": "<nil>"
}

4
testdata/d2oracle/TestMove/invalid-near.exp.json generated vendored Normal file
View file

@ -0,0 +1,4 @@
{
"graph": null,
"err": "failed to move: \"y\" to \"x.y\": failed to recompile:\nx: {\n near: x.y\n y\n}\n\nd2/testdata/d2oracle/TestMove/invalid-near.d2:2:9: near keys cannot be set to an descendant"
}

View file

@ -2,11 +2,11 @@
"graph": {
"name": "",
"ast": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,0:0:0-4:0:23",
"range": "d2/testdata/d2oracle/TestMove/near.d2,0:0:0-6:0:30",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,0:0:0-3:1:22",
"range": "d2/testdata/d2oracle/TestMove/near.d2,0:0:0-2:1:18",
"key": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,0:0:0-0:1:1",
"path": [
@ -26,7 +26,7 @@
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,0:3:3-3:0:21",
"range": "d2/testdata/d2oracle/TestMove/near.d2,0:3:3-2:0:17",
"nodes": [
{
"map_key": {
@ -53,23 +53,52 @@
"range": "d2/testdata/d2oracle/TestMove/near.d2,1:8:13-1:11:16",
"value": [
{
"string": "x.y",
"raw_string": "x.y"
"string": "a.y",
"raw_string": "a.y"
}
]
}
}
}
},
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,3:0:19-5:1:29",
"key": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,3:0:19-3:1:20",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,3:0:19-3:1:20",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,3:3:22-5:0:28",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,2:2:19-2:3:20",
"range": "d2/testdata/d2oracle/TestMove/near.d2,4:2:26-4:3:27",
"key": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,2:2:19-2:3:20",
"range": "d2/testdata/d2oracle/TestMove/near.d2,4:2:26-4:3:27",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,2:2:19-2:3:20",
"range": "d2/testdata/d2oracle/TestMove/near.d2,4:2:26-4:3:27",
"value": [
{
"string": "y",
@ -160,8 +189,8 @@
"range": ",0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
"string": "a",
"raw_string": "a"
}
]
}
@ -191,6 +220,53 @@
},
"zIndex": 0
},
{
"id": "a",
"id_val": "a",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,3:0:19-3:1:20",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,3:0:19-3:1:20",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "a"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "y",
"id_val": "y",
@ -201,11 +277,11 @@
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,2:2:19-2:3:20",
"range": "d2/testdata/d2oracle/TestMove/near.d2,4:2:26-4:3:27",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/near.d2,2:2:19-2:3:20",
"range": "d2/testdata/d2oracle/TestMove/near.d2,4:2:26-4:3:27",
"value": [
{
"string": "y",

147
testdata/d2oracle/TestSet/replace_dimensions.exp.json generated vendored Normal file
View file

@ -0,0 +1,147 @@
{
"graph": {
"name": "",
"ast": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-3:0:25",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-2:1:24",
"key": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-0:6:6",
"value": [
{
"string": "square",
"raw_string": "square"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:8:8-2:0:23",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,1:2:12-1:12:22",
"key": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,1:2:12-1:7:17",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,1:2:12-1:7:17",
"value": [
{
"string": "width",
"raw_string": "width"
}
]
}
}
]
},
"primary": {},
"value": {
"number": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,1:9:19-1:12:22",
"raw": "200",
"value": "200"
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "square",
"id_val": "square",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-0:6:6",
"value": [
{
"string": "square",
"raw_string": "square"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "square"
},
"style": {},
"width": {
"value": "200"
},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": "<nil>"
}

211
testdata/d2oracle/TestSet/replace_position.exp.json generated vendored Normal file
View file

@ -0,0 +1,211 @@
{
"graph": {
"name": "",
"ast": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-5:0:47",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-4:1:46",
"key": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-0:6:6",
"value": [
{
"string": "square",
"raw_string": "square"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:8:8-4:0:45",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,1:2:12-1:12:22",
"key": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,1:2:12-1:7:17",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,1:2:12-1:7:17",
"value": [
{
"string": "width",
"raw_string": "width"
}
]
}
}
]
},
"primary": {},
"value": {
"number": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,1:9:19-1:12:22",
"raw": "100",
"value": "100"
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,2:2:25-2:10:33",
"key": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,2:2:25-2:5:28",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,2:2:25-2:5:28",
"value": [
{
"string": "top",
"raw_string": "top"
}
]
}
}
]
},
"primary": {},
"value": {
"number": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,2:7:30-2:10:33",
"raw": "200",
"value": "200"
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,3:2:36-3:10:44",
"key": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,3:2:36-3:6:40",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,3:2:36-3:6:40",
"value": [
{
"string": "left",
"raw_string": "left"
}
]
}
}
]
},
"primary": {},
"value": {
"number": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,3:8:42-3:10:44",
"raw": "44",
"value": "44"
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "square",
"id_val": "square",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-0:6:6",
"value": [
{
"string": "square",
"raw_string": "square"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "square"
},
"style": {},
"width": {
"value": "100"
},
"top": {
"value": "200"
},
"left": {
"value": "44"
},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": "<nil>"
}

147
testdata/d2oracle/TestSet/set_dimensions.exp.json generated vendored Normal file
View file

@ -0,0 +1,147 @@
{
"graph": {
"name": "",
"ast": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-1:0:21",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-0:20:20",
"key": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-0:6:6",
"value": [
{
"string": "square",
"raw_string": "square"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:8:8-0:19:19",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:9:9-0:19:19",
"key": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:9:9-0:14:14",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:9:9-0:14:14",
"value": [
{
"string": "width",
"raw_string": "width"
}
]
}
}
]
},
"primary": {},
"value": {
"number": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:16:16-0:19:19",
"raw": "200",
"value": "200"
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "square",
"id_val": "square",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-0:6:6",
"value": [
{
"string": "square",
"raw_string": "square"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "square"
},
"style": {},
"width": {
"value": "200"
},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": "<nil>"
}

147
testdata/d2oracle/TestSet/set_position.exp.json generated vendored Normal file
View file

@ -0,0 +1,147 @@
{
"graph": {
"name": "",
"ast": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-1:0:19",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-0:18:18",
"key": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-0:6:6",
"value": [
{
"string": "square",
"raw_string": "square"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:8:8-0:17:17",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:9:9-0:17:17",
"key": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:9:9-0:12:12",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:9:9-0:12:12",
"value": [
{
"string": "top",
"raw_string": "top"
}
]
}
}
]
},
"primary": {},
"value": {
"number": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:14:14-0:17:17",
"raw": "200",
"value": "200"
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "square",
"id_val": "square",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-0:6:6",
"value": [
{
"string": "square",
"raw_string": "square"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "square"
},
"style": {},
"top": {
"value": "200"
},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": "<nil>"
}