mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add Pathname#lexer and Pathname#lexer_name
This commit is contained in:
@@ -22,6 +22,22 @@ module Linguist
|
|||||||
Language.find_by_extension(extname)
|
Language.find_by_extension(extname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def lexer
|
||||||
|
if language
|
||||||
|
language.lexer
|
||||||
|
else
|
||||||
|
'plain'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def lexer_name
|
||||||
|
if language
|
||||||
|
language.name
|
||||||
|
else
|
||||||
|
'Text'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
@path.dup
|
@path.dup
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,4 +41,21 @@ class TestPathname < Test::Unit::TestCase
|
|||||||
assert_equal Language['Nu'], Pathname.new("itty.nu").language
|
assert_equal Language['Nu'], Pathname.new("itty.nu").language
|
||||||
assert_nil Pathname.new("defun.kt").language
|
assert_nil Pathname.new("defun.kt").language
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_lexer
|
||||||
|
assert_equal 'ruby', Pathname.new("file.rb").lexer
|
||||||
|
assert_equal 'ruby', Pathname.new("Rakefile").lexer
|
||||||
|
assert_equal 'bash', Pathname.new("file.ebuild").lexer
|
||||||
|
assert_equal 'python', Pathname.new("itty.py").lexer
|
||||||
|
assert_equal 'scheme', Pathname.new("itty.nu").lexer
|
||||||
|
assert_equal 'plain', Pathname.new("defun.kt").lexer
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_lexer_name
|
||||||
|
assert_equal 'Ruby', Pathname.new("file.rb").lexer_name
|
||||||
|
assert_equal 'Gentoo Ebuild', Pathname.new("file.ebuild").lexer_name
|
||||||
|
assert_equal 'Ruby', Pathname.new("Rakefile").lexer_name
|
||||||
|
assert_equal 'Nu', Pathname.new("itty.nu").lexer_name
|
||||||
|
assert_equal 'Text', Pathname.new("defun.kt").lexer_name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user