prevent bad constraint usage
This commit is contained in:
parent
202ffa254b
commit
a283e619bb
3 changed files with 11 additions and 178 deletions
|
|
@ -886,6 +886,10 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) {
|
||||||
if !in && arrowheadIn {
|
if !in && arrowheadIn {
|
||||||
c.errorf(f.LastPrimaryKey(), fmt.Sprintf(`invalid shape, can only set "%s" for arrowheads`, obj.Shape.Value))
|
c.errorf(f.LastPrimaryKey(), fmt.Sprintf(`invalid shape, can only set "%s" for arrowheads`, obj.Shape.Value))
|
||||||
}
|
}
|
||||||
|
case "constraint":
|
||||||
|
if obj.Shape.Value != d2target.ShapeSQLTable {
|
||||||
|
c.errorf(f.LastPrimaryKey(), `"constraint" keyword can only be used in "sql_table" shapes`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2117,9 +2117,7 @@ ok: {
|
||||||
label: bar
|
label: bar
|
||||||
constraint: BIZ
|
constraint: BIZ
|
||||||
}`,
|
}`,
|
||||||
assertions: func(t *testing.T, g *d2graph.Graph) {
|
expErr: `d2/testdata/d2compiler/TestCompile/constraint_label.d2:3:3: "constraint" keyword can only be used in "sql_table" shapes`,
|
||||||
assert.String(t, "bar", g.Objects[0].Label.Value)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid_direction",
|
name: "invalid_direction",
|
||||||
|
|
|
||||||
177
testdata/d2compiler/TestCompile/constraint_label.exp.json
generated
vendored
177
testdata/d2compiler/TestCompile/constraint_label.exp.json
generated
vendored
|
|
@ -1,180 +1,11 @@
|
||||||
{
|
{
|
||||||
"graph": {
|
"graph": null,
|
||||||
"name": "",
|
"err": {
|
||||||
"isFolderOnly": false,
|
"errs": [
|
||||||
"ast": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-3:1:38",
|
|
||||||
"nodes": [
|
|
||||||
{
|
{
|
||||||
"map_key": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-3:1:38",
|
|
||||||
"key": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-0:3:3",
|
|
||||||
"path": [
|
|
||||||
{
|
|
||||||
"unquoted_string": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-0:3:3",
|
|
||||||
"value": [
|
|
||||||
{
|
|
||||||
"string": "foo",
|
|
||||||
"raw_string": "foo"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"primary": {},
|
|
||||||
"value": {
|
|
||||||
"map": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:4:4-3:1:38",
|
|
||||||
"nodes": [
|
|
||||||
{
|
|
||||||
"map_key": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,1:2:8-1:12:18",
|
|
||||||
"key": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,1:2:8-1:7:13",
|
|
||||||
"path": [
|
|
||||||
{
|
|
||||||
"unquoted_string": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,1:2:8-1:7:13",
|
|
||||||
"value": [
|
|
||||||
{
|
|
||||||
"string": "label",
|
|
||||||
"raw_string": "label"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"primary": {},
|
|
||||||
"value": {
|
|
||||||
"unquoted_string": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,1:9:15-1:12:18",
|
|
||||||
"value": [
|
|
||||||
{
|
|
||||||
"string": "bar",
|
|
||||||
"raw_string": "bar"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"map_key": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,2:2:21-2:17:36",
|
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,2:2:21-2:17:36",
|
||||||
"key": {
|
"errmsg": "d2/testdata/d2compiler/TestCompile/constraint_label.d2:3:3: \"constraint\" keyword can only be used in \"sql_table\" shapes"
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,2:2:21-2:12:31",
|
|
||||||
"path": [
|
|
||||||
{
|
|
||||||
"unquoted_string": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,2:2:21-2:12:31",
|
|
||||||
"value": [
|
|
||||||
{
|
|
||||||
"string": "constraint",
|
|
||||||
"raw_string": "constraint"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
|
||||||
},
|
|
||||||
"primary": {},
|
|
||||||
"value": {
|
|
||||||
"unquoted_string": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,2:14:33-2:17:36",
|
|
||||||
"value": [
|
|
||||||
{
|
|
||||||
"string": "BIZ",
|
|
||||||
"raw_string": "BIZ"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"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": "foo",
|
|
||||||
"id_val": "foo",
|
|
||||||
"references": [
|
|
||||||
{
|
|
||||||
"key": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-0:3:3",
|
|
||||||
"path": [
|
|
||||||
{
|
|
||||||
"unquoted_string": {
|
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-0:3:3",
|
|
||||||
"value": [
|
|
||||||
{
|
|
||||||
"string": "foo",
|
|
||||||
"raw_string": "foo"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"key_path_index": 0,
|
|
||||||
"map_key_edge_index": -1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"attributes": {
|
|
||||||
"label": {
|
|
||||||
"value": "bar"
|
|
||||||
},
|
|
||||||
"labelDimensions": {
|
|
||||||
"width": 0,
|
|
||||||
"height": 0
|
|
||||||
},
|
|
||||||
"style": {},
|
|
||||||
"near_key": null,
|
|
||||||
"shape": {
|
|
||||||
"value": "rectangle"
|
|
||||||
},
|
|
||||||
"direction": {
|
|
||||||
"value": ""
|
|
||||||
},
|
|
||||||
"constraint": [
|
|
||||||
"BIZ"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"zIndex": 0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"err": null
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue