From 5a5e2e11718380b70ec5c9ef5c15e8ea2773ceba Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 17 Nov 2019 23:44:57 +0000 Subject: [PATCH] t/t-bytes.py: Check that indexing, slicing, etc. return `C.ByteString'. --- t/t-algorithms.py | 2 +- t/t-bytes.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/t/t-algorithms.py b/t/t-algorithms.py index 2fd0e09..d7b97cb 100644 --- a/t/t-algorithms.py +++ b/t/t-algorithms.py @@ -788,7 +788,7 @@ class TestKeccak (HashBufferTestMixin): ## Check masking. x = xcls().hash(m).xof() - me.assertEqual(x.mask(m), C.ByteString(m) ^ C.ByteString(h[0:len(m)])) + me.assertEqual(x.mask(m), m ^ h[0:len(m)]) ## Check the `check' method. me.assertTrue(xcls().hash(m).check(h0)) diff --git a/t/t-bytes.py b/t/t-bytes.py index 6755e96..36a3f9f 100644 --- a/t/t-bytes.py +++ b/t/t-bytes.py @@ -48,6 +48,7 @@ class TestByteString (U.TestCase): x = C.ByteString(T.bin("once upon a time there was a string")) ## Check that simple indexing works. + me.assertEqual(type(x[3]), C.ByteString) me.assertEqual(x[3], 'e') me.assertEqual(x[-5], 't') @@ -55,7 +56,8 @@ class TestByteString (U.TestCase): x[34]; me.assertRaises(IndexError, lambda: x[35]) x[-35]; me.assertRaises(IndexError, lambda: x[-36]) - ## Check slicing. + ## Check slicing. This should always give us bytes. + me.assertEqual(type(x[7:17]), C.ByteString) me.assertEqual(x[7:17], T.bin("on a time ")) ## Complex slicing is also supported. @@ -143,13 +145,18 @@ class TestByteString (U.TestCase): me.assertEqual(~x, C.bytes("fc5a03")) ## Concatenation. + me.assertEqual(type(x + y), C.ByteString) me.assertEqual(x + y, C.bytes("03a5fc5fac30")) ## Replication (asymmetric but commutative). + me.assertEqual(type(3*x), C.ByteString) + me.assertEqual(type(x*3), C.ByteString) me.assertEqual(3*x, C.bytes("03a5fc03a5fc03a5fc")) me.assertEqual(x*3, C.bytes("03a5fc03a5fc03a5fc")) ## Replication by zero (regression test). + me.assertEqual(type(0*x), C.ByteString) + me.assertEqual(type(x*0), C.ByteString) me.assertEqual(0*x, C.ByteString(T.bin(""))) me.assertEqual(x*0, C.ByteString(T.bin(""))) -- 2.11.0