Test status (tests run / total # of tests):
Output | Expected |
~~~~~~~~~~~~~~~~~~~~ |
|
Test hash |
|
~~~~~~~~~~~~~~~~~~~~ |
|
6 |
|
7 |
|
1 |
|
2 |
|
"hello" |
|
"good" |
|
test native JS hash |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test yield |
|
~~~~~~~~~~~~~~~~~~~~ |
|
three_times_yield |
|
1 |
|
2 |
|
3 |
|
-- |
|
three_times_block |
|
1 |
|
2 |
|
3 |
|
-- |
|
three_times_indirect |
|
1 |
|
2 |
|
3 |
|
1 |
|
2 |
|
3 |
|
-- |
|
three_times_yield2 |
|
1 |
|
3 |
|
4 |
|
loop |
|
2 |
|
4 |
|
6 |
|
8 |
|
10 |
|
["out", 10] |
|
-- |
|
loop2 |
|
2 |
|
4 |
|
6 |
|
8 |
|
10 |
|
["out", 10] |
|
-- |
|
while-loop |
|
2 |
|
4 |
|
6 |
|
8 |
|
10 |
|
---- |
|
10 |
|
9 |
|
8 |
|
7 |
|
6 |
|
5 |
|
4 |
|
3 |
|
2 |
|
1 |
|
-- |
|
"test_proc" |
|
0 |
|
#<LocalJumpError: break from proc-closure> |
|
"before" |
|
"return_in_block before" |
|
4 |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test insertion sort |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Before insertion sort: |
|
[3, 6, 2, 5, 3, 7, 1, 8] |
|
After insertion sort: |
|
[1, 2, 3, 3, 5, 6, 7, 8] |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test lebewesen |
|
~~~~~~~~~~~~~~~~~~~~ |
|
miau, ich bin Leni |
|
wau wau |
|
ich jage Leni |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test expr |
|
~~~~~~~~~~~~~~~~~~~~ |
|
1 |
|
true |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test simple output |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Hello World from RubyJS |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test if |
|
~~~~~~~~~~~~~~~~~~~~ |
|
OK |
|
OK |
|
OK |
|
OK |
|
"a" |
|
"a" |
|
true |
|
"b" |
|
false |
|
nil |
|
"a" |
|
"a" |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test class |
|
~~~~~~~~~~~~~~~~~~~~ |
|
true |
|
false |
|
false |
|
false |
|
false |
|
true |
|
false |
|
true |
|
true |
|
true |
|
true |
|
true |
|
true |
|
true |
|
false |
|
true |
|
true |
|
false |
|
"String" |
|
"NilClass" |
|
true |
|
true |
|
String |
|
T_TestClass::A |
|
T_TestClass::B |
|
T_TestClass::C |
|
T_TestClass::D |
|
T_TestClass::X |
|
"T_TestClass::X" |
|
"T_TestClass::A" |
|
"T_TestClass::B" |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test case |
|
~~~~~~~~~~~~~~~~~~~~ |
|
OKAY |
|
true |
|
true |
|
OK |
|
OKAY |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test splat |
|
~~~~~~~~~~~~~~~~~~~~ |
|
[] |
|
[] |
|
[1] |
|
[1] |
|
[1] |
|
[1, 2] |
|
[1, 2] |
|
[1, 2] |
|
[1, 1, 2] |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test string |
|
~~~~~~~~~~~~~~~~~~~~ |
|
"hello" |
|
"hallo\b\t\n" |
|
"hallo\\leute" |
|
"\"super\"" |
|
1 |
|
3 |
|
nil |
|
2 |
|
8 |
|
"h" |
|
"ha" |
|
"hallo" |
|
"0000000010" |
|
"10" |
|
"()(x" |
|
"1000000000" |
|
"10" |
|
"x()(" |
|
"abc 3 def" |
|
"\"hallo\",4.5" |
|
"harro" |
|
"harro" |
|
"harro" |
|
"hablah blaho" |
|
"ll" |
|
"ll" |
|
"ll" |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test inspect |
|
~~~~~~~~~~~~~~~~~~~~ |
|
[{"Hello"=>"Rubyconf"}] |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test regexp |
|
~~~~~~~~~~~~~~~~~~~~ |
|
"okay" |
|
2 |
|
"ll" |
|
nil |
|
nil |
|
"ll" |
|
"o" |
|
nil |
|
nil |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test args |
|
~~~~~~~~~~~~~~~~~~~~ |
|
0 |
|
1 |
|
"hallo" |
|
[] |
|
-- |
|
1 |
|
2 |
|
"hallo" |
|
[] |
|
-- |
|
1 |
|
2 |
|
9 |
|
[] |
|
-- |
|
1 |
|
2 |
|
9 |
|
[5] |
|
-- |
|
1 |
|
2 |
|
9 |
|
[5, 6] |
|
-- |
|
1 |
|
2 |
|
9 |
|
[5, 6, 7, 8, 9, 10, 11, 12] |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test array |
|
~~~~~~~~~~~~~~~~~~~~ |
|
"b" |
|
["a", "c"] |
|
nil |
|
test native JS array mapping |
|
[1, 2, nil, [nil, nil, 4]] |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test eql |
|
~~~~~~~~~~~~~~~~~~~~ |
|
true |
|
false |
|
false |
|
true |
|
false |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test send |
|
~~~~~~~~~~~~~~~~~~~~ |
|
send |
|
1 |
|
2 |
|
nil |
|
"in B" |
|
1 |
|
2 |
|
nil |
|
respond_to? |
|
true |
|
true |
|
true |
|
false |
|
false |
|
method_missing |
|
false |
|
"mm: blah_blah, 123" |
|
catched!!! |
|
"goood" |
|
class Method |
|
#<Method: String#to_s> |
|
"hallo" |
|
#<Method: Array#+> |
|
[1, 2, 3, 2, 3] |
|
#<Method: Array#+> |
|
[1, 2, 3] |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test range |
|
~~~~~~~~~~~~~~~~~~~~ |
|
0 |
|
2 |
|
0..2 |
|
"1..6" |
|
"1...2" |
|
"0..2" |
|
"0...2" |
|
0 |
|
1 |
|
2 |
|
3 |
|
4 |
|
0 |
|
1 |
|
2 |
|
3 |
|
true |
|
false |
|
false |
|
false |
|
true |
|
true |
|
false |
|
[] |
|
[-5, -4, -3, -2, -1] |
|
0 |
|
0 |
|
4 |
|
4 |
|
false |
|
1 |
|
1 |
|
5 |
|
5 |
|
true |
|
true |
|
false |
|
false |
|
true |
|
true |
|
true |
|
false |
|
55 |
|
100 |
|
54 |
|
100 |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test massign |
|
~~~~~~~~~~~~~~~~~~~~ |
|
1 |
|
2 |
|
-- |
|
1 |
|
2 |
|
-- |
|
1 |
|
2 |
|
nil |
|
-- |
|
1 |
|
2 |
|
3 |
|
-- |
|
swap |
|
1 |
|
2 |
|
2 |
|
1 |
|
-- |
|
splat1 |
|
1 |
|
2 |
|
nil |
|
[] |
|
-- |
|
splat2 |
|
1 |
|
[2] |
|
-- |
|
splat3 |
|
1 |
|
[2, 3, 4, 5] |
|
-- |
|
splat with globals |
|
nil |
|
nil |
|
1 |
|
2 |
|
-- |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test hot ruby |
|
~~~~~~~~~~~~~~~~~~~~ |
|
InsertionSort |
|
Before insertion sort: |
|
[3, 6, 2, 5, 3, 7, 1, 8] |
|
After insertion sort: |
|
[1, 2, 3, 3, 5, 6, 7, 8] |
|
Array args |
|
Hello World ! |
|
Block |
|
Action is eloquence - William Shakespeare |
|
Class |
|
PI is about |
|
3.14159292035 |
|
Const |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test new |
|
~~~~~~~~~~~~~~~~~~~~ |
|
test |
|
~~~~~~~~~~~~~~~~~~~~ |
|
Test exception |
|
~~~~~~~~~~~~~~~~~~~~ |
|
"before block" |
|
"in block" |
|
"after block" |
|
"block" |
|
"else" |
|
#<RuntimeError: test> |
|
before begin |
|
before raise |
|
#<Exception: blah> |
|
yes |
|
ensure |
|
after begin |
|
-- |
|
abc |
|
#<RuntimeError: r> |
|
b |
|
e |
|
#<ArgumentError: wrong number of arguments (1 for 0)> |
|
require 'common'
#
# file: test/test_hash.rb
#
module T_TestHash
class TestHash
if $RUBYJS
def hash
`var el = {}; el["1"] = null; return el`
end
else
def hash
{"1" => nil}
end
end
def test
h = {"a" => 6, "b" => 7, "1" => 1, 1 => 2, "1,2" => "hello", [1,2] => "good"}
p h["a"]
p h["b"]
p h["1"]
p h[1]
p h["1,2"]
p h[[1,2]]
puts "test native JS hash"
a = hash()
#p a
end
def self.main
new.test
end
end
end
#
# file: test/test_yield.rb
#
module T_TestYield
class TestYield
def three_times_yield
yield 1
yield 2
yield 3
end
def test_three_times_yield
puts "three_times_yield"
three_times_yield {|i| p i }
puts "--"
end
def three_times_block(&block)
block.call(1)
block.call(2)
block.call(3)
end
def test_three_times_block
puts "three_times_block"
three_times_block {|i| p i }
puts "--"
end
def three_times_indirect(&block)
three_times_yield(&block)
three_times_block(&block)
end
def test_three_times_indirect
puts "three_times_indirect"
three_times_indirect {|i| p i}
puts "--"
end
def three_times_yield2
p yield(1)
p yield(2)
p yield(3)
end
def test_three_times_yield2
puts "three_times_yield2"
three_times_yield2 {|i|
if i == 1
i
else
next i+1
end
}
end
def loop
while true
yield
end
p "not reached"
end
def loop2(&block)
while true
block.call
end
p "not reached"
end
def test_loop
puts "loop"
i = 0
res = loop do
i += 1
next if i % 2 == 1
p i
break "out", i if i > 8
end
p res
puts "--"
end
def test_loop2
puts "loop2"
i = 0
res = loop2 do
i += 1
next if i % 2 == 1
p i
break "out", i if i > 8
end
p res
puts "--"
end
def test_while_loop
puts "while-loop"
i = 0
while true
i += 1
next if i % 2 == 1
p i
break if i > 8
end
puts "----"
while i > 0
p i
i -= 1
end
puts "--"
end
def return_in_block(&block)
p "return_in_block before"
block.call
p "return_in_block after"
end
def test_return_in_block
p "before"
return_in_block { return 4 }
p "after (NOT)"
end
def test_proc
p "test_proc"
a = proc { return 0 }
p a.call
a = Proc.new { break 3 }
p a.call
end
def test
test_three_times_yield
test_three_times_block
test_three_times_indirect
test_three_times_yield2
test_loop
test_loop2
test_while_loop
(proc {||}).call
begin
test_proc
rescue LocalJumpError => e
p e
end
p test_return_in_block()
end
def self.main
new.test
end
end
end
#
# file: test/test_insertion_sort.rb
#
module T_TestInsertionSort
class TestInsertionSort
def sort ary
puts "Before insertion sort:"
p ary
for i in 1..(ary.length-1) do
n = i
while n >= 1 && ary[n] < ary[n - 1] do
if ary[n] < ary[n - 1]
tmp = ary[n]
ary[n] = ary[n - 1]
ary[n - 1] = tmp
end
n -= 1
end
end
puts "After insertion sort:"
p ary
end
def self.main
new.sort [3, 6, 2, 5, 3, 7, 1, 8]
end
end
end
#
# file: test/test_lebewesen.rb
#
module T_TestLebewesen
class TestLebewesen
def self.main
leni = Katze.new("AA-BB", "Leni")
flocki = Katze.new("AC-DC", "Flocki")
bello = Hund.new("AA-ZZ")
leni.miau
bello.wau
bello.jage(leni)
end
end
class Lebewesen
def initialize(dns)
@dns = dns
end
end
class Katze < Lebewesen
attr_reader :name
def initialize(dns, name)
super(dns)
@name = name
end
def miau
puts "miau, ich bin " + @name
end
end
class Hund < Lebewesen
def wau
puts "wau wau"
end
def jage(katze)
puts "ich jage " + katze.name
end
end
end
#
# file: test/test_expr.rb
#
module T_TestExpr
class TestExpr
def test
i = if true then 1 else 2 end
p i
i = true or return
p i
end
def self.main
new.test
end
end
end
#
# file: test/test_simple_output.rb
#
module T_TestSimpleOutput
class TestSimpleOutput
def self.main()
puts "Hello World from RubyJS"
end
end
end
#
# file: test/test_if.rb
#
module T_TestIf
class TestIf
def test
puts "OK" if true
puts "NOT OK" if false
puts "OK" unless false
puts "NOT OK" unless true
puts "OK" if true and true and (true or false) and (!false)
puts "OK" if 5 < 6 and 6 < 7
# test the "||" operator
p(false || "a") # => "a"
p(nil || "a") # => "a"
p(true || "a") # => true
p("b" || "a") # => "b"
# test the "&&" operator
p(false && "a") # => false
p(nil && "a") # => nil
p(true && "a") # => "a"
p("b" && "a") # => "a"
end
def self.main
new.test
end
end
end
#
# file: test/test_class.rb
#
module T_TestClass
module X
end
class A
include X
end
class B < A
end
class C < B
end
class D
end
class TestClass
def self.main
p A.new.instance_of?(A) # => true
p A.new.instance_of?(B) # => false
p B.new.instance_of?(A) # => false
p A.new.instance_of?(X) # => false
p B.new.instance_of?(X) # => false
p A.new.kind_of?(A) # => true
p A.new.kind_of?(B) # => false
p B.new.kind_of?(A) # => true
p A.new.kind_of?(X) # => true
p B.new.kind_of?(X) # => true
p C.new.kind_of?(X) # => true
p C.new.kind_of?(A) # => true
p C.new.kind_of?(B) # => true
p C.new.kind_of?(C) # => true
p C.new.kind_of?(D) # => false
p C.new.kind_of?(Object) # => true
p C.new.kind_of?(Kernel) # => true
p C.new.kind_of?(Class) # => false
p ("hallo".class.name)
p (nil.class.name)
p (nil.instance_of?(NilClass))
p ("hallo".instance_of?(String))
p ("hallo".class)
p A
p B
p C
p D
p X
p X.name
p A.name
p B.name
end
end
end
#
# file: test/test_case.rb
#
module T_TestCase
class TestCase
def test
case 1+1
when 1, 3
puts "NOT OKAY"
when 2
puts "OKAY"
else
puts "NOT OKAY"
end
p (Array === [])
p (RuntimeError === RuntimeError.new)
case 1
when Fixnum
puts "OK"
when 1
puts "OK"
end
case 4
when 0..3
puts "NOT OKAY"
when 1...4
puts "NOT OKAY"
when 2..4
puts "OKAY"
end
end
def self.main
new.test
end
end
end
#
# file: test/test_splat.rb
#
module T_TestSplat
class TestSplat
def m(*args)
p args
end
def self.main
obj = new()
obj.m
obj.m(*[])
obj.m(1)
obj.m(*[1])
obj.m(1,*[])
obj.m(1,2)
obj.m(*[1,2])
obj.m(1,*[2])
obj.m(1,*[1,2])
end
end
end
#
# file: test/test_string.rb
#
module T_TestString
class TestString
def test
# inspect
p "hello"
p "hallo\b\t\n"
p "hallo\\leute"
p '"super"'
# index
p "hello".index('e')
p "hello".index('lo')
p "hello".index('a')
p "hello hello".index('ll')
p "hello hello".index('ll', 3)
# []
p "hallo"[0,1]
p "hallo"[0,2]
p "hallo"[0,5]
p ("10".rjust(10, "0"))
p ("10".rjust(1, "blah"))
p ("x".rjust(4, "()"))
p ("10".ljust(10, "0"))
p ("10".ljust(1, "blah"))
p ("x".ljust(4, "()"))
# string interpolation
p "abc #{ 1 + 2 } def"
@a = "hallo".inspect
@b = 4.5
p "#{@a},#{@b}"
# gsub
s = "hallo".gsub("l", "r")
p s
s = "hallo".gsub(/ll/, "rr")
p s
s = "hallo".gsub(/l/) { "r" }
p s
s = "hallo".gsub(/ll/) { "blah blah" }
p s
"hallllllo".gsub(/(l)l/) {|i| p i }
end
def self.main
new.test
end
end
end
#
# file: test/test_inspect.rb
#
module T_TestInspect
class TestInspect
def test
o = [{"Hello"=>'Rubyconf'}]
puts o.inspect
end
def self.main
new.test
end
end
end
#
# file: test/test_regexp.rb
#
module T_TestRegexp
class TestRegexp
def test
p "okay" if "hallo" =~ /ll/
pos = "hallo" =~ /ll/
p pos
"hallo" =~ /(ll)/
p $1
p $2
p $3
"hallo" =~ /a(ll)(o)/
p $1
p $2
p $3
p $4
end
def self.main
new.test
end
end
end
#
# file: test/test_args.rb
#
module T_TestArgs
class TestArgs
def m(a, b=1, c="hallo", *args)
p a
p b
p c
p args
end
def self.main
obj = new()
obj.m(0)
puts "--"
obj.m(1,2)
puts "--"
obj.m(1,2,9)
puts "--"
obj.m(1,2,9,5)
puts "--"
obj.m(1,2,9,5,6)
puts "--"
obj.m(1,2,9,5,6,7,8,9,10,11,12)
end
end
end
#
# file: test/test_array.rb
#
module T_TestArray
class TestArray
if $RUBYJS
def array
[1, 2, `null`, [`null`, `null`, 4]]
end
else
def array
[1, 2, nil, [nil, nil, 4]]
end
end
def test
# delete
a = [ "a", "b", "b", "b", "c" ]
p a.delete("b") #=> "b"
p a #=> ["a", "c"]
p a.delete("z") #=> nil
puts "test native JS array mapping"
p array()
end
def self.main
new.test
end
end
end
#
# file: test/test_eql.rb
#
module T_TestEql
class TestEql
def self.main
p "a".eql?("a") # => true
p "a".eql?(1) # => false
p "1".eql?(1) # => false
p [1,2].eql?([1,2]) # => true
p 1.eql?("1") # => false
end
end
end
#
# file: test/test_send.rb
#
module T_TestSend
class A
def a_method(a,b)
p a, b
end
end
class B < A
def a_method(b, a)
p "in B"
super
end
def c_method(b)
end
end
class C
def method_missing(id, *args, &block)
p "mm: #{id}, #{args}"
end
end
class TestSend
def self.main
puts "send"
p A.new.send("a_method", 1, 2)
p B.new.send("a_method", 1, 2)
puts "respond_to?"
p A.new.respond_to?(:a_method)
p A.new.respond_to?(:to_s)
p A.new.respond_to?(:inspect)
p A.new.respond_to?(:b_method)
p A.new.respond_to?(:c_method)
puts "method_missing"
p C.new.respond_to?(:blah_blah)
C.new.blah_blah(1,2,3)
begin
A.new.blah_blah
puts "FAILURE?"
rescue NoMethodError
puts "catched!!!"
end
begin
A.not_a_method
rescue NoMethodError
p "goood"
end
puts "class Method"
m = "hallo".method(:to_s)
p m
p m.call
a = [1,2,3]
m = a.method(:+)
p m
p m.call([2,3])
p m
p a
end
end
end
#
# file: test/test_range.rb
#
module T_TestRange
class TestRange
def test
a = Range.new(0,2)
p a.first
p a.last
p a
i = 1
p ((i..i+5).to_s)
p ((i...i+i).to_s)
p ((0..2).to_s)
p ((0...2).to_s)
(0..4).each do |i| p i end
(0...4).each do |i| p i end
(-1..-4).each do |i| p i end
p ((0..4).include?(4))
p ((0..4).include?(5))
p ((0...4).include?(5))
p ((0...4).include?(4))
p ((0...4).include?(3))
p ((0...4).include?(0))
p ((0...4).include?(-1))
p ((-1..-5).to_a)
p ((-5..-1).to_a)
r = Range.new(0, 4)
p r.first
p r.begin
p r.last
p r.end
p r.exclude_end?
r = 1...5
p r.first
p r.begin
p r.last
p r.end
p r.exclude_end?
p (false == false)
p (false == true)
p (true == false)
p (true == true)
p ((0..2) == (0..2))
p ((0..2) == Range.new(0,2))
p ((0..2) == (0...2))
j = 55
p j
for i in 1..100
j = i
end
p j
j = 54
p j
for j in 1..100
end
p j
end
def self.main
new.test
end
end
end
#
# file: test/test_massign.rb
#
module T_TestMassign
class TestMassign
def self.main
a, b = 1, 2
p a
p b
puts "--"
a, b = 1, 2, 3
p a
p b
puts "--"
c = 5
a, b, c = 1, 2
p a
p b
p c
puts "--"
@a, b, @c = 1, 2, 3
p @a
p b
p @c
puts "--"
puts "swap"
# swap
a, b = 1, 2
p a
p b
a, b = b, a
p a
p b
puts "--"
puts "splat1"
a, b, c, *d = 1, 2
p a
p b
p c
p d
puts "--"
puts "splat2"
a, *b = 1, 2
p a
p b
puts "--"
puts "splat3"
a, *b = 1, 2, 3, 4, 5
p a
p b
puts "--"
puts "splat with globals"
p $a
p $b
$a, $b = 1, 2
p $a
p $b
puts "--"
#TODO: a, b = 1 (to_ary)
end
end
end
#
# file: test/test_hot_ruby.rb
#
module T_TestHotRuby
#
# Examples taken from: http://hotruby.accelart.jp/
#
class TestHotRuby
def sort ary
puts "Before insertion sort:"
p ary
for i in 1..(ary.length-1) do
n = i
while n >= 1 && ary[n] < ary[n - 1] do
if ary[n] < ary[n - 1]
tmp = ary[n]
ary[n] = ary[n - 1]
ary[n - 1] = tmp
end
n -= 1
end
end
puts "After insertion sort:"
p ary
end
def addPrint a, b, c
puts a + b + c
end
def self.main
t = new()
puts "InsertionSort"
t.sort [3, 6, 2, 5, 3, 7, 1, 8]
puts "Array args"
ary = [' World ', '!']
t.addPrint 'Hello', *ary
puts "Block"
Foo.new.main
puts "Class"
puts Pi::PI
# different precision on Ruby vs. Javascript
puts Pi.new.calc.to_s[0,13]
puts "Const"
# FIXME
=begin
Bar_::Baz_.new.run
Bar2.new.run
Object::Bar2.new.run
Bar3.new.run
=end
end
end
#
# Block
#
class Hoge
def add_msg &block
block.call "is" # s/yield/call/
end
end
class Foo
NAME = ' - William Shakespeare'
def main
pre = "Action"
@space = " "
Hoge.new.add_msg do |msg|
fuga = "eloquence"
puts pre + @space + msg + @space + fuga + NAME
end
end
end
#
# Class
#
class Pi
def initialize
@a = 355.0
end
def calc
b = 113.0
return @a / b
end
PI = 'PI is about'
end
#
# Const
#
class Foo_
CONST = 'Foo'
end
class Bar_
CONST = 'Bar'
class Baz_ < Foo_
def run
puts CONST # => "Bar" Outer class const
# In this case, you have to specify if you want to see parent class const.
puts Foo_::CONST # => "Foo"
end
end
end
class Foo2
CONST = 'Foo'
end
CONST = 'Object'
class Bar2 < Foo2
def run
puts CONST # => "Foo"
end
end
# If you specify "Object", then const in Object is searched before.
class Object
class Bar2 < Foo2
def run
puts CONST # => "Object"
end
end
end
class Foo3
CONST = 'Foo'
end
class Bar3 < Foo3
def run
puts CONST # => "Foo"
#CONST = 'Bar' # Define Bar's const "CONST"
puts CONST # => "Bar" (Foo::CONST is hidden)
puts Foo3::CONST # => "Foo" (You can see by "::")
end
end
end
#
# file: test/test_new.rb
#
module T_TestNew
class TestNew
def initialize
end
def test
puts "test"
end
def self.main()
new().test
end
end
end
#
# file: test/test_exception.rb
#
module T_TestException
class TestException
def self.main
p "before block"
begin
p "in block"
end
p "after block"
###
begin
p "block"
rescue
p "rescue"
rescue Exception => a
p "another rescue"
p a
else
p "else"
end
p RuntimeError.new("test")
puts "before begin"
begin
puts "before raise"
raise Exception, "blah"
puts "after raise"
rescue
puts "noooo"
rescue Exception => a
p a
puts "yes"
ensure
puts "ensure"
end
puts "after begin"
puts "--"
begin
puts "abc"
raise "r"
rescue
p $!
puts "b"
ensure
puts "e"
end
#
# Test arity checks
#
begin
p("hallo".to_s(2))
rescue ArgumentError => a
p a
end
end
end
end
class TestSuite
def self.main
begin
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test hash'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestHash::TestHash.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test yield'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestYield::TestYield.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test insertion sort'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestInsertionSort::TestInsertionSort.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test lebewesen'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestLebewesen::TestLebewesen.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test expr'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestExpr::TestExpr.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test simple output'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestSimpleOutput::TestSimpleOutput.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test if'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestIf::TestIf.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test class'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestClass::TestClass.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test case'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestCase::TestCase.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test splat'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestSplat::TestSplat.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test string'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestString::TestString.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test inspect'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestInspect::TestInspect.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test regexp'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestRegexp::TestRegexp.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test args'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestArgs::TestArgs.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test array'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestArray::TestArray.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test eql'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestEql::TestEql.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test send'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestSend::TestSend.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test range'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestRange::TestRange.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test massign'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestMassign::TestMassign.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test hot ruby'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestHotRuby::TestHotRuby.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test new'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestNew::TestNew.main
puts '~~~~~~~~~~~~~~~~~~~~'
puts 'Test exception'
puts '~~~~~~~~~~~~~~~~~~~~'
T_TestException::TestException.main
rescue Exception => a
p "unhandled exception"
p a
end
end
end
TestSuite.main unless $RUBYJS