diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-16 15:01:55 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-16 15:01:55 +0000 |
commit | cc9b886691bc4d2f9b81edc5583c929fda7ea769 (patch) | |
tree | 0ea1dca6880135a46eed4108b5c6d716db9e4980 /test/ruby/test_io.rb | |
parent | e46e5d2438089b24048927840d646c731dc882cf (diff) | |
download | ruby-cc9b886691bc4d2f9b81edc5583c929fda7ea769.tar.gz |
* io.c (rb_io_advise): New API. IO#advise() allows to tell the
ruby runtime how it expects to use a file handle. This feature
can be improved a performance some situations.
Note: This feature is mainly developed by Run Paint Run Run.
Thank you! [ruby-core:33110] [Ruby 1.9-Feature#4038]
* io.c (do_io_advise): Helper function.
* io.c (io_advise_sym_to_const): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r-- | test/ruby/test_io.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 75263e9cc5..b3d543fc2f 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1737,4 +1737,38 @@ End end end end + + def test_advise + t = make_tempfile + assert_raise(ArgumentError, "no arguments") { t.advise } + %w{normal random sequential willneed dontneed noreuse}.map(&:to_sym).each do |adv| + [[0,0], [0, 20], [400, 2]].each do |offset, len| + open(make_tempfile.path) do |t| + assert_equal(t.advise(adv, offset, len), nil) + assert_raise(ArgumentError, "superfluous arguments") do + t.advise(adv, offset, len, offset) + end + assert_raise(TypeError, "wrong type for first argument") do + t.advise(adv.to_s, offset, len) + end + assert_raise(TypeError, "wrong type for last argument") do + t.advise(adv, offset, Array(len)) + end + assert_raise(RangeError, "last argument too big") do + t.advise(adv, offset, 9999e99) + end + end + assert_raise(IOError, "closed file") do + make_tempfile.advise(adv.to_sym, offset, len) + end + end + end + %w{Normal rand glark will_need zzzzzzzzzzzz \u2609}.map(&:to_sym).each do |adv| + [[0,0], [0, 20], [400, 2]].each do |offset, len| + open(make_tempfile.path) do |t| + assert_equal(t.advise(adv, offset, len), nil) + end + end + end + end end |