Add tests for IsTaggedNull, IsYNodeEmptySeq and IsYNodeEmptyMap.

This commit is contained in:
jregan
2020-08-09 12:15:22 -07:00
parent 01b34c8ea0
commit 5559601ecb
5 changed files with 98 additions and 13 deletions

View File

@@ -49,10 +49,6 @@ func IsEmptyMap(node *RNode) bool {
return IsMissingOrNull(node) || IsYNodeEmptyMap(node.YNode())
}
func IsNull(node *RNode) bool {
return !node.IsNil() && node.YNode().Tag == NodeTagNull
}
func IsFieldEmpty(node *MapNode) bool {
if node == nil || node.Value == nil || node.Value.YNode() == nil ||
node.Value.YNode().Tag == NodeTagNull {
@@ -63,11 +59,16 @@ func IsFieldEmpty(node *MapNode) bool {
}
func IsYNodeEmptyMap(n *yaml.Node) bool {
return n.Kind == yaml.MappingNode && len(n.Content) == 0
return n != nil && n.Kind == yaml.MappingNode && len(n.Content) == 0
}
// IsYNodeTaggedNull returns true if the node is explicitly tagged Null.
func IsYNodeTaggedNull(n *yaml.Node) bool {
return n != nil && n.Tag == NodeTagNull
}
func IsYNodeEmptySeq(n *yaml.Node) bool {
return n.Kind == yaml.SequenceNode && len(n.Content) == 0
return n != nil && n.Kind == yaml.SequenceNode && len(n.Content) == 0
}
// IsYNodeEmptyDoc is true if the node is a Document with no content.
@@ -377,6 +378,11 @@ func (rn *RNode) IsNil() bool {
return rn == nil || rn.YNode() == nil
}
// IsTaggedNull is true if a non-nil node is explicitly tagged Null.
func (rn *RNode) IsTaggedNull() bool {
return !rn.IsNil() && IsYNodeTaggedNull(rn.YNode())
}
// GetMeta returns the ResourceMeta for an RNode
func (rn *RNode) GetMeta() (ResourceMeta, error) {
if IsMissingOrNull(rn) {