summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-23 09:38:08 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-23 09:38:08 +0000
commitbd3ee06295a54b714282d71bca309c86f1869aa9 (patch)
tree62dd4e250cc53680f48f4784e63c4e45c9ecf2cf
parentbb022bed3a0e20b6fee92ad8910d1e0651c43f18 (diff)
* 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
-rw-r--r--ChangeLog6
-rw-r--r--test/ruby/test_yield.rb67
-rw-r--r--yarvtest/test_yield.rb207
3 files changed, 73 insertions, 207 deletions
diff --git a/ChangeLog b/ChangeLog
index 9af381eb72..03c2fc2d88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/test/ruby/test_yield.rb b/test/ruby/test_yield.rb
new file mode 100644
index 0000000000..bc00407e4d
--- /dev/null
+++ b/test/ruby/test_yield.rb
@@ -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
diff --git a/yarvtest/test_yield.rb b/yarvtest/test_yield.rb
deleted file mode 100644
index 56fa48b0c8..0000000000
--- a/yarvtest/test_yield.rb
+++ /dev/null
@@ -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
-
-