Add Blob#binary?

This commit is contained in:
Joshua Peek
2011-05-13 12:54:16 -05:00
parent 6ead7d8f37
commit dec56649b2
2 changed files with 13 additions and 1 deletions

View File

@@ -26,8 +26,12 @@ module Linguist
defined?(Grit::Submodule) && @blob.kind_of?(Grit::Submodule)
end
def binary?
mime_type == 'octet-stream' || !(text? || image?)
end
def file?
image? || !text? || mime_type == 'octet-stream'
image? || binary?
end
def text?

View File

@@ -50,6 +50,14 @@ class TestBlob < Test::Unit::TestCase
assert_equal 15, blob("foo.rb").size
end
def test_binary
assert blob("linguist.gem").binary?
assert blob("git.deb").binary?
assert blob("git.exe").binary?
assert !blob("file.txt").binary?
assert !blob("octocat.png").binary?
end
def test_file
assert blob("octocat.png").file?
assert blob("linguist.gem").file?