summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-27 01:25:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-27 01:25:01 +0000
commit1ac307dddc22f333e5e1d93110eb4eeb947fc79c (patch)
tree0ce5c5ec0b7180d66b36c3092458139cdead73a2
parentf9e7c3c37f022aa88dc19c993e814df03c623239 (diff)
* 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
-rw-r--r--ChangeLog5
-rw-r--r--lib/rdoc/parser.rb4
-rw-r--r--test/rdoc/test_rdoc_parser.rb8
3 files changed, 12 insertions, 5 deletions
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 <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
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