예제 #1
0
파일: Repl.java 프로젝트: afeinberg/dynjs
 public void run() {
   ConsoleReader console = null;
   try {
     console = new ConsoleReader(in, out);
     console.println(WELCOME_MESSAGE);
     String statement = null;
     while ((statement = console.readLine(PROMPT)) != null) {
       if ("exit".equals(statement.trim())) {
         return;
       } else {
         try {
           dynJS.eval(context, statement);
         } catch (DynJSException e) {
           console.println(e.getClass().getSimpleName());
           console.println(e.getLocalizedMessage());
           console.println("Error parsing statement: " + statement.toString());
         } catch (Exception e) {
           e.printStackTrace(new PrintWriter(out));
         }
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
예제 #2
0
 private void check(String scriptlet, Object expected) {
   dynJS.eval(context, scriptlet);
   Object result = context.getScope().resolve("result");
   assertThat(result).isEqualTo(expected);
 }