Skip to content

Compute and pretty-print diffs for data structures like arrays and dictionaries

License

Notifications You must be signed in to change notification settings

ssfrr/DeepDiffs.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DeepDiffs

CI codecov.io

DeepDiffs.jl provides the deepdiff function, which finds and displays differences (diffs) between Julia data structures. It supports Vectors, Dicts, and Strings. When diffing dictionaries where values associated with a particular key may change, deepdiff will recurse into value to provide a more detailed diff.

Many users will likely only use the deepdiff function to interactively visualize diffs. For more advanced usage, the return value from deepdiff will be some subtype of the DeepDiff abstract type which can be further manipulated. These subtypes support the following functions:

  • before(diff): returns the first original (left-hand-side) value that was diffed
  • after(diff): returns the modified (right-hand-side) value that was diffed
  • added(diff): returns a list of indices or dictionary keys that were new items. These indices correspond to the "after" value.
  • removed(diff): returns a list of indices or dictionary keys that were removed. These indices correspond to the "before" value.
  • changed(diff): returns a dictionary whose keys are indices or dictionary keys and whose values are themselves DeepDiffs that describe the modified value. Currently this is only meaningful when diffing dictionaries because the keys can be matched up between the original and modified values.

Diffing Vectors

Vectors are diffed using a longest-subsequence algorithm that tries to minmize the number of additions and removals necessary to transform one Vector to another.

Dict diff output

Diffing Dicts

Dicts are diffed by matching up the keys between the original and modified values, so it can recognize removed, added, or modified values.

Dict diff output

If color is disabled then the additions and removals are displayed a little differently:

Dict diff output

Diffing Strings

Single-line strings

Single-line strings are diffed character-by-character. The indices returned by added and removed correspond to indices in the Vector of characters returned by collect(str::String).

Dict diff output

Multi-line strings

Multi-line strings (strings with at least one newline) are diffed line-by-line. The indices returned by added and removed correspond to line numbers.

Dict diff output

About

Compute and pretty-print diffs for data structures like arrays and dictionaries

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages