fix id/idval
This commit is contained in:
parent
b1a318631b
commit
96288dd369
6 changed files with 23 additions and 17 deletions
|
|
@ -2113,7 +2113,7 @@ b
|
|||
tassert.Equal(t, 5, len(g.Objects))
|
||||
tassert.Equal(t, "a", g.Objects[0].ID)
|
||||
tassert.Equal(t, "b", g.Objects[1].ID)
|
||||
tassert.Equal(t, `04:20,11:20`, g.Objects[2].ID)
|
||||
tassert.Equal(t, `"04:20,11:20"`, g.Objects[2].ID)
|
||||
tassert.Equal(t, `loop through each table`, g.Objects[3].ID)
|
||||
tassert.Equal(t, 1, len(g.Objects[0].ChildrenArray))
|
||||
tassert.Equal(t, 0, len(g.Objects[1].ChildrenArray))
|
||||
|
|
|
|||
|
|
@ -694,7 +694,10 @@ func (obj *Object) Text() *d2target.MText {
|
|||
}
|
||||
}
|
||||
|
||||
func (obj *Object) newObject(id string) *Object {
|
||||
func (obj *Object) newObject(ids d2ast.String) *Object {
|
||||
id := d2format.Format(&d2ast.KeyPath{
|
||||
Path: []*d2ast.StringBox{d2ast.MakeValueBox(d2ast.RawString(ids.ScalarString(), true)).StringBox()},
|
||||
})
|
||||
idval := id
|
||||
k, _ := d2parser.ParseKey(id)
|
||||
if k != nil && len(k.Path) > 0 {
|
||||
|
|
@ -901,9 +904,12 @@ func (obj *Object) EnsureChild(ida []d2ast.String) *Object {
|
|||
return obj.Parent.EnsureChild(ida)
|
||||
}
|
||||
|
||||
child, ok := obj.Children[strings.ToLower(id.ScalarString())]
|
||||
head := d2format.Format(&d2ast.KeyPath{
|
||||
Path: []*d2ast.StringBox{d2ast.MakeValueBox(d2ast.RawString(id.ScalarString(), true)).StringBox()},
|
||||
})
|
||||
child, ok := obj.Children[strings.ToLower(head)]
|
||||
if !ok {
|
||||
child = obj.newObject(id.ScalarString())
|
||||
child = obj.newObject(id)
|
||||
}
|
||||
|
||||
if len(ida) >= 1 {
|
||||
|
|
|
|||
6
testdata/d2compiler/TestCompile/escaped_id.exp.json
generated
vendored
6
testdata/d2compiler/TestCompile/escaped_id.exp.json
generated
vendored
|
|
@ -56,8 +56,8 @@
|
|||
"edges": null,
|
||||
"objects": [
|
||||
{
|
||||
"id": "b\nb",
|
||||
"id_val": "b",
|
||||
"id": "\"b\\nb\"",
|
||||
"id_val": "b\nb",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
|
|
@ -82,7 +82,7 @@
|
|||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "b"
|
||||
"value": "b\nb"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
|
|
|
|||
6
testdata/d2compiler/TestCompile/name-with-dot-underscore.exp.json
generated
vendored
6
testdata/d2compiler/TestCompile/name-with-dot-underscore.exp.json
generated
vendored
|
|
@ -291,8 +291,8 @@
|
|||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "D.E",
|
||||
"id_val": "D",
|
||||
"id": "\"D.E\"",
|
||||
"id_val": "D.E",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
|
|
@ -317,7 +317,7 @@
|
|||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "D"
|
||||
"value": "D.E"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
|
|
|
|||
2
testdata/d2compiler/TestCompile/null.exp.json
generated
vendored
2
testdata/d2compiler/TestCompile/null.exp.json
generated
vendored
|
|
@ -56,7 +56,7 @@
|
|||
"edges": null,
|
||||
"objects": [
|
||||
{
|
||||
"id": "null",
|
||||
"id": "'null'",
|
||||
"id_val": "null",
|
||||
"references": [
|
||||
{
|
||||
|
|
|
|||
12
testdata/d2compiler/TestCompile/sequence-timestamp.exp.json
generated
vendored
12
testdata/d2compiler/TestCompile/sequence-timestamp.exp.json
generated
vendored
|
|
@ -442,8 +442,8 @@
|
|||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "04:20,11:20",
|
||||
"id_val": "04",
|
||||
"id": "\"04:20,11:20\"",
|
||||
"id_val": "04:20,11:20",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
|
|
@ -468,7 +468,7 @@
|
|||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "04"
|
||||
"value": "04:20,11:20"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
|
|
@ -532,8 +532,8 @@
|
|||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "start_time = datetime.datetime.now",
|
||||
"id_val": "start_time = datetime",
|
||||
"id": "\"start_time = datetime.datetime.now\"",
|
||||
"id_val": "start_time = datetime.datetime.now",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
|
|
@ -569,7 +569,7 @@
|
|||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "start_time = datetime"
|
||||
"value": "start_time = datetime.datetime.now"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
|
|
|
|||
Loading…
Reference in a new issue