Exemplo n.º 1
0
 def test_strange_chars(self):
     jsi = JSInterpreter(
         'function $_xY1 ($_axY1) { var $_axY2 = $_axY1 + 1; return $_axY2; }'
     )
     self.assertEqual(jsi.call_function('$_xY1', 20), 21)
Exemplo n.º 2
0
 def test_array_access(self):
     jsi = JSInterpreter(
         'function f(){var x = [1,2,3]; x[0] = 4; x[0] = 5; x[2] = 7; return x;}'
     )
     self.assertEqual(jsi.call_function('f'), [5, 2, 7])
Exemplo n.º 3
0
 def test_empty_return(self):
     jsi = JSInterpreter('function f(){return; y()}')
     self.assertEqual(jsi.call_function('f'), None)
Exemplo n.º 4
0
    def test_morespace(self):
        jsi = JSInterpreter('function x (a) { return 2 * a + 1 ; }')
        self.assertEqual(jsi.call_function('x', 3), 7)

        jsi = JSInterpreter('function f () { x =  2  ; return x; }')
        self.assertEqual(jsi.call_function('f'), 2)
Exemplo n.º 5
0
 def test_calc(self):
     jsi = JSInterpreter('function x4(a){return 2*a+1;}')
     self.assertEqual(jsi.call_function('x4', 3), 7)
Exemplo n.º 6
0
 def test_comma(self):
     jsi = JSInterpreter('''
     function x() { a=5; a -= 1, a+=3; return a }
     ''')
     self.assertEqual(jsi.call_function('x'), 7)
Exemplo n.º 7
0
 def test_literal_list(self):
     jsi = JSInterpreter('''
     function x() { [1, 2, "asdf", [5, 6, 7]][3] }
     ''')
     self.assertEqual(jsi.call_function('x'), [5, 6, 7])
Exemplo n.º 8
0
 def test_for_loop_break(self):
     jsi = JSInterpreter('''
     function x() { a=0; for (i=0; i-10; i++) { break; a++ } a }
     ''')
     self.assertEqual(jsi.call_function('x'), 0)
Exemplo n.º 9
0
 def test_try(self):
     jsi = JSInterpreter('''
     function x() { try{return 10} catch(e){return 5} }
     ''')
     self.assertEqual(jsi.call_function('x'), 10)