Merge pull request #864 from alixander/validate-topleft
validate top and left keywords
This commit is contained in:
commit
cb48ebdb81
3 changed files with 31 additions and 2 deletions
|
|
@ -288,20 +288,28 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) {
|
||||||
attrs.Height.Value = scalar.ScalarString()
|
attrs.Height.Value = scalar.ScalarString()
|
||||||
attrs.Height.MapKey = f.LastPrimaryKey()
|
attrs.Height.MapKey = f.LastPrimaryKey()
|
||||||
case "top":
|
case "top":
|
||||||
_, err := strconv.Atoi(scalar.ScalarString())
|
v, err := strconv.Atoi(scalar.ScalarString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.errorf(scalar, "non-integer top %#v: %s", scalar.ScalarString(), err)
|
c.errorf(scalar, "non-integer top %#v: %s", scalar.ScalarString(), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if v < 0 {
|
||||||
|
c.errorf(scalar, "top must be a non-negative integer: %#v", scalar.ScalarString())
|
||||||
|
return
|
||||||
|
}
|
||||||
attrs.Top = &d2graph.Scalar{}
|
attrs.Top = &d2graph.Scalar{}
|
||||||
attrs.Top.Value = scalar.ScalarString()
|
attrs.Top.Value = scalar.ScalarString()
|
||||||
attrs.Top.MapKey = f.LastPrimaryKey()
|
attrs.Top.MapKey = f.LastPrimaryKey()
|
||||||
case "left":
|
case "left":
|
||||||
_, err := strconv.Atoi(scalar.ScalarString())
|
v, err := strconv.Atoi(scalar.ScalarString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.errorf(scalar, "non-integer left %#v: %s", scalar.ScalarString(), err)
|
c.errorf(scalar, "non-integer left %#v: %s", scalar.ScalarString(), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if v < 0 {
|
||||||
|
c.errorf(scalar, "left must be a non-negative integer: %#v", scalar.ScalarString())
|
||||||
|
return
|
||||||
|
}
|
||||||
attrs.Left = &d2graph.Scalar{}
|
attrs.Left = &d2graph.Scalar{}
|
||||||
attrs.Left.Value = scalar.ScalarString()
|
attrs.Left.Value = scalar.ScalarString()
|
||||||
attrs.Left.MapKey = f.LastPrimaryKey()
|
attrs.Left.MapKey = f.LastPrimaryKey()
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,15 @@ x: {
|
||||||
tassert.Equal(t, "200", g.Objects[0].Attributes.Top.Value)
|
tassert.Equal(t, "200", g.Objects[0].Attributes.Top.Value)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "positions_negative",
|
||||||
|
text: `hey: {
|
||||||
|
top: 200
|
||||||
|
left: -200
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/positions_negative.d2:3:8: left must be a non-negative integer: "-200"`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "equal_dimensions_on_circle",
|
name: "equal_dimensions_on_circle",
|
||||||
|
|
||||||
|
|
|
||||||
12
testdata/d2compiler/TestCompile/positions_negative.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/positions_negative.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"ioerr": null,
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/positions_negative.d2,2:7:24-2:11:28",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/positions_negative.d2:3:8: left must be a non-negative integer: \"-200\""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue