Skip to content

Commit

Permalink
Show empty keys in diffs correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanSerikov committed Feb 1, 2021
1 parent 9c14b94 commit 56b263c
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/contractparser/newmiguel/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (l *listDecoder) Decode(data gjson.Result, path string, nm *meta.NodeMetada
node := Node{
Prim: nm.Prim,
Type: nm.Type,
Name: nm.Name,
Name: &(nm.Name),
Children: make([]*Node, 0),
}

Expand Down
5 changes: 1 addition & 4 deletions internal/contractparser/newmiguel/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (l *mapDecoder) Decode(data gjson.Result, path string, nm *meta.NodeMetadat
if err != nil {
return nil, err
}
argNode.Name = s
argNode.Name = &s
node.Children = append(node.Children, argNode)
}
}
Expand All @@ -76,9 +76,6 @@ func (l *mapDecoder) Decode(data gjson.Result, path string, nm *meta.NodeMetadat
func (l *mapDecoder) getKey(key *Node) (s string, err error) {
switch kv := key.Value.(type) {
case string:
if kv == "" {
kv = `""`
}
s = kv
case int, int64:
s = fmt.Sprintf("%d", kv)
Expand Down
4 changes: 2 additions & 2 deletions internal/contractparser/newmiguel/namedtuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func (l *namedTupleDecoder) Decode(data gjson.Result, path string, nm *meta.Node
if err != nil {
return nil, err
}
argNode.Name = name
argNode.Name = &name
node.Children = append(node.Children, argNode)
} else {
node.Children = append(node.Children, &Node{
Name: name,
Name: &name,
Value: nil,
})
}
Expand Down
6 changes: 4 additions & 2 deletions internal/contractparser/newmiguel/namedunion.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ func (l *namedUnionDecoder) Decode(data gjson.Result, path string, nm *meta.Node
if err != nil {
return nil, err
}
argNode.Name = metadata.GetFieldName(arg, i)
name := metadata.GetFieldName(arg, i)
argNode.Name = &name
node.Children = append(node.Children, argNode)
return &node, nil
}
}
node.Name = metadata[path].GetName(-1)
name := metadata[path].GetName(-1)
node.Name = &name
return &node, nil
}
2 changes: 1 addition & 1 deletion internal/contractparser/newmiguel/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
type Node struct {
Prim string `json:"prim,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Name *string `json:"name,omitempty"`
From interface{} `json:"from,omitempty"`
DiffType string `json:"diff_type,omitempty"`
Value interface{} `json:"value,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion internal/contractparser/newmiguel/or.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func (l *orDecoder) Decode(data gjson.Result, path string, nm *meta.NodeMetadata
return nil, err
}

argNode.Name = metadata.GetFieldName(arg, i)
name := metadata.GetFieldName(arg, i)
argNode.Name = &name
node.Children = append(node.Children, argNode)
return &node, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/contractparser/newmiguel/tuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (l *tupleDecoder) Decode(data gjson.Result, path string, nm *meta.NodeMetad
node := Node{
Prim: nm.Prim,
Type: nm.Type,
Name: nm.Name,
Name: &(nm.Name),
Children: make([]*Node, 0),
}
if data.Value() == nil {
Expand All @@ -37,7 +37,7 @@ func (l *tupleDecoder) Decode(data gjson.Result, path string, nm *meta.NodeMetad
node.Children = append(node.Children, &Node{
Prim: argMeta.Prim,
Type: argMeta.Type,
Name: argMeta.Name,
Name: &(argMeta.Name),
Children: make([]*Node, 0),
})
}
Expand Down
6 changes: 4 additions & 2 deletions internal/contractparser/newmiguel/union.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ func (l *unionDecoder) Decode(data gjson.Result, path string, nm *meta.NodeMetad
return nil, err
}
argMeta := metadata[arg]
argNode.Name = argMeta.GetName(i)
name := argMeta.GetName(i)
argNode.Name = &name
node.Children = append(node.Children, argNode)
return &node, nil
}
}
node.Name = metadata[path].GetName(-1)
name := metadata[path].GetName(-1)
node.Name = &name
return &node, nil
}

0 comments on commit 56b263c

Please sign in to comment.