[PATCH 5 of 9] dicthelpers: add unit tests
Siddharth Agarwal
sid0 at fb.com
Sun Mar 24 19:27:49 CDT 2013
# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1364170255 25200
# Sun Mar 24 17:10:55 2013 -0700
# Node ID 7bc5b8e56c65d7ad228fe700974a9621bdfd42c4
# Parent 78f178247f634bac6ff2ffe54b0d06185ef0e670
dicthelpers: add unit tests
diff --git a/tests/test-dicthelpers.py b/tests/test-dicthelpers.py
new file mode 100644
--- /dev/null
+++ b/tests/test-dicthelpers.py
@@ -0,0 +1,34 @@
+from mercurial.dicthelpers import diff, join
+
+def test_dicthelpers():
+ # empty dicts
+ print "diff({}, {}):", sorted(diff({}, {}).items())
+ print "join({}, {}):", sorted(join({}, {}).items())
+
+ d1 = {}
+ d1['a'] = 'foo'
+ d1['b'] = 'bar'
+ d1['c'] = 'baz'
+
+ # same identity
+ print "diff(d1, d1):", sorted(diff(d1, d1).items())
+ print "join(d1, d1):", sorted(join(d1, d1).items())
+
+ # vs empty
+ print "diff(d1, {}):", sorted(diff(d1, {}).items())
+ print "join(d1, {}):", sorted(join(d1, {}).items())
+
+ d2 = {}
+ d2['a'] = 'foo2'
+ d2['b'] = 'bar'
+ d2['d'] = 'quux'
+
+ print "diff(d1, d2):", sorted(diff(d1, d2).items())
+ print "join(d1, d2):", sorted(join(d1, d2).items())
+
+ # with default argument
+ print "diff(d1, d2, 123):", sorted(diff(d1, d2, 123).items())
+ print "join(d1, d2, 456):", sorted(join(d1, d2, 456).items())
+
+if __name__ == '__main__':
+ test_dicthelpers()
diff --git a/tests/test-dicthelpers.py.out b/tests/test-dicthelpers.py.out
new file mode 100644
--- /dev/null
+++ b/tests/test-dicthelpers.py.out
@@ -0,0 +1,10 @@
+diff({}, {}): []
+join({}, {}): []
+diff(d1, d1): []
+join(d1, d1): [('a', ('foo', 'foo')), ('b', ('bar', 'bar')), ('c', ('baz', 'baz'))]
+diff(d1, {}): [('a', ('foo', None)), ('b', ('bar', None)), ('c', ('baz', None))]
+join(d1, {}): [('a', ('foo', None)), ('b', ('bar', None)), ('c', ('baz', None))]
+diff(d1, d2): [('a', ('foo', 'foo2')), ('c', ('baz', None)), ('d', (None, 'quux'))]
+join(d1, d2): [('a', ('foo', 'foo2')), ('b', ('bar', 'bar')), ('c', ('baz', None)), ('d', (None, 'quux'))]
+diff(d1, d2, 123): [('a', ('foo', 'foo2')), ('c', ('baz', 123)), ('d', (123, 'quux'))]
+join(d1, d2, 456): [('a', ('foo', 'foo2')), ('b', ('bar', 'bar')), ('c', ('baz', 456)), ('d', (456, 'quux'))]
More information about the Mercurial-devel
mailing list