File: jruby_spec.rb

package info (click to toggle)
jruby 1.5.1-1%2Bdeb6u1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze-lts
  • size: 47,024 kB
  • ctags: 74,144
  • sloc: ruby: 398,155; java: 169,506; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (37 lines) | stat: -rw-r--r-- 985 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require File.dirname(__FILE__) + "/../spec_helper"
require 'jruby'

describe "JRuby#compile" do
  it "should produce a CompiledScript instance" do
    compiled = JRuby.compile("foo = 1")
    compiled.should be_kind_of JRuby::CompiledScript
  end
end

describe "JRuby::CompiledScript#inspect_bytecode" do
  it "should produce a String representation of the compiled bytecode" do
    compiled = JRuby.compile("foo = 1")
    bytecode = compiled.inspect_bytecode

    bytecode.should be_kind_of String
  end
end

describe "JRuby.ast_for" do
  it "should produce an AST node" do
    node = JRuby.ast_for("n = 1")
    node[0][0].name.should == "n"
    node[0][0][0].value.should == 1
  end

  it "should produce a node that can be run" do
    JRuby.ast_for("1 + 2 + 3").run.should == 6
  end

  it "can combine nodes together" do
    n1 = JRuby.ast_for("n = 0").first
    n2 = JRuby.ast_for("n += 1").first
    n3 = JRuby.ast_for("n += 2").first
    (n1 + n2 + n3).run.should == 3
  end
end