values must be positive

This commit is contained in:
Gavin Nishizawa 2023-04-03 11:52:12 -07:00
parent abe27cdc26
commit 06fb313d3e
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
4 changed files with 9 additions and 15 deletions

View file

@ -368,8 +368,8 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) {
c.errorf(scalar, "non-integer rows %#v: %s", scalar.ScalarString(), err)
return
}
if v < 0 {
c.errorf(scalar, "rows must be a non-negative integer: %#v", scalar.ScalarString())
if v <= 0 {
c.errorf(scalar, "rows must be a positive integer: %#v", scalar.ScalarString())
return
}
attrs.Rows = &d2graph.Scalar{}
@ -381,8 +381,8 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) {
c.errorf(scalar, "non-integer columns %#v: %s", scalar.ScalarString(), err)
return
}
if v < 0 {
c.errorf(scalar, "columns must be a non-negative integer: %#v", scalar.ScalarString())
if v <= 0 {
c.errorf(scalar, "columns must be a positive integer: %#v", scalar.ScalarString())
return
}
attrs.Columns = &d2graph.Scalar{}

View file

@ -2286,7 +2286,7 @@ obj {
columns: -200
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/grid_negative.d2:3:11: columns must be a non-negative integer: "-200"`,
expErr: `d2/testdata/d2compiler/TestCompile/grid_negative.d2:3:11: columns must be a positive integer: "-200"`,
},
}

View file

@ -29,15 +29,9 @@ func newGrid(root *d2graph.Object) *grid {
// TODO consider making this based on node dimensions
if g.rows == 0 {
// set rows based on number of columns
if g.columns == 0 {
// 0,0: put everything in one row
g.rows = 1
g.columns = len(g.nodes)
} else {
g.rows = len(g.nodes) / g.columns
if len(g.nodes)%g.columns != 0 {
g.rows++
}
g.rows = len(g.nodes) / g.columns
if len(g.nodes)%g.columns != 0 {
g.rows++
}
} else if g.columns == 0 {
// set columns based on number of rows

View file

@ -5,7 +5,7 @@
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/grid_negative.d2,2:10:28-2:14:32",
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_negative.d2:3:11: columns must be a non-negative integer: \"-200\""
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_negative.d2:3:11: columns must be a positive integer: \"-200\""
}
]
}