def test_foo3(self): interp = Interpreter() res = interp.run_src('var a = 40;') res = interp.run_src('var b = 2;') res = interp.run_src('a + b;') assert res == _w(42)
def run(files, opts): from js.interpreter import Interpreter, load_file interactive = len(files) == 0 inspect = opts.get('inspect', False) interp = Interpreter(opts) for filename in files: src = load_file(filename) try: interp.run_src(src) except ParseError as exc: printsyntaxerror(unicode(filename), exc, src) raise SystemExit except LexerError as e: printlexererror(unicode(filename), e, src) raise SystemExit except JsException as e: printerrormessage(unicode(filename), e._msg()) raise SystemExit if inspect or interactive: repl(interp)
def run(files, opts): from js.interpreter import Interpreter, load_file interactive = len(files) == 0 inspect = opts.get('inspect', False) interp = Interpreter(opts) for filename in files: src = load_file(filename) try: interp.run_src(src) except ParseError as exc: printsyntaxerror(unicode(filename), exc, src) raise SystemExit except LexerError as e: printlexererror(unicode(filename), e, src) raise SystemExit except JsException as e: printerrormessage(unicode(filename), e._msg()) raise SystemExit if inspect or interactive: repl(interp)
def f(testfile): interp = Interpreter({'no-exception-jseval': True}) shell_src = load_file(str(shellpath)) interp.run_src(shell_src) test_src = load_file(testfile) interp.run_src(test_src) global_object = interp.global_object testcases = global_object.get(u'testcases') testcount = testcases.get(u'length').ToInt32() run_test_func = global_object.get(u'run_test') test_results = [] for number in xrange(testcount): w_test_number = _w(number) result_obj = run_test_func.Call(args=[w_test_number]) result_passed = result_obj.get(u'passed').to_boolean() result_reason = str(result_obj.get(u'reason').to_string()) test_results.append({'number': number, 'passed': result_passed, 'reason': result_reason}) return test_results
def assertp(code, prints, captured): out, err = captured.readouterr() from js.interpreter import Interpreter jsint = Interpreter() jsint.run_src(code) out, err = captured.readouterr() assert out.strip() == prints.strip()
def assertv(code, value): from js.interpreter import Interpreter from js.object_space import _w jsint = Interpreter() ret_val = jsint.run_src(code) assert ret_val == _w(value)
def test_foo2(self): src = ''' var a = 40; var b = 2; return a + b; ''' interp = Interpreter() res = interp.run_src(src) assert res == _w(42)
def test_foo4(self): interp = Interpreter() res = interp.run_src('40 + 2;') assert res == _w(42)