d2ir: More import tests
This commit is contained in:
parent
9f0c24f5d7
commit
42706f8b64
4 changed files with 484 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ package d2ir_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"oss.terrastruct.com/d2/d2ir"
|
||||||
"oss.terrastruct.com/util-go/assert"
|
"oss.terrastruct.com/util-go/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -26,7 +27,7 @@ label: meow`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nested",
|
name: "nested/map",
|
||||||
run: func(t testing.TB) {
|
run: func(t testing.TB) {
|
||||||
m, err := compileFS(t, "index.d2", map[string]string{
|
m, err := compileFS(t, "index.d2", map[string]string{
|
||||||
"index.d2": "x: @x.y",
|
"index.d2": "x: @x.y",
|
||||||
|
|
@ -42,6 +43,33 @@ label: meow`,
|
||||||
assertQuery(t, m, 0, 0, "meow", "x.label")
|
assertQuery(t, m, 0, 0, "meow", "x.label")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "nested/array",
|
||||||
|
run: func(t testing.TB) {
|
||||||
|
m, err := compileFS(t, "index.d2", map[string]string{
|
||||||
|
"index.d2": "x: @x.y",
|
||||||
|
"x.d2": `y: [1, 2]`,
|
||||||
|
})
|
||||||
|
assert.Success(t, err)
|
||||||
|
assertQuery(t, m, 1, 0, nil, "")
|
||||||
|
x := assertQuery(t, m, 0, 0, nil, "x")
|
||||||
|
xf, ok := x.(*d2ir.Field)
|
||||||
|
assert.True(t, ok)
|
||||||
|
assert.Equal(t, `[1, 2]`, xf.Composite.String())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "nested/scalar",
|
||||||
|
run: func(t testing.TB) {
|
||||||
|
m, err := compileFS(t, "index.d2", map[string]string{
|
||||||
|
"index.d2": "x: @x.y",
|
||||||
|
"x.d2": `y: meow`,
|
||||||
|
})
|
||||||
|
assert.Success(t, err)
|
||||||
|
assertQuery(t, m, 1, 0, nil, "")
|
||||||
|
assertQuery(t, m, 0, 0, "meow", "x")
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "spread",
|
name: "spread",
|
||||||
run: func(t testing.TB) {
|
run: func(t testing.TB) {
|
||||||
|
|
|
||||||
105
testdata/d2ir/TestCompile/imports/nested/array.exp.json
generated
vendored
Normal file
105
testdata/d2ir/TestCompile/imports/nested/array.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
{
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "x",
|
||||||
|
"composite": {
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"value": {
|
||||||
|
"range": "x.d2,0:4:4-0:8:8",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "1, 2",
|
||||||
|
"raw_string": "1, 2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"string": {
|
||||||
|
"range": "index.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path": {
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"context": {
|
||||||
|
"edge": null,
|
||||||
|
"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,
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "index.d2,0:4:4-0:5:5",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "index.d2,0:6:6-0:7:7",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "y",
|
||||||
|
"raw_string": "y"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"edges": null
|
||||||
|
}
|
||||||
249
testdata/d2ir/TestCompile/imports/nested/map.exp.json
generated
vendored
Normal file
249
testdata/d2ir/TestCompile/imports/nested/map.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,249 @@
|
||||||
|
{
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "x",
|
||||||
|
"composite": {
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "shape",
|
||||||
|
"primary": {
|
||||||
|
"value": {
|
||||||
|
"range": "x.d2,1:8:13-1:14:19",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "circle",
|
||||||
|
"raw_string": "circle"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"string": {
|
||||||
|
"range": "x.d2,1:1:6-1:6:11",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "shape",
|
||||||
|
"raw_string": "shape"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path": {
|
||||||
|
"range": "x.d2,1:1:6-1:6:11",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "x.d2,1:1:6-1:6:11",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "shape",
|
||||||
|
"raw_string": "shape"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"context": {
|
||||||
|
"edge": null,
|
||||||
|
"key": {
|
||||||
|
"range": "x.d2,1:1:6-1:14:19",
|
||||||
|
"key": {
|
||||||
|
"range": "x.d2,1:1:6-1:6:11",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "x.d2,1:1:6-1:6:11",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "shape",
|
||||||
|
"raw_string": "shape"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "x.d2,1:8:13-1:14:19",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "circle",
|
||||||
|
"raw_string": "circle"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "label",
|
||||||
|
"primary": {
|
||||||
|
"value": {
|
||||||
|
"range": "x.d2,2:8:28-2:12:32",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "meow",
|
||||||
|
"raw_string": "meow"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"string": {
|
||||||
|
"range": "x.d2,2:1:21-2:6:26",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "label",
|
||||||
|
"raw_string": "label"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path": {
|
||||||
|
"range": "x.d2,2:1:21-2:6:26",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "x.d2,2:1:21-2:6:26",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "label",
|
||||||
|
"raw_string": "label"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"context": {
|
||||||
|
"edge": null,
|
||||||
|
"key": {
|
||||||
|
"range": "x.d2,2:1:21-2:12:32",
|
||||||
|
"key": {
|
||||||
|
"range": "x.d2,2:1:21-2:6:26",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "x.d2,2:1:21-2:6:26",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "label",
|
||||||
|
"raw_string": "label"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "x.d2,2:8:28-2:12:32",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "meow",
|
||||||
|
"raw_string": "meow"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"edges": null
|
||||||
|
},
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"string": {
|
||||||
|
"range": "index.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path": {
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"context": {
|
||||||
|
"edge": null,
|
||||||
|
"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,
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "index.d2,0:4:4-0:5:5",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "index.d2,0:6:6-0:7:7",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "y",
|
||||||
|
"raw_string": "y"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"edges": null
|
||||||
|
}
|
||||||
101
testdata/d2ir/TestCompile/imports/nested/scalar.exp.json
generated
vendored
Normal file
101
testdata/d2ir/TestCompile/imports/nested/scalar.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
{
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "x",
|
||||||
|
"primary": {
|
||||||
|
"value": {
|
||||||
|
"range": "x.d2,0:3:3-0:7:7",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "meow",
|
||||||
|
"raw_string": "meow"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"string": {
|
||||||
|
"range": "index.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path": {
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"context": {
|
||||||
|
"edge": null,
|
||||||
|
"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,
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "index.d2,0:4:4-0:5:5",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "index.d2,0:6:6-0:7:7",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "y",
|
||||||
|
"raw_string": "y"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"edges": null
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue