Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Fix bug in Bool.js, change default for JSCleaner #566

Merged
merged 2 commits into from Jun 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions batavia/types/Bool.js
Expand Up @@ -83,7 +83,7 @@ Bool.prototype.__ge__ = function(other) {
} else {
this_bool = 0.0
}
return new types.Float(this_bool >= other.valueOf())
return new Bool(this_bool >= other.valueOf())
} else if (types.isinstance(other, types.Int)) {
return this.__int__().__ge__(other)
} else if (types.isinstance(other, Bool)) {
Expand Down Expand Up @@ -115,7 +115,7 @@ Bool.prototype.__gt__ = function(other) {
} else {
this_bool = 0.0
}
return new types.Float(this_bool > other.valueOf())
return new Bool(this_bool > other.valueOf())
} else if (types.isinstance(other, types.Int)) {
return this.__int__().__gt__(other)
} else if (types.isinstance(other, Bool)) {
Expand Down Expand Up @@ -147,7 +147,7 @@ Bool.prototype.__le__ = function(other) {
} else {
this_bool = 0.0
}
return new types.Float(this_bool <= other.valueOf())
return new Bool(this_bool <= other.valueOf())
} else if (types.isinstance(other, types.Int)) {
return this.__int__().__le__(other)
} else if (types.isinstance(other, Bool)) {
Expand Down Expand Up @@ -179,7 +179,7 @@ Bool.prototype.__lt__ = function(other) {
} else {
this_bool = 0.0
}
return new types.Float(this_bool < other.valueOf())
return new Bool(this_bool < other.valueOf())
} else if (types.isinstance(other, types.Int)) {
return this.__int__().__lt__(other)
} else if (types.isinstance(other, Bool)) {
Expand Down
3 changes: 2 additions & 1 deletion batavia/types/Float.js
Expand Up @@ -197,7 +197,8 @@ Float.prototype.__neg__ = function() {
}

Float.prototype.__not__ = function() {
return new Float(!this.valueOf())
var types = require('../types')
return new types.Bool(!this.valueOf())
}

Float.prototype.__invert__ = function() {
Expand Down
1 change: 1 addition & 0 deletions batavia/types/StrUtils.js
Expand Up @@ -316,6 +316,7 @@ function _substitute(format, args) {
case ('bytes'):
case ('bytearray'):
case ('slice'):
case ('bool'):
return bataviaType.__repr__()

case ('type'):
Expand Down
10 changes: 7 additions & 3 deletions tests/test_utils.py
Expand Up @@ -91,8 +91,12 @@ def test_exception_with_other_text(self):
)

def test_bool(self):
self.assertNormalized('true', 'True')
self.assertNormalized('false', 'False')
self.assertNormalized(
'true', 'True', js_cleaner=JSCleaner(js_bool=True)
)
self.assertNormalized(
'true', 'True', js_cleaner=JSCleaner(js_bool=True)
)

def test_float(self):
self.assertNormalized('7.95089e-06', '7.95089e-6')
Expand Down Expand Up @@ -245,7 +249,7 @@ def test_js_code(self):
)

class JSCleanerTests(TranspileTestCase):
cleaner = JSCleaner()
cleaner = JSCleaner(js_bool=True)

def test_cleanse_err_msg(self):
js_in = adjust("""
Expand Down
21 changes: 13 additions & 8 deletions tests/utils.py
Expand Up @@ -5,7 +5,6 @@
import contextlib
from io import StringIO
import importlib
import inspect
import os
import py_compile
import re
Expand Down Expand Up @@ -209,7 +208,7 @@ def wrapper(self, *args, **kwargs):


class JSCleaner:
def __init__(self, err_msg = True, memory_ref = True, js_bool = True, decimal = True, float_exp = True, complex_num = True,
def __init__(self, err_msg = True, memory_ref = True, js_bool = False, decimal = True, float_exp = True, complex_num = True,
high_precision_float = True, test_ref = True, custom = True):

self.transforms = {
Expand Down Expand Up @@ -688,10 +687,10 @@ def runAsJavaScript(


class NotImplementedToExpectedFailure:

def _is_flakey(self):
return self._testMethodName in getattr(self, "is_flakey", [])

def _is_not_implemented(self):
'''
A test is expected to fail if:
Expand Down Expand Up @@ -1354,7 +1353,7 @@ def _module_one_arg_func_test(name, module, f, examples, small_ints=False):
actuals = [x for x in examples if abs(int(x)) < 8192]

def func(self):
self.assertOneArgModuleFuction(
self.assertOneArgModuleFunction(
name=name,
module=module,
func=f,
Expand All @@ -1366,7 +1365,7 @@ def func(self):

def _module_two_arg_func_test(name, module, f, examples, examples2):
def func(self):
self.assertTwoArgModuleFuction(
self.assertTwoArgModuleFunction(
name=name,
module=module,
func=f,
Expand All @@ -1384,7 +1383,9 @@ def func(self):
class ModuleFunctionTestCase(NotImplementedToExpectedFailure):
numerics_only = False

def assertOneArgModuleFuction(self, name, module, func, x_values, substitutions):
def assertOneArgModuleFunction(
self, name, module, func, x_values, substitutions, **kwargs
):
self.assertCodeExecution(
'##################################################\n'.join(
adjust("""
Expand All @@ -1411,9 +1412,12 @@ def assertOneArgModuleFuction(self, name, module, func, x_values, substitutions)
"Error running %s module %s" % (module, name),
substitutions=substitutions,
run_in_function=False,
**kwargs
)

def assertTwoArgModuleFuction(self, name, module, func, x_values, y_values, substitutions):
def assertTwoArgModuleFunction(
self, name, module, func, x_values, y_values, substitutions, **kwargs
):
self.assertCodeExecution(
'##################################################\n'.join(
adjust("""
Expand Down Expand Up @@ -1443,6 +1447,7 @@ def assertTwoArgModuleFuction(self, name, module, func, x_values, y_values, subs
"Error running %s module %s" % (module, name),
substitutions=substitutions,
run_in_function=False,
**kwargs
)

@classmethod
Expand Down