Exemplo n.º 1
0
def test_transform_raise_without_exception_value():
    _assert_transform(
        cc.try_(
            [cc.ret(cc.ref("x"))],
            handlers=[
                cc.except_(cc.ref("AssertionError"), cc.ref("error"), [cc.raise_()]),
            ],
        ),
        """
            try {
                return x;
            } catch ($exception0) {
                if ($exception0.$nopeException === $nope.undefined) {
                    throw $exception0;
                } else {
                    if ($nope.builtins.isinstance($exception0.$nopeException, AssertionError)) {
                        var error = $exception0.$nopeException;
                        throw $exception0;
                    } else {
                        throw $exception0;
                    }
                }
            }
        """,
    )
Exemplo n.º 2
0
def test_transform_raise_with_exception_value():
    _assert_transform(
        cc.raise_(cc.ref("error")),
        """
            var $exception0 = error;
            var $error1 = new $nope.Error();
            $error1.$nopeException = $exception0;
            $error1.toString = function() {
                return ($nope.builtins.getattr($nope.builtins.type($exception0), "__name__") + ": ") + $nope.builtins.str($exception0);
            };
            throw $error1;
        """,
    )
Exemplo n.º 3
0
    def raise_generates_throw_with_nope_exception_contained_in_csharp_exception(self):
        node = cc.raise_(cc.ref("x"))
        
        expected = """throw __Nope.Internals.@CreateException(x);
"""
        assert_equal(expected, cs.dumps(transform(node)))
Exemplo n.º 4
0
 def test_transform_raise_statement_transforms_value(self):
     _assert_transform(
         nodes.raise_(nodes.ref("value")),
         cc.raise_(cc.ref("value"))
     )