Merge pull request #837 from ejulio-ts/fix-serde
serde: fiz deserialize
This commit is contained in:
commit
a28dcd31d4
3 changed files with 12 additions and 11 deletions
|
|
@ -13,3 +13,4 @@
|
|||
- Fixes rare compiler bug when using underscores in edges to create objects across containers. [#824](https://github.com/terrastruct/d2/pull/824)
|
||||
- Fixes rare possibility of rendered connections being hidden or cut off. [#828](https://github.com/terrastruct/d2/pull/828)
|
||||
- Creating nested children within `sql_table` and `class` shapes are now prevented (caused confusion when accidentally done). [#834](https://github.com/terrastruct/d2/pull/834)
|
||||
- Fixes graph deserialization bug. [#837](https://github.com/terrastruct/d2/pull/837)
|
||||
|
|
@ -49,7 +49,7 @@ func DeserializeGraph(bytes []byte, g *Graph) error {
|
|||
for _, id := range so["ChildrenArray"].([]interface{}) {
|
||||
o := idToObj[id.(string)]
|
||||
childrenArray = append(childrenArray, o)
|
||||
children[strings.ToLower(id.(string))] = o
|
||||
children[strings.ToLower(o.ID)] = o
|
||||
|
||||
o.Parent = idToObj[so["AbsID"].(string)]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,19 +17,19 @@ func TestSerialization(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
|
||||
asserts := func(g *d2graph.Graph) {
|
||||
a := g.Root.ChildrenArray[0]
|
||||
a_a := a.ChildrenArray[0]
|
||||
|
||||
assert.Equal(t, 4, len(g.Objects))
|
||||
assert.Equal(t, 1, len(g.Root.ChildrenArray))
|
||||
assert.Equal(t, 1, len(g.Root.ChildrenArray[0].ChildrenArray))
|
||||
assert.Equal(t, 2, len(g.Root.ChildrenArray[0].ChildrenArray[0].ChildrenArray))
|
||||
assert.Equal(t,
|
||||
g.Root.ChildrenArray[0],
|
||||
g.Root.ChildrenArray[0].ChildrenArray[0].Parent,
|
||||
)
|
||||
assert.Equal(t, 1, len(a.ChildrenArray))
|
||||
assert.Equal(t, 2, len(a_a.ChildrenArray))
|
||||
assert.Equal(t, a, a_a.Parent)
|
||||
assert.Equal(t, g.Root, a.Parent)
|
||||
|
||||
assert.Equal(t,
|
||||
g.Root,
|
||||
g.Root.ChildrenArray[0].Parent,
|
||||
)
|
||||
assert.Contains(t, a.Children, "a")
|
||||
assert.Contains(t, a_a.Children, "b")
|
||||
assert.Contains(t, a_a.Children, "c")
|
||||
|
||||
assert.Equal(t, 1, len(g.Edges))
|
||||
assert.Equal(t, "b", g.Edges[0].Src.ID)
|
||||
|
|
|
|||
Loading…
Reference in a new issue