add overlay tests
This commit is contained in:
parent
fd70b5ef46
commit
7269ee1706
3 changed files with 1494 additions and 0 deletions
|
|
@ -3296,6 +3296,59 @@ layers: {
|
||||||
assert.Equal(t, "im a var", g.Layers[0].Objects[0].Label.Value)
|
assert.Equal(t, "im a var", g.Layers[0].Objects[0].Label.Value)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "scenario",
|
||||||
|
run: func(t *testing.T) {
|
||||||
|
g := assertCompile(t, `
|
||||||
|
vars: {
|
||||||
|
x: im a var
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios: {
|
||||||
|
l: {
|
||||||
|
hi: ${x}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, "")
|
||||||
|
assert.Equal(t, 1, len(g.Scenarios[0].Objects))
|
||||||
|
assert.Equal(t, "im a var", g.Scenarios[0].Objects[0].Label.Value)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "overlay",
|
||||||
|
run: func(t *testing.T) {
|
||||||
|
g := assertCompile(t, `
|
||||||
|
vars: {
|
||||||
|
x: im x var
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios: {
|
||||||
|
l: {
|
||||||
|
vars: {
|
||||||
|
y: im y var
|
||||||
|
}
|
||||||
|
x: ${x}
|
||||||
|
y: ${y}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
layers: {
|
||||||
|
l2: {
|
||||||
|
vars: {
|
||||||
|
y: im y var
|
||||||
|
}
|
||||||
|
x: ${x}
|
||||||
|
y: ${y}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, "")
|
||||||
|
assert.Equal(t, 2, len(g.Scenarios[0].Objects))
|
||||||
|
assert.Equal(t, "im x var", g.Scenarios[0].Objects[0].Label.Value)
|
||||||
|
assert.Equal(t, "im y var", g.Scenarios[0].Objects[1].Label.Value)
|
||||||
|
assert.Equal(t, 2, len(g.Layers[0].Objects))
|
||||||
|
assert.Equal(t, "im x var", g.Layers[0].Objects[0].Label.Value)
|
||||||
|
assert.Equal(t, "im y var", g.Layers[0].Objects[1].Label.Value)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tca {
|
for _, tc := range tca {
|
||||||
|
|
|
||||||
1069
testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json
generated
vendored
Normal file
1069
testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
372
testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json
generated
vendored
Normal file
372
testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,372 @@
|
||||||
|
{
|
||||||
|
"graph": {
|
||||||
|
"name": "",
|
||||||
|
"isFolderOnly": false,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,0:0:0-10:0:65",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,1:0:1-3:1:24",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,1:0:1-1:4:5",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,1:0:1-1:4:5",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "vars",
|
||||||
|
"raw_string": "vars"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"map": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,1:6:7-3:1:24",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:2:11-2:13:22",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:2:11-2:3:12",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:2:11-2:3:12",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "im a var",
|
||||||
|
"raw_string": "im a var"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,5:0:26-9:1:64",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,5:0:26-5:9:35",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,5:0:26-5:9:35",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "scenarios",
|
||||||
|
"raw_string": "scenarios"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"map": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,5:11:37-9:1:64",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,6:2:41-8:3:62",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,6:2:41-6:3:42",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,6:2:41-6:3:42",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "l",
|
||||||
|
"raw_string": "l"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"map": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,6:5:44-8:3:62",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:4:50-7:12:58",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:4:50-7:6:52",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:4:50-7:6:52",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "hi",
|
||||||
|
"raw_string": "hi"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"substitution": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:12:58",
|
||||||
|
"spread": false,
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:10:56-7:11:57",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"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": null,
|
||||||
|
"scenarios": [
|
||||||
|
{
|
||||||
|
"name": "l",
|
||||||
|
"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": "vars"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"map": {
|
||||||
|
"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": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "im a var",
|
||||||
|
"raw_string": "im a var"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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": "hi"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "im a var",
|
||||||
|
"raw_string": "im a var"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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": "hi",
|
||||||
|
"id_val": "hi",
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:4:50-7:6:52",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:4:50-7:6:52",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "hi",
|
||||||
|
"raw_string": "hi"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path_index": 0,
|
||||||
|
"map_key_edge_index": -1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": "im a var"
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": "rectangle"
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"err": null
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue