mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add Blob#loc and Blob#sloc
This commit is contained in:
@@ -12,10 +12,6 @@ module Linguist
|
|||||||
|
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
def data
|
|
||||||
@blob.data
|
|
||||||
end
|
|
||||||
|
|
||||||
def mime_type
|
def mime_type
|
||||||
Mime.lookup(name.extname)
|
Mime.lookup(name.extname)
|
||||||
end
|
end
|
||||||
@@ -29,10 +25,26 @@ module Linguist
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def data
|
||||||
|
@blob.data
|
||||||
|
end
|
||||||
|
|
||||||
|
def lines
|
||||||
|
@lines ||= data ? data.split("\n", -1) : []
|
||||||
|
end
|
||||||
|
|
||||||
def size
|
def size
|
||||||
@blob.size
|
@blob.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def loc
|
||||||
|
lines.size
|
||||||
|
end
|
||||||
|
|
||||||
|
def sloc
|
||||||
|
lines.grep(/\S/).size
|
||||||
|
end
|
||||||
|
|
||||||
def submodule?
|
def submodule?
|
||||||
defined?(Grit::Submodule) && @blob.kind_of?(Grit::Submodule)
|
defined?(Grit::Submodule) && @blob.kind_of?(Grit::Submodule)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -51,10 +51,22 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
assert_equal "module Foo\nend\n", blob("foo.rb").data
|
assert_equal "module Foo\nend\n", blob("foo.rb").data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_lines
|
||||||
|
assert_equal ["module Foo", "end", ""], blob("foo.rb").lines
|
||||||
|
end
|
||||||
|
|
||||||
def test_size
|
def test_size
|
||||||
assert_equal 15, blob("foo.rb").size
|
assert_equal 15, blob("foo.rb").size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_loc
|
||||||
|
assert_equal 3, blob("foo.rb").loc
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sloc
|
||||||
|
assert_equal 2, blob("foo.rb").sloc
|
||||||
|
end
|
||||||
|
|
||||||
def test_binary
|
def test_binary
|
||||||
assert blob("linguist.gem").binary?
|
assert blob("linguist.gem").binary?
|
||||||
assert blob("git.deb").binary?
|
assert blob("git.deb").binary?
|
||||||
|
|||||||
Reference in New Issue
Block a user