示例#1
0
 def test_transform_boolean_or(self):
     _assert_transform(
         nodes.bool_or(nodes.ref("x"), nodes.ref("y")),
         cc.ternary_conditional(
             cc.call(cc.builtin("bool"), [cc.ref("x")]),
             cc.ref("x"),
             cc.ref("y")
         ),
     )
示例#2
0
 def test_transform_while_loop(self):
     _assert_transform(
         nodes.while_(
             nodes.ref("x"),
             [nodes.ret(nodes.ref("y"))],
         ),
         cc.while_(
             cc.call(cc.builtin("bool"), [cc.ref("x")]),
             [cc.ret(cc.ref("y"))],
         )
     )
示例#3
0
 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"))],
         )
     )
示例#4
0
 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),
         ]),
     )
示例#5
0
def test_transform_builtin_reference():
    _assert_transform(
        cc.builtin("x"),
        js.ref("$nope.builtins.x")
    )
示例#6
0
 def test_transform(self):
     _assert_transform(
         nodes.slice(nodes.ref("x"), nodes.ref("y"), nodes.none()),
         cc.call(cc.builtin("slice"), [cc.ref("x"), cc.ref("y"), cc.none]),
     )
示例#7
0
 def test_transform_boolean_not(self):
     _assert_transform(
         nodes.bool_not(nodes.ref("x")),
         cc.not_(cc.call(cc.builtin("bool"), [cc.ref("x")])),
     )