tests/test-lrucachedict.py
changeset 27576 6cd3044985c2
parent 27371 45d996a566d7
child 28930 e3f01188d439
--- a/tests/test-lrucachedict.py	Thu Dec 31 09:55:56 2015 +0100
+++ b/tests/test-lrucachedict.py	Wed Dec 30 13:10:53 2015 -0800
@@ -1,11 +1,11 @@
 from mercurial import util
 
-def printifpresent(d, xs):
+def printifpresent(d, xs, name='d'):
     for x in xs:
         present = x in d
-        print "'%s' in d: %s" % (x, present)
+        print "'%s' in %s: %s" % (x, name, present)
         if present:
-            print "d['%s']: %s" % (x, d[x])
+            print "%s['%s']: %s" % (name, x, d[x])
 
 def test_lrucachedict():
     d = util.lrucachedict(4)
@@ -42,5 +42,29 @@
     d['b']
     printifpresent(d, ['a', 'b'])
 
+    # test copy method
+    d = util.lrucachedict(4)
+    d['a'] = 'va3'
+    d['b'] = 'vb3'
+    d['c'] = 'vc3'
+    d['d'] = 'vd3'
+
+    dc = d.copy()
+
+    # all of these should be present
+    print "\nAll of these should be present:"
+    printifpresent(dc, ['a', 'b', 'c', 'd'], 'dc')
+
+    # 'a' should be dropped because it was least recently used
+    print "\nAll of these except 'a' should be present:"
+    dc['e'] = 've3'
+    printifpresent(dc, ['a', 'b', 'c', 'd', 'e'], 'dc')
+
+    # contents and order of original dict should remain unchanged
+    print "\nThese should be in reverse alphabetical order and read 'v?3':"
+    dc['b'] = 'vb3_new'
+    for k in list(iter(d)):
+        print "d['%s']: %s" % (k, d[k])
+
 if __name__ == '__main__':
     test_lrucachedict()