def test_customjstransform_from_coffeescript_with_args(): code = "return foo.get('value') // 2 + x" v_code = "return [foo.get('value') // 2 + x for x in xs]" slider = Slider() formatter = CustomJSTransform.from_coffeescript(func=code, v_func=v_code, args={"foo": slider}) assert formatter.func == dedent("""\ return Math.floor(foo.get('value') / 2) + x; """) assert formatter.v_func == dedent("""\ var x; return [ (function () { var i, len, results; results = []; for (i = 0, len = xs.length; i < len; i++) { x = xs[i]; results.push(Math.floor(foo.get('value') / 2) + x); } return results; })() ]; """) assert formatter.args == {"foo": slider}
def test_customjstransform_from_coffeescript_no_arg(): code = "return x * x" v_code = "return [x * x for x in xs]" transform = CustomJSTransform.from_coffeescript(code, v_code) assert transform.func == dedent("""\ return x * x; """) assert transform.v_func == dedent("""\ var x; return [ (function () { var i, len, results; results = []; for (i = 0, len = xs.length; i < len; i++) { x = xs[i]; results.push(x * x); } return results; })() ]; """) assert transform.args == {}
def test_customjstransform_from_coffeescript_no_arg(): code = "return x * x" v_code = "return [x * x for x in xs]" transform = CustomJSTransform.from_coffeescript(code, v_code) assert transform.func == dedent("""\ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); return x * x; """) assert transform.v_func == dedent("""\ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var x; return [ (function () { var i, len, results; results = []; for (i = 0, len = xs.length; i < len; i++) { x = xs[i]; results.push(x * x); } return results; })() ]; """) assert transform.args == {}