MCPcopy Create free account
hub / github.com/aws-cloudformation/rain / Diff

Function Diff

internal/node/node.go:303–331  ·  view source on GitHub ↗

Diff returns an array of strings describing differences between two nodes

(node1, node2 *yaml.Node)

Source from the content-addressed store, hash-verified

301
302// Diff returns an array of strings describing differences between two nodes
303func Diff(node1, node2 *yaml.Node) (diffs []string) {
304 switch {
305 case node1 == nil && node2 == nil:
306 return nil
307 case node1 == nil:
308 diffs = append(diffs, fmt.Sprintf("Node2: %v", node2.Value))
309 case node2 == nil:
310 diffs = append(diffs, fmt.Sprintf("Node1: %v", node1.Value))
311 default:
312 if node1.Kind != node2.Kind {
313 diffs = append(diffs, fmt.Sprintf("Node1: %v, Node2: %v", node1.Value, node2.Value))
314 } else {
315 switch node1.Kind {
316 case yaml.MappingNode:
317 diffs = appendMappingDiffs(diffs, node1, node2)
318 case yaml.SequenceNode:
319 diffs = appendSequenceDiffs(diffs, node1, node2)
320 case yaml.ScalarNode:
321 if node1.Value != node2.Value {
322 diffs = append(diffs,
323 fmt.Sprintf("Node1: %v, Node2: %v", node1.Value, node2.Value))
324 }
325 default:
326 diffs = append(diffs, fmt.Sprintf("Unsupported node kind: %v", node1.Kind))
327 }
328 }
329 }
330 return diffs
331}
332
333func appendMappingDiffs(diffs []string, node1, node2 *yaml.Node) []string {
334 keys1 := make(map[string]yaml.Node)

Callers 5

TestDiffFunction · 0.92
TestMergeNodesFunction · 0.92
TestMergeNodes2Function · 0.92
appendDiffsFunction · 0.70

Calls 2

appendMappingDiffsFunction · 0.85
appendSequenceDiffsFunction · 0.85

Tested by 4

TestDiffFunction · 0.74
TestMergeNodesFunction · 0.74
TestMergeNodes2Function · 0.74