Skip to content

Commit

Permalink
Merge pull request beeware#526 from shortdiv/testing-branch
Browse files Browse the repository at this point in the history
fix: Added fix for lshift and rshift
  • Loading branch information
glasnt committed May 24, 2017
2 parents d957318 + a271740 commit 2f22821
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 12 additions & 0 deletions batavia/types/Bool.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ Bool.prototype.__lshift__ = function(other) {
return new types.Int(0)
}
} else if (types.isinstance(other, types.Int)) {
if (other.valueOf() < 0) {
throw new exceptions.ValueError.$pyclass('negative shift count')
}
if (Number.MAX_SAFE_INTEGER < other.valueOf()) {
throw new exceptions.OverflowError.$pyclass('Python int too large to convert to C ssize_t')
}
if (this.valueOf()) {
this_bool = 1
} else {
Expand All @@ -540,6 +546,12 @@ Bool.prototype.__rshift__ = function(other) {
return new types.Int(0)
}
} else if (types.isinstance(other, types.Int)) {
if (other.valueOf() < 0) {
throw new exceptions.ValueError.$pyclass('negative shift count')
}
if (Number.MAX_SAFE_INTEGER < Math.abs(other.valueOf())) {
throw new exceptions.OverflowError.$pyclass('Python int too large to convert to C ssize_t')
}
if (this.valueOf()) {
this_bool = 1
} else {
Expand Down
11 changes: 1 addition & 10 deletions tests/datatypes/test_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,13 @@ class BinaryBoolOperationTests(BinaryOperationTestCase, TranspileTestCase):
data_type = 'bool'

not_implemented = [
'test_lshift_int',

'test_rshift_int',

'test_true_divide_complex',
'test_true_divide_complex'
]


class InplaceBoolOperationTests(InplaceOperationTestCase, TranspileTestCase):
data_type = 'bool'

not_implemented = [

'test_lshift_int',

'test_rshift_int',

'test_true_divide_complex',
]
3 changes: 0 additions & 3 deletions tests/datatypes/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ class InplaceIntOperationTests(InplaceOperationTestCase, TranspileTestCase):
'test_power_complex',
'test_power_float',

'test_rshift_int', # this works, but some of the cases are too large
# until we replace bignumber.js

'test_subtract_complex',

'test_true_divide_complex',
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ def assertInplaceOperation(self, x_values, y_values, operation, format, substitu
'test_lshift_%s' % datatype, 'x <<= y', examples, small_ints=True
)
vars()['test_rshift_%s' % datatype] = _inplace_test(
'test_rshift_%s' % datatype, 'x >>= y', examples
'test_rshift_%s' % datatype, 'x >>= y', examples, small_ints=True
)
vars()['test_and_%s' % datatype] = _inplace_test(
'test_and_%s' % datatype, 'x &= y', examples
Expand Down

0 comments on commit 2f22821

Please sign in to comment.