Merge pull request #245 from alixander/alixander/shape-sequence
syntax: shape: sequence
This commit is contained in:
commit
3f6b14cb00
5 changed files with 266 additions and 45 deletions
|
|
@ -266,6 +266,8 @@ func (c *compiler) compileKey(obj *d2graph.Object, m *d2ast.Map, mk *d2ast.Key)
|
|||
}, unresolvedObj)
|
||||
} else if obj.Parent == nil {
|
||||
// Top level reserved key set on root.
|
||||
c.compileAttributes(&obj.Attributes, mk)
|
||||
c.applyScalar(&obj.Attributes, reserved, mk.Value.ScalarBox())
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1501,6 +1501,26 @@ dst.id <-> src.dst_id
|
|||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "basic_sequence",
|
||||
|
||||
text: `x: {
|
||||
shape: sequence_diagram
|
||||
}
|
||||
`,
|
||||
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||
diff.AssertStringEq(t, "sequence_diagram", g.Objects[0].Attributes.Shape.Value)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "root_sequence",
|
||||
|
||||
text: `shape: sequence_diagram
|
||||
`,
|
||||
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||
diff.AssertStringEq(t, "sequence_diagram", g.Root.Attributes.Shape.Value)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
|||
|
|
@ -277,6 +277,7 @@ const (
|
|||
ShapeClass = "class"
|
||||
ShapeSQLTable = "sql_table"
|
||||
ShapeImage = "image"
|
||||
ShapeSequenceDiagram = "sequence_diagram"
|
||||
)
|
||||
|
||||
var Shapes = []string{
|
||||
|
|
@ -302,6 +303,7 @@ var Shapes = []string{
|
|||
ShapeClass,
|
||||
ShapeSQLTable,
|
||||
ShapeImage,
|
||||
ShapeSequenceDiagram,
|
||||
}
|
||||
|
||||
func IsShape(s string) bool {
|
||||
|
|
@ -368,6 +370,7 @@ var DSL_SHAPE_TO_SHAPE_TYPE = map[string]string{
|
|||
ShapeClass: shape.CLASS_TYPE,
|
||||
ShapeSQLTable: shape.TABLE_TYPE,
|
||||
ShapeImage: shape.IMAGE_TYPE,
|
||||
ShapeSequenceDiagram: shape.SQUARE_TYPE,
|
||||
}
|
||||
|
||||
var SHAPE_TYPE_TO_DSL_SHAPE map[string]string
|
||||
|
|
|
|||
133
testdata/d2compiler/TestCompile/basic_sequence.exp.json
generated
vendored
Normal file
133
testdata/d2compiler/TestCompile/basic_sequence.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
{
|
||||
"graph": {
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-3:0:33",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-2:1:32",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-0:1:1",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-0:1:1",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"map": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:3:3-2:0:31",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,1:2:7-1:25:30",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,1:2:7-1:7:12",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,1:2:7-1:7:12",
|
||||
"value": [
|
||||
{
|
||||
"string": "shape",
|
||||
"raw_string": "shape"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,1:9:14-1:25:30",
|
||||
"value": [
|
||||
{
|
||||
"string": "sequence_diagram",
|
||||
"raw_string": "sequence_diagram"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"root": {
|
||||
"id": "",
|
||||
"id_val": "",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
"edges": null,
|
||||
"objects": [
|
||||
{
|
||||
"id": "x",
|
||||
"id_val": "x",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-0:1:1",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-0:1:1",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": 0
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "x"
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "sequence_diagram"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"err": null
|
||||
}
|
||||
63
testdata/d2compiler/TestCompile/root_sequence.exp.json
generated
vendored
Normal file
63
testdata/d2compiler/TestCompile/root_sequence.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
"graph": {
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:0:0-1:0:24",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:0:0-0:23:23",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:0:0-0:5:5",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:0:0-0:5:5",
|
||||
"value": [
|
||||
{
|
||||
"string": "shape",
|
||||
"raw_string": "shape"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:7:7-0:23:23",
|
||||
"value": [
|
||||
{
|
||||
"string": "sequence_diagram",
|
||||
"raw_string": "sequence_diagram"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"root": {
|
||||
"id": "",
|
||||
"id_val": "",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "sequence_diagram"
|
||||
}
|
||||
}
|
||||
},
|
||||
"edges": null,
|
||||
"objects": null
|
||||
},
|
||||
"err": null
|
||||
}
|
||||
Loading…
Reference in a new issue