diff --git a/ChangeLog b/ChangeLog index e9d111b28b..8f3cf7533e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Jul 27 10:24:50 2009 Nobuyoshi Nakada + + * lib/rdoc/parser.rb (RDoc::Parser.binary?): fix for empty files. + [ruby-dev:38848] + Sun Jul 26 19:17:33 2009 Nobuyoshi Nakada * io.c (argf_eof): go to the next file if called after ARGF.close diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index bb7e0c7d81..3798734d5e 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -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? diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb index d6420d20f1..19e859e528 100644 --- a/test/rdoc/test_rdoc_parser.rb +++ b/test/rdoc/test_rdoc_parser.rb @@ -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