chiark / gitweb /
@@@ lbuf needs test
[mLib-python] / test.py
diff --git a/test.py b/test.py
index 9cd09e22674626209aef22aa4dcdad33c2cfd000..6e4a761db033adb29ab46f480550bed2f442aa44 100644 (file)
--- a/test.py
+++ b/test.py
@@ -11,6 +11,7 @@ import mLib as M
 if SYS.version_info >= (3,):
   def _bin(text): return text.encode()
   def _text(bin): return bin.decode()
+  xrange = range
 else:
   def _bin(text): return text
   def _text(bin): return bin
@@ -238,7 +239,35 @@ OS.close(fd)
 must_equal(data, _bin("Hello, world!"))
 
 ## mdup
-## print(";; test mdup...")
+print(";; test mdup...")
+def mkfd():
+  fd = OS.open(",delete-me", OS.O_WRONLY | OS.O_CREAT, 0o666)
+  OS.unlink(",delete-me")
+  return fd
+def fid(fd):
+  st = OS.fstat(fd)
+  return st.st_dev, st.st_ino
+initial = [mkfd() for i in xrange(5)]
+ref = [fid(fd) for fd in initial]
+op = [(initial[0], initial[1]),
+      (initial[1], initial[2]),
+      (initial[2], initial[0]),
+      (initial[0], initial[3]),
+      (initial[3], -1),
+      (initial[0], initial[4])]
+M.mdup(op)
+for have, want in op:
+  if want != -1: must_equal(have, want)
+must_equal(op[0][0], initial[1]); must_equal(fid(op[0][0]), ref[0])
+must_equal(op[1][0], initial[2]); must_equal(fid(op[1][0]), ref[1])
+must_equal(op[2][0], initial[0]); must_equal(fid(op[2][0]), ref[2])
+must_equal(op[3][0], initial[3]); must_equal(fid(op[3][0]), ref[0])
+pass;                             must_equal(fid(op[4][0]), ref[3])
+must_equal(op[5][0], initial[4]); must_equal(fid(op[5][0]), ref[0])
+for fd, _ in op: OS.close(fd)
+
+## (not testing detachtty and daemonize)
+
 
 
 ## Done!