Merge pull request #837 from ejulio-ts/fix-serde

serde: fiz deserialize
This commit is contained in:
Júlio César Batista 2023-02-17 15:57:25 -03:00 committed by GitHub
commit a28dcd31d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 11 deletions

View file

@ -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)

View file

@ -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)]
}

View file

@ -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)