summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_long.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2016-08-29 18:27:06 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2016-08-29 18:27:06 (GMT)
commit82a95277b8f8cb8245abdd14decff9d44d13d25c (patch)
treed223cd7cd9a745b25d5c364bbe26bec1140f2e0f /Lib/test/test_long.py
parent4e1de16f88cd8b99b2d154e647b63f2f6f8b58ae (diff)
downloadcpython-82a95277b8f8cb8245abdd14decff9d44d13d25c.zip
cpython-82a95277b8f8cb8245abdd14decff9d44d13d25c.tar.gz
cpython-82a95277b8f8cb8245abdd14decff9d44d13d25c.tar.bz2
Issue #27870: A left shift of zero by a large integer no longer attempts to allocate large amounts of memory.
Diffstat (limited to 'Lib/test/test_long.py')
-rw-r--r--Lib/test/test_long.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index f0dd074..4d293f2 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -878,6 +878,21 @@ class LongTest(unittest.TestCase):
self.check_truediv(-x, y)
self.check_truediv(-x, -y)
+ def test_lshift_of_zero(self):
+ self.assertEqual(0 << 0, 0)
+ self.assertEqual(0 << 10, 0)
+ with self.assertRaises(ValueError):
+ 0 << -1
+
+ @support.cpython_only
+ def test_huge_lshift_of_zero(self):
+ # Shouldn't try to allocate memory for a huge shift. See issue #27870.
+ # Other implementations may have a different boundary for overflow,
+ # or not raise at all.
+ self.assertEqual(0 << sys.maxsize, 0)
+ with self.assertRaises(OverflowError):
+ 0 << (sys.maxsize + 1)
+
def test_small_ints(self):
for i in range(-5, 257):
self.assertIs(i, i + 0)