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
|
# this is used for generating the repo front page
def do(cmd, comment=None):
if comment:
print("# " + comment)
print(">>> " + cmd)
c = compile(cmd, filename="<string>", mode='single')
eval(c, globals())
print()
do('from jsondiff import diff')
do("diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4})")
do("diff(['a', 'b', 'c'], ['a', 'b', 'c', 'd'])")
do("diff(['a', 'b', 'c'], ['a', 'c'])")
do("diff({'a': [0, {'b': 4}, 1]}, {'a': [0, {'b': 5}, 1]})", "Typical diff looks like what you'd expect...")
do("diff({'a': [0, {'b': 4}, 1]}, {'a': [0, {'c': 5}, 1]})", "...but similarity is taken into account")
do("diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4}, syntax='explicit')", "Support for various diff syntaxes")
do("diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4}, syntax='symmetric')")
do("diff({'a', 'b', 'c'}, {'a', 'c', 'd'})", "Special handling of sets")
do("print(diff('[\"a\", \"b\", \"c\"]', '[\"a\", \"c\", \"d\"]', load=True, dump=True))", "Load and dump JSON")
|