Ejemplo n.º 1
0
  /** Test of exec method, of class JRubyEngine. */
  @Test
  public void testExec() throws Exception {
    System.out.println("exec");
    BSFManager manager = new BSFManager();
    JRubyEngine instance = new JRubyEngine();
    instance.initialize(manager, "jruby", null);
    String file = "";
    int line = 0;
    int col = 0;
    Object expr = null;
    instance.exec(file, line, col, expr);

    String partone =
        "def partone\n"
            + "impression = \"Sooooo Gooood!\"\n"
            + "f = File.new(\""
            + basedir
            + "/build/test-results/bsfeval.txt\", \"w\")\n"
            + "begin\n"
            + "f.puts impression\n"
            + "ensure\n"
            + "f.close\n"
            + "end\n"
            + "end\n"
            + "partone";
    String parttwo =
        "def parttwo\n"
            + "f = File.open \""
            + basedir
            + "/build/test-results/bsfeval.txt\"\n"
            + "begin\n"
            + "comment = f.gets\n"
            + "return comment\n"
            + "ensure\n"
            + "f.close\n"
            + "end\n"
            + "end\n"
            + "parttwo";
    instance.exec("<script>", 0, 0, partone);

    Object expResult = "Sooooo Gooood!\n";
    Object result = instance.eval("<script>", 0, 0, parttwo);
    assertEquals(expResult, result);
  }