Better test coverage of operators (in 2.7 and 3.0)

This commit is contained in:
rocky
2019-11-18 18:10:58 -05:00
parent e713169bdf
commit ca7f483dbb
7 changed files with 56 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,4 @@
# Tests BINARY_TRUE_DIVIDE and INPLACE_TRUE_DIVIDE
from __future__ import division # needed on 2.6 and 2.7
from __future__ import division # needed on 2.2 .. 2.7
x = len(__file__) / 1
x /= 1

View File

@@ -0,0 +1,53 @@
# Covers a large number of operators
#
# This code is RUNNABLE!
from __future__ import division # needed on 2.2 .. 2.7
import sys
PYTHON_VERSION = sys.version_info[0] + (sys.version_info[1] / 10.0)
# some floats (from 01_float.py)
x = 1e300
assert 0.0 == x * 0
assert x * 1e300 == float("inf")
assert str(float("inf") * 0.0) == "nan"
assert str(float("-inf") * 0.0) == "nan"
assert -1e300 * 1e300 == float("-inf")
# Complex (adapted from 02_complex.py)
y = 5j
assert y ** 2 == -25
y **= 3
assert y == (-0-125j)
# Tests BINARY_TRUE_DIVIDE and INPLACE_TRUE_DIVIDE (from 02_try_divide.py)
x = 2
assert 4 / x == 2
if PYTHON_VERSION >= 2.2:
x = 5
assert x / 2 == 2.5
x = 3
x /= 2
assert x == 1.5
x = 2
assert 4 // x == 2
x = 7
x //= 2
assert x == 3
x = 3
assert x % 2 == 1
x %= 2
assert x == 1
assert x << 2 == 4
x <<= 3
assert x == 8
assert x >> 1 == 4
x >>= 1
assert x == 4

View File

@@ -62,7 +62,8 @@ class Scanner3(Scanner):
# Create opcode classification sets
# Note: super initilization above initializes self.opc
# Ops that start SETUP_ ... We will COME_FROM with these names
# For ops that start SETUP_ ... we will add COME_FROM with these names
# at the their targets.
# Some blocks and END_ statements. And they can start
# a new statement
if self.version < 3.8: