1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rdoc/parser.rb (RDoc::Parser.binary?): fix for empty files.

[ruby-dev:38848]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-07-27 01:25:01 +00:00
parent f9e7c3c37f
commit 1ac307dddc
3 changed files with 12 additions and 5 deletions

View file

@ -1,3 +1,8 @@
Mon Jul 27 10:24:50 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rdoc/parser.rb (RDoc::Parser.binary?): fix for empty files.
[ruby-dev:38848]
Sun Jul 26 19:17:33 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (argf_eof): go to the next file if called after ARGF.close

View file

@ -66,8 +66,8 @@ class RDoc::Parser
# Return _true_ if the +file+ seems like binary.
def self.binary?(file)
s = File.read(file, 1024)
s.count("^ -~\t\r\n").fdiv(s.size) > 0.3 || s.index("\x00") unless s.empty?
s = File.read(file, 1024) or return false
s.count("^ -~\t\r\n").fdiv(s.size) > 0.3 || s.index("\x00")
end
private_class_method :binary?

View file

@ -1,9 +1,9 @@
require 'rubygems'
require 'minitest/unit'
require 'test/unit'
require 'rdoc/parser'
require 'rdoc/parser/ruby'
class TestRDocParser < MiniTest::Unit::TestCase
class TestRDocParser < Test::Unit::TestCase
def test_can_parse
assert_equal(RDoc::Parser.can_parse(__FILE__), RDoc::Parser::Ruby)
@ -16,7 +16,9 @@ class TestRDocParser < MiniTest::Unit::TestCase
assert_equal(RDoc::Parser.can_parse(readme_file_name), RDoc::Parser::Simple)
binary_file_name = File.join(File.dirname(__FILE__), "binary.dat")
assert_equal(RDoc::Parser.can_parse(binary_file_name), nil)
assert_nil(RDoc::Parser.can_parse(binary_file_name))
empty_file_name = File.join(File.dirname(__FILE__), "empty.dat")
assert_not_nil(RDoc::Parser.can_parse(empty_file_name))
end
end