mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Basic blob tests
This commit is contained in:
2
test/fixtures/blob/foo.rb
vendored
Normal file
2
test/fixtures/blob/foo.rb
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module Foo
|
||||||
|
end
|
||||||
52
test/test_blob.rb
Normal file
52
test/test_blob.rb
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
require 'linguist/blob'
|
||||||
|
|
||||||
|
require 'test/unit'
|
||||||
|
require 'mime/types'
|
||||||
|
|
||||||
|
class TestBlob < Test::Unit::TestCase
|
||||||
|
include Linguist
|
||||||
|
|
||||||
|
class FixtureBlob
|
||||||
|
def initialize(name)
|
||||||
|
@name = name
|
||||||
|
@path = File.expand_path("../fixtures/blob/#{name}", __FILE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
def name
|
||||||
|
@name
|
||||||
|
end
|
||||||
|
|
||||||
|
def mime_type
|
||||||
|
guesses = ::MIME::Types.type_for(name)
|
||||||
|
orginal_type = guesses.first ? guesses.first.simplified : 'text/plain'
|
||||||
|
end
|
||||||
|
|
||||||
|
def data
|
||||||
|
File.read(@path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def size
|
||||||
|
File.size(@path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def blob(name)
|
||||||
|
Blob.new(FixtureBlob.new(name))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_name
|
||||||
|
assert_equal Pathname.new("foo.rb"), blob("foo.rb").name
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_mime_type
|
||||||
|
assert_equal "application/ruby", blob("foo.rb").mime_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_data
|
||||||
|
assert_equal "module Foo\nend\n", blob("foo.rb").data
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_size
|
||||||
|
assert_equal 15, blob("foo.rb").size
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user