From c3fbf873bf7724a77220f4f215c99a7b6d3e5864 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 17 Nov 2024 21:13:06 -0800 Subject: [PATCH] add test --- d2compiler/compile_test.go | 16 ++ .../TestCompile/var_in_markdown.exp.json | 195 ++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 testdata/d2compiler/TestCompile/var_in_markdown.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 379c6bfb1..3fb75077f 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -2865,6 +2865,22 @@ x*: { tassert.Equal(t, "x2.ok", g.Objects[3].AbsID()) }, }, + { + name: "var_in_markdown", + text: `vars: { + v: { + ok + } +} + +x: |md + m${v}y +| +`, + assertions: func(t *testing.T, g *d2graph.Graph) { + tassert.Equal(t, "moky", g.Objects[0].Attributes.Label.Value) + }, + }, { name: "var_in_vars", text: `vars: { diff --git a/testdata/d2compiler/TestCompile/var_in_markdown.exp.json b/testdata/d2compiler/TestCompile/var_in_markdown.exp.json new file mode 100644 index 000000000..aee91bb0d --- /dev/null +++ b/testdata/d2compiler/TestCompile/var_in_markdown.exp.json @@ -0,0 +1,195 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,0:0:0-9:0:47", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,0:0:0-4:1:27", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,0:6:6-4:1:27", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,1:2:10-3:3:25", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,1:2:10-1:3:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,1:2:10-1:3:11", + "value": [ + { + "string": "v", + "raw_string": "v" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,1:5:13-3:3:25", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,2:4:19-2:6:21", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,2:4:19-2:6:21", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,2:4:19-2:6:21", + "value": [ + { + "string": "ok", + "raw_string": "ok" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,6:0:29-8:1:46", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,6:0:29-6:1:30", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,6:0:29-6:1:30", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "block_string": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,6:3:32-8:1:46", + "quote": "", + "tag": "md", + "value": "m${v}y" + } + } + } + } + ] + }, + "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": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,6:0:29-6:1:30", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/var_in_markdown.d2,6:0:29-6:1:30", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "m${v}y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "language": "markdown", + "shape": { + "value": "text" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +}