Ejemplo n.º 1
0
 def test_call_args(self):
     space = ObjSpace()
     interp = MockInterpreter(space)
     sin = interp.locate_function("sin")
     w_res = space.call_args(sin, [space.wrap(1.2)])
     assert space.float_w(w_res) == math.sin(1.2)
     max = interp.locate_function("max")
     w_res = space.call_args(max, [space.wrap(2), space.wrap(15),
                                   space.wrap(3)])
     assert space.int_w(w_res) == 15
     w_res = space.call_args(max, [W_Reference(space.wrap(2)),
                                   space.wrap(15),
                                   space.wrap(3)])
     assert space.int_w(w_res) == 15
     str_repeat = interp.locate_function("str_repeat")
     w_res = space.call_args(str_repeat, [space.newstr("a"), space.wrap(3)])
     assert space.str_w(w_res) == "aaa"
     source = """<?php
     function f($a, $b) {
         return $a + 10 * $b;
     }
     """
     bc = compile_php('<input>', source, space, interp)
     interp.run_main(space, bc)
     f = interp.locate_function("f")
     w_res = space.call_args(f, [space.wrap(1), space.wrap(2)])
     assert space.int_w(w_res) == 21
Ejemplo n.º 2
0
 def test_call_args(self):
     space = ObjSpace()
     interp = MockInterpreter(space)
     sin = interp.locate_function("sin")
     w_res = space.call_args(sin, [space.wrap(1.2)])
     assert space.float_w(w_res) == math.sin(1.2)
     max = interp.locate_function("max")
     w_res = space.call_args(
         max, [space.wrap(2), space.wrap(15),
               space.wrap(3)])
     assert space.int_w(w_res) == 15
     w_res = space.call_args(
         max, [W_Reference(space.wrap(2)),
               space.wrap(15),
               space.wrap(3)])
     assert space.int_w(w_res) == 15
     str_repeat = interp.locate_function("str_repeat")
     w_res = space.call_args(str_repeat, [space.newstr("a"), space.wrap(3)])
     assert space.str_w(w_res) == "aaa"
     source = """<?php
     function f($a, $b) {
         return $a + 10 * $b;
     }
     """
     bc = compile_php('<input>', source, space, interp)
     interp.run_main(space, bc)
     f = interp.locate_function("f")
     w_res = space.call_args(f, [space.wrap(1), space.wrap(2)])
     assert space.int_w(w_res) == 21
Ejemplo n.º 3
0
def test_parse_array_output():
    space = ObjSpace()
    output = run_source(space, '''
    $a = array(1, 2, 3);
    echo $a;
    $a = array("c" => 2);
    echo $a;
    ''')
    assert len(output) == 2
    assert space.arraylen(output[0]) == 3
    assert space.arraylen(output[1]) == 1
    assert space.int_w(space.getitem(output[0], space.wrap(2))) == 3
    assert space.int_w(space.getitem(output[1], space.newstr('c'))) == 2
Ejemplo n.º 4
0
def test_parse_array_output():
    space = ObjSpace()
    output = run_source(space, '''
    $a = array(1, 2, 3);
    echo $a;
    $a = array("c" => 2);
    echo $a;
    ''')
    assert len(output) == 2
    assert space.arraylen(output[0]) == 3
    assert space.arraylen(output[1]) == 1
    assert space.int_w(space.getitem(output[0], space.wrap(2))) == 3
    assert space.int_w(space.getitem(output[1], space.newstr('c'))) == 2