예제 #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
예제 #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
예제 #3
0
def _as_list(w_arr):
    space = ObjSpace()
    iter = space.create_iter(w_arr)
    result = []
    while not iter.done():
        _, w_val = iter.next_item(space)
        result.append(space.str_w(w_val))
    return result
예제 #4
0
def test_parse_str():
    space = ObjSpace()
    output = run_source(space, '''
    echo "dupa";
    ''')
    assert space.str_w(output[0]) == 'dupa'
예제 #5
0
def test_parse_str():
    space = ObjSpace()
    output = run_source(space, '''
    echo "dupa";
    ''')
    assert space.str_w(output[0]) == 'dupa'