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 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)
|
- 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)
|
- 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{}) {
|
for _, id := range so["ChildrenArray"].([]interface{}) {
|
||||||
o := idToObj[id.(string)]
|
o := idToObj[id.(string)]
|
||||||
childrenArray = append(childrenArray, o)
|
childrenArray = append(childrenArray, o)
|
||||||
children[strings.ToLower(id.(string))] = o
|
children[strings.ToLower(o.ID)] = o
|
||||||
|
|
||||||
o.Parent = idToObj[so["AbsID"].(string)]
|
o.Parent = idToObj[so["AbsID"].(string)]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,19 +17,19 @@ func TestSerialization(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
asserts := func(g *d2graph.Graph) {
|
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, 4, len(g.Objects))
|
||||||
assert.Equal(t, 1, len(g.Root.ChildrenArray))
|
assert.Equal(t, 1, len(g.Root.ChildrenArray))
|
||||||
assert.Equal(t, 1, len(g.Root.ChildrenArray[0].ChildrenArray))
|
assert.Equal(t, 1, len(a.ChildrenArray))
|
||||||
assert.Equal(t, 2, len(g.Root.ChildrenArray[0].ChildrenArray[0].ChildrenArray))
|
assert.Equal(t, 2, len(a_a.ChildrenArray))
|
||||||
assert.Equal(t,
|
assert.Equal(t, a, a_a.Parent)
|
||||||
g.Root.ChildrenArray[0],
|
assert.Equal(t, g.Root, a.Parent)
|
||||||
g.Root.ChildrenArray[0].ChildrenArray[0].Parent,
|
|
||||||
)
|
|
||||||
|
|
||||||
assert.Equal(t,
|
assert.Contains(t, a.Children, "a")
|
||||||
g.Root,
|
assert.Contains(t, a_a.Children, "b")
|
||||||
g.Root.ChildrenArray[0].Parent,
|
assert.Contains(t, a_a.Children, "c")
|
||||||
)
|
|
||||||
|
|
||||||
assert.Equal(t, 1, len(g.Edges))
|
assert.Equal(t, 1, len(g.Edges))
|
||||||
assert.Equal(t, "b", g.Edges[0].Src.ID)
|
assert.Equal(t, "b", g.Edges[0].Src.ID)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue