* test/ruby/test_yield.rb: new test.

* yarvtest/test_yield.rb: removed (moved to test_yield.rb).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2007-02-23 09:38:08 +00:00
Родитель bb022bed3a
Коммит bd3ee06295
3 изменённых файлов: 73 добавлений и 207 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Fri Feb 23 18:37:55 2007 Minero Aoki <aamine@loveruby.net>
* test/ruby/test_yield.rb: new test.
* yarvtest/test_yield.rb: removed (moved to test_yield.rb).
Fri Feb 23 18:27:17 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* thread.c (rb_thread_polling): check interrupts here.

67
test/ruby/test_yield.rb Normal file
Просмотреть файл

@ -0,0 +1,67 @@
require 'test/unit'
class TestRubyYield < Test::Unit::TestCase
def test_ary_each
ary = [1]
ary.each {|a, b, c, d| assert_equal [1,nil,nil,nil], [a,b,c,d] }
ary.each {|a, b, c| assert_equal [1,nil,nil], [a,b,c] }
ary.each {|a, b| assert_equal [1,nil], [a,b] }
ary.each {|a| assert_equal 1, a }
end
def test_hash_each
h = {:a => 1}
h.each do |k, v|
assert_equal :a, k
assert_equal 1, v
end
h.each do |kv|
assert_equal [:a, 1], kv
end
end
def test_yield_0
assert_equal 1, iter0 { 1 }
assert_equal 2, iter0 { 2 }
end
def iter0
yield
end
def test_yield_1
iter1([]) {|a, b| assert_equal [nil,nil], [a, b] }
iter1([1]) {|a, b| assert_equal [1,nil], [a, b] }
iter1([1, 2]) {|a, b| assert_equal [1,2], [a,b] }
iter1([1, 2, 3]) {|a, b| assert_equal [1,2], [a,b] }
iter1([]) {|a| assert_equal [], a }
iter1([1]) {|a| assert_equal [1], a }
iter1([1, 2]) {|a| assert_equal [1,2], a }
iter1([1, 2, 3]) {|a| assert_equal [1,2,3], a }
end
def iter1(args)
yield args
end
def test_yield2
def iter2_1() yield 1, *[2, 3] end
iter2_1 {|a, b, c| assert_equal [1,2,3], [a,b,c] }
def iter2_2() yield 1, *[] end
iter2_2 {|a, b, c| assert_equal [1,nil,nil], [a,b,c] }
def iter2_3() yield 1, *[2] end
iter2_3 {|a, b, c| assert_equal [1,2,nil], [a,b,c] }
end
def test_yield_nested
[[1, [2, 3]]].each {|a, (b, c)|
assert_equal [1,2,3], [a,b,c]
}
[[1, [2, 3]]].map {|a, (b, c)|
assert_equal [1,2,3], [a,b,c]
}
end
end

Просмотреть файл

@ -1,207 +0,0 @@
require 'yarvtest/yarvtest'
class TestYield < YarvTestBase
def test_simple
ae %q{
def iter
yield
end
iter{
1
}
}
end
def test_hash_each
ae %q{
h = {:a => 1}
a = []
h.each{|k, v|
a << [k, v]
}
h.each{|kv|
a << kv
}
a
}
end
def test_ary_each
ae %q{
ans = []
ary = [1,2,3]
ary.each{|a, b, c, d|
ans << [a, b, c, d]
}
ary.each{|a, b, c|
ans << [a, b, c]
}
ary.each{|a, b|
ans << [a, b]
}
ary.each{|a|
ans << [a]
}
ans
}
end
def test_iter
ae %q{
def iter *args
yield *args
end
ans = []
ary = [1,2,3]
ary.each{|a, b, c, d|
ans << [a, b, c, d]
}
ary.each{|a, b, c|
ans << [a, b, c]
}
ary.each{|a, b|
ans << [a, b]
}
ary.each{|a|
ans << [a]
}
ans
}
end
def test_iter2
ae %q{
def iter args
yield *args
end
ans = []
iter([]){|a, b|
ans << [a, b]
}
iter([1]){|a, b|
ans << [a, b]
}
iter([1, 2]){|a, b|
ans << [a, b]
}
iter([1, 2, 3]){|a, b|
ans << [a, b]
}
ans
}
ae %q{
def iter args
yield *args
end
ans = []
iter([]){|a|
ans << a
}
iter([1]){|a|
ans << a
}
iter([1, 2]){|a|
ans << a
}
iter([1, 2, 3]){|a|
ans << a
}
ans
}
end
def test_1_ary_and_n_params
ae %q{
def iter args
yield args
end
ans = []
iter([]){|a, b|
ans << [a, b]
}
iter([1]){|a, b|
ans << [a, b]
}
iter([1, 2]){|a, b|
ans << [a, b]
}
iter([1, 2, 3]){|a, b|
ans << [a, b]
}
ans
}
end
def test_1_ary_and_1_params
ae %q{
def iter args
yield args
end
ans = []
iter([]){|a|
ans << a
}
iter([1]){|a|
ans << a
}
iter([1, 2]){|a|
ans << a
}
iter([1, 2, 3]){|a|
ans << a
}
ans
}
end
def test_argscat
ae %q{
def iter
yield 1, *[2, 3]
end
iter{|a, b, c|
[a, b, c]
}
}
ae %q{
def iter
yield 1, *[]
end
iter{|a, b, c|
[a, b, c]
}
}
if false
ae %q{
def iter
yield 1, *2
end
iter{|a, b, c|
[a, b, c]
}
}
end
end
def test_massgin
ae %q{
ans = []
[[1, [2, 3]], [4, [5, 6]]].each{|a, (b, c)|
ans << [a, b, c]
}
ans
}
ae %q{
ans = []
[[1, [2, 3]], [4, [5, 6]]].map{|a, (b, c)|
ans << [a, b, c]
} + ans
}
end
end