File: diff.go

package info (click to toggle)
golang-github-abdullin-seq 0.0~git20160510.d5467c1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 88 kB
  • sloc: makefile: 8
file content (33 lines) | stat: -rw-r--r-- 544 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package seq

import "strings"

func hasNestedObject(actual map[string]string, key string) bool {
	for k, _ := range actual {
		if strings.HasPrefix(k, key) {
			return true
		}
	}
	return false
}

func diff(expected, actual map[string]string) *Result {
	res := NewResult()

	for ek, ev := range expected {
		var av, ok = actual[ek]

		if !ok {
			if hasNestedObject(actual, ek) {
				res.AddIssue(ek, ev, "{Object}")
			} else {
				res.AddIssue(ek, ev, "nothing")
			}

		} else if av != ev {
			res.AddIssue(ek, ev, av)
		}
	}

	return res
}