bkld empty maps/lists
This commit is contained in:
@@ -34,7 +34,7 @@ func diffMap(dst map[string]any, src any) (any, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func diffMapMap(dst, src map[string]any) (map[string]any, error) {
|
||||
func diffMapMap(dst, src map[string]any) (any, error) {
|
||||
ret := map[string]any{}
|
||||
|
||||
for k, v := range dst {
|
||||
@@ -63,6 +63,10 @@ func diffMapMap(dst, src map[string]any) (map[string]any, error) {
|
||||
ret[k] = nil
|
||||
}
|
||||
|
||||
if len(ret) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@@ -76,7 +80,7 @@ func diffList(dst []any, src any) (any, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func diffListList(dst, src []any) ([]any, error) { //nolint:unparam
|
||||
func diffListList(dst, src []any) (any, error) { //nolint:unparam
|
||||
ret := []any{}
|
||||
|
||||
outer1:
|
||||
@@ -111,5 +115,9 @@ outer2:
|
||||
}
|
||||
}
|
||||
|
||||
if len(ret) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@ func GetFormat(name string) (*Format, error) {
|
||||
}
|
||||
|
||||
func (f *Format) Marshal(v any) ([]byte, error) {
|
||||
if v == nil {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
ret, err := f.marshal(v)
|
||||
if err != nil {
|
||||
return nil, polyfill.ErrorsJoin(err, ErrMarshal)
|
||||
|
||||
2
tests/diff-list-same/a.yaml
Normal file
2
tests/diff-list-same/a.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
a:
|
||||
- b: 2
|
||||
2
tests/diff-list-same/b.yaml
Normal file
2
tests/diff-list-same/b.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
a:
|
||||
- b: 2
|
||||
1
tests/diff-list-same/cmd
Normal file
1
tests/diff-list-same/cmd
Normal file
@@ -0,0 +1 @@
|
||||
bkld a.yaml b.yaml
|
||||
0
tests/diff-list-same/expected
Normal file
0
tests/diff-list-same/expected
Normal file
2
tests/diff-map-same/a.yaml
Normal file
2
tests/diff-map-same/a.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
a:
|
||||
b: 2
|
||||
2
tests/diff-map-same/b.yaml
Normal file
2
tests/diff-map-same/b.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
a:
|
||||
b: 2
|
||||
1
tests/diff-map-same/cmd
Normal file
1
tests/diff-map-same/cmd
Normal file
@@ -0,0 +1 @@
|
||||
bkld a.yaml b.yaml
|
||||
0
tests/diff-map-same/expected
Normal file
0
tests/diff-map-same/expected
Normal file
Reference in New Issue
Block a user