Merge pull request #1364 from berniexie/no-empty-block-strings
compile: no empty block strings
This commit is contained in:
commit
69b816c1b4
9 changed files with 70 additions and 21 deletions
|
|
@ -18,3 +18,4 @@
|
||||||
- Fixes panic using reserved keywords as containers [#1358](https://github.com/terrastruct/d2/pull/1358)
|
- Fixes panic using reserved keywords as containers [#1358](https://github.com/terrastruct/d2/pull/1358)
|
||||||
- When multiple classes are applied changing different attributes of arrowheads, they are
|
- When multiple classes are applied changing different attributes of arrowheads, they are
|
||||||
all applied instead of only the last one [#1362](https://github.com/terrastruct/d2/pull/1362)
|
all applied instead of only the last one [#1362](https://github.com/terrastruct/d2/pull/1362)
|
||||||
|
- Prevent empty block strings [#1364](https://github.com/terrastruct/d2/pull/1364)
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,9 @@ func (c *compiler) compileLabel(attrs *d2graph.Attributes, f d2ir.Node) {
|
||||||
// TODO: Delete instead.
|
// TODO: Delete instead.
|
||||||
attrs.Label.Value = scalar.ScalarString()
|
attrs.Label.Value = scalar.ScalarString()
|
||||||
case *d2ast.BlockString:
|
case *d2ast.BlockString:
|
||||||
|
if strings.TrimSpace(scalar.ScalarString()) == "" {
|
||||||
|
c.errorf(f.LastPrimaryKey(), "block string cannot be empty")
|
||||||
|
}
|
||||||
attrs.Language = scalar.Tag
|
attrs.Language = scalar.Tag
|
||||||
fullTag, ok := ShortToFullLanguageAliases[scalar.Tag]
|
fullTag, ok := ShortToFullLanguageAliases[scalar.Tag]
|
||||||
if ok {
|
if ok {
|
||||||
|
|
|
||||||
|
|
@ -610,6 +610,24 @@ x: {
|
||||||
expErr: `d2/testdata/d2compiler/TestCompile/md_block_string_err.d2:4:19: unexpected text after md block string. See https://d2lang.com/tour/text#advanced-block-strings.
|
expErr: `d2/testdata/d2compiler/TestCompile/md_block_string_err.d2:4:19: unexpected text after md block string. See https://d2lang.com/tour/text#advanced-block-strings.
|
||||||
d2/testdata/d2compiler/TestCompile/md_block_string_err.d2:5:1: block string must be terminated with |`,
|
d2/testdata/d2compiler/TestCompile/md_block_string_err.d2:5:1: block string must be terminated with |`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "no_empty_block_string",
|
||||||
|
text: `Text: |md |`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/no_empty_block_string.d2:1:1: block string cannot be empty`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "no_white_spaces_only_block_string",
|
||||||
|
text: `Text: |md |`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/no_white_spaces_only_block_string.d2:1:1: block string cannot be empty`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "no_new_lines_only_block_string",
|
||||||
|
text: `Text: |md
|
||||||
|
|
||||||
|
|
||||||
|
|`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/no_new_lines_only_block_string.d2:1:1: block string cannot be empty`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "underscore_edge_existing",
|
name: "underscore_edge_existing",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,6 @@ func testMeasured(t *testing.T) {
|
||||||
name: "empty-sql_table",
|
name: "empty-sql_table",
|
||||||
mtexts: []*d2target.MText{},
|
mtexts: []*d2target.MText{},
|
||||||
script: `a: "" { shape: sql_table }
|
script: `a: "" { shape: sql_table }
|
||||||
`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "empty-markdown",
|
|
||||||
mtexts: []*d2target.MText{},
|
|
||||||
script: `a: |md
|
|
||||||
` + " " + `
|
|
||||||
|
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -929,19 +929,6 @@ cf many required: {
|
||||||
style.stroke-width: 8
|
style.stroke-width: 8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "empty_md_measurement",
|
|
||||||
script: `
|
|
||||||
a
|
|
||||||
b: |md
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
c
|
|
||||||
d
|
|
||||||
a -> b -> c
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
loadFromFile(t, "slow_grid"),
|
loadFromFile(t, "slow_grid"),
|
||||||
|
|
|
||||||
12
testdata/d2compiler/TestCompile/no_empty_block_string.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/no_empty_block_string.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"ioerr": null,
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/no_empty_block_string.d2,0:0:0-0:11:11",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/no_empty_block_string.d2:1:1: block string cannot be empty"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
12
testdata/d2compiler/TestCompile/no_empty_block_strings.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/no_empty_block_strings.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"ioerr": null,
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/no_empty_block_strings.d2,0:0:0-0:11:11",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/no_empty_block_strings.d2:1:1: block string cannot be empty"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
12
testdata/d2compiler/TestCompile/no_new_lines_only_block_string.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/no_new_lines_only_block_string.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"ioerr": null,
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/no_new_lines_only_block_string.d2,0:0:0-3:1:13",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/no_new_lines_only_block_string.d2:1:1: block string cannot be empty"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
12
testdata/d2compiler/TestCompile/no_white_spaces_only_block_string.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/no_white_spaces_only_block_string.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"ioerr": null,
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/no_white_spaces_only_block_string.d2,0:0:0-0:16:16",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/no_white_spaces_only_block_string.d2:1:1: block string cannot be empty"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue