Permalink
Browse files

* test/scanf/test_scanf.rb (ScanfTests#each_test): yield in order.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 30f6370 commit fa086089fb591705f080eaf7a6021012dd3c6efc @nobu nobu committed May 13, 2010
Showing with 10 additions and 7 deletions.
  1. +10 −7 test/scanf/test_scanf.rb
View
@@ -287,18 +287,23 @@ def tests
]
end
+
+ def each_test
+ i = "0" * (Math.log(self.tests.size, 10).floor+1)
+ self.tests.each do |test|
+ yield test, i.succ!
+ end
+ end
end
class TestStringScanf
include Scanf
extend ScanfTests
- i = 1
- self.tests.each do |test|
+ self.each_test do |test, i|
define_method("test_#{i}") do ||
assert_equal(test[2], test[1].scanf(test[0]))
- end
- i += 1
+ end
end
end
@@ -308,15 +313,13 @@ class TestIOScanf
tmpfilename = "#{Dir.tmpdir}/iotest.dat.#{$$}"
- i = 1
- self.tests.each do |test|
+ self.each_test do |test, i|
define_method("test_#{i}") do ||
File.open(tmpfilename, "w") {|fh| fh.print test[1]}
File.open(tmpfilename, "r") { |fh|
assert_equal(test[2], fh.scanf(test[0]))
}
File.delete(tmpfilename)
end
- i += 1
end
end

0 comments on commit fa08608

Please sign in to comment.