def test_transform_if_else(): _assert_transform( cc.if_( cc.ref("x"), [cc.ret(cc.ref("y"))], [cc.ret(cc.ref("z"))], ), js.if_( js.ref("x"), [js.ret(js.ref("y"))], [js.ret(js.ref("z"))], ) )
def test_condition_is_transformed_using_bool_builtin(self): _assert_transform( nodes.if_( nodes.ref("x"), [nodes.ret(nodes.ref("y"))], [nodes.ret(nodes.ref("z"))], ), cc.if_( cc.call(cc.builtin("bool"), [cc.ref("x")]), [cc.ret(cc.ref("y"))], [cc.ret(cc.ref("z"))], ) )
def test_condition_is_not_transformed_using_bool_builtin_if_already_a_bool(self): condition_node = nodes.ref("x") _assert_transform( nodes.if_( condition_node, [nodes.ret(nodes.ref("y"))], [nodes.ret(nodes.ref("z"))], ), cc.if_( cc.ref("x"), [cc.ret(cc.ref("y"))], [cc.ret(cc.ref("z"))], ), type_lookup=[ (condition_node, types.bool_type), ], )
def test_function_without_explicit_return_on_all_paths_returns_none_at_end(self): _assert_transform( nodes.func( name="f", args=nodes.args([]), body=[ nodes.if_( nodes.ref("x"), [nodes.ret(nodes.bool_literal(True))], [] ), ], type=None ), cc.func("f", [], [ cc.if_( cc.call(cc.builtin("bool"), [cc.ref("x")]), [cc.ret(cc.true)], ), cc.ret(cc.none), ]), )