Skip to content

Commit

Permalink
fix(int): Can diff ints, needed for csv body files
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Nov 1, 2019
1 parent 0533c9c commit d2c2210
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
36 changes: 36 additions & 0 deletions deepdiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,42 @@ func dotGraphTree(d *diff) *bytes.Buffer {
return buf
}

func TestDiffIntData(t *testing.T) {
leftData := []interface{}{
[]interface{}{ int64(1), int64(2), int64(3)},
[]interface{}{ int64(4), int64(5), int64(6)},
[]interface{}{ int64(7), int64(8), int64(9)},
}
rightData := []interface{}{
[]interface{}{ int64(1), int64(2), int64(3)},
[]interface{}{ int64(4), int64(0), int64(6)},
[]interface{}{int64(10), int64(8), int64(9)},
}

diff, err := Diff(leftData, rightData)
if err != nil {
t.Fatalf("Diff error: %s", err)
}

expect := []*Delta{
&Delta{
Type: DTUpdate,
Path: "/1/1",
Value: int64(0),
SourceValue: int64(5),
},
&Delta{
Type: DTUpdate,
Path: "/2/0",
Value: int64(10),
SourceValue: int64(7),
},
}
if err := CompareDiffs(expect, diff); err != nil {
t.Errorf("Compare result mismatch: %s", err)
}
}

func BenchmarkDiff1(b *testing.B) {
srcData := `{
"foo" : {
Expand Down
4 changes: 4 additions & 0 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ func formatStats(ds *Stats, color bool) string {
neutralColor, insertColor, deleteColor, updateColor, closeColor string
)

if ds == nil {
return "<nil>"
}

if color {
neutralColor = "\x1b[37m"
insertColor = "\x1b[32m"
Expand Down
8 changes: 8 additions & 0 deletions format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ func TestFormatStatsPretty(t *testing.T) {
}
}
}

func TestFormatStatsNull(t *testing.T) {
got := FormatPrettyStats(nil)
expect := `<nil>`
if got != expect {
t.Errorf("want:\n%s\ngot:\n%s", expect, got)
}
}
10 changes: 10 additions & 0 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ func tree(v interface{}, name string, parent node, nodes chan node) (n node) {
value: v,
weight: 1,
}
case int64:
istr := strconv.FormatInt(x, 10)
n = &scalar{
t: ntInt,
name: name,
hash: NewHash().Sum([]byte(istr)),
parent: parent,
value: v,
weight: len(istr),
}
case float64:
fstr := strconv.FormatFloat(x, 'f', -1, 64)
n = &scalar{
Expand Down

0 comments on commit d2c2210

Please sign in to comment.