[Python-checkins] CVS: python/dist/src/Lib/test test_struct.py,1.13,1.14

Tim Peters tim_one@users.sourceforge.net
Fri, 14 Sep 2001 19:35:17 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv24968/python/Lib/test

Modified Files:
	test_struct.py 
Log Message:
The 'p' (Pascal string) pack code acts unreasonably when the string size
and count exceed 255.  Changed to preserve as much of the string as
possible (instead of count%256 characters).


Index: test_struct.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_struct.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** test_struct.py	2001/06/18 22:27:39	1.13
--- test_struct.py	2001/09/15 02:35:15	1.14
***************
*** 369,370 ****
--- 369,395 ----
      t = IntTester(*args)
      t.run()
+ 
+ 
+ ###########################################################################
+ # The p ("Pascal string") code.
+ 
+ def test_p_code():
+     for code, input, expected, expectedback in [
+             ('p','abc', '\x00', ''),
+             ('1p', 'abc', '\x00', ''),
+             ('2p', 'abc', '\x01a', 'a'),
+             ('3p', 'abc', '\x02ab', 'ab'),
+             ('4p', 'abc', '\x03abc', 'abc'),
+             ('5p', 'abc', '\x03abc\x00', 'abc'),
+             ('6p', 'abc', '\x03abc\x00\x00', 'abc'),
+             ('1000p', 'x'*1000, '\xff' + 'x'*999, 'x'*255)]:
+         got = struct.pack(code, input)
+         if got != expected:
+             raise TestFailed("pack(%r, %r) == %r but expected %r" %
+                              (code, input, got, expected))
+         (got,) = struct.unpack(code, got)
+         if got != expectedback:
+             raise TestFailed("unpack(%r, %r) == %r but expected %r" %
+                              (code, input, got, expectedback))
+ 
+ test_p_code()