-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathstring_list_diff.go
More file actions
48 lines (36 loc) · 1.07 KB
/
string_list_diff.go
File metadata and controls
48 lines (36 loc) · 1.07 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package diff
import "github.com/oasdiff/oasdiff/utils"
// StringsDiff describes the changes between a pair of lists of strings
type StringsDiff struct {
Added []string `json:"added,omitempty" yaml:"added,omitempty"`
Deleted []string `json:"deleted,omitempty" yaml:"deleted,omitempty"`
}
func newStringsDiff() *StringsDiff {
return &StringsDiff{
Added: []string{},
Deleted: []string{},
}
}
// Empty indicates whether a change was found in this element
func (stringsDiff *StringsDiff) Empty() bool {
if stringsDiff == nil {
return true
}
return len(stringsDiff.Added) == 0 &&
len(stringsDiff.Deleted) == 0
}
func getStringsDiff(strings1, strings2 []string) *StringsDiff {
diff := getStringsDiffInternal(strings1, strings2)
if diff.Empty() {
return nil
}
return diff
}
func getStringsDiffInternal(strings1, strings2 []string) *StringsDiff {
result := newStringsDiff()
s1 := utils.StringSetFromSlice(strings1)
s2 := utils.StringSetFromSlice(strings2)
result.Added = s2.Minus(s1).ToStringList()
result.Deleted = s1.Minus(s2).ToStringList()
return result
}