summaryrefslogtreecommitdiff
path: root/lib/coderay/helpers
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2010-01-01 04:42:13 +0000
committermurphy <murphy@rubychan.de>2010-01-01 04:42:13 +0000
commitc45da135ebc403f9e10c09afec73b44bdbc74153 (patch)
tree04527bb7755d01ce5ea0ae4b95f417f15dcc4e4a /lib/coderay/helpers
parente2e6e212ebe78a4d29376f46b69cc44c302ffdc5 (diff)
downloadcoderay-c45da135ebc403f9e10c09afec73b44bdbc74153.tar.gz
Fixed: More file extensions for C++ scanner as suggested by Sander Cox.
Diffstat (limited to 'lib/coderay/helpers')
-rw-r--r--lib/coderay/helpers/file_type.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/coderay/helpers/file_type.rb b/lib/coderay/helpers/file_type.rb
index f9cdd36..e8a0384 100644
--- a/lib/coderay/helpers/file_type.rb
+++ b/lib/coderay/helpers/file_type.rb
@@ -38,7 +38,9 @@ module FileType
ext2 = filename.to_s[/\.(.*)/, 1] # from first dot
type =
+ TypeFromExt[ext] ||
TypeFromExt[ext.downcase] ||
+ (TypeFromExt[ext2] if ext2) ||
(TypeFromExt[ext2.downcase] if ext2) ||
TypeFromName[name] ||
TypeFromName[name.downcase]
@@ -82,7 +84,6 @@ module FileType
TypeFromExt = {
'c' => :c,
- 'cpp' => :cpp,
'css' => :css,
'diff' => :diff,
'dpr' => :delphi,
@@ -119,6 +120,9 @@ module FileType
'yaml' => :yaml,
'yml' => :yaml,
}
+ for cpp_alias in %w[cc cpp cp cxx c++ C hh hpp h++ cu]
+ TypeFromExt[cpp_alias] = :cpp
+ end
TypeFromShebang = /\b(?:ruby|perl|python|sh)\b/
@@ -190,6 +194,17 @@ class FileTypeTests < Test::Unit::TestCase
assert_not_equal :c, FileType['~/projects/blabla/c']
end
+ def test_cpp
+ assert_equal :cpp, FileType['test.c++']
+ assert_equal :cpp, FileType['test.cxx']
+ assert_equal :cpp, FileType['test.hh']
+ assert_equal :cpp, FileType['test.hpp']
+ assert_equal :cpp, FileType['test.cu']
+ assert_equal :cpp, FileType['test.C']
+ assert_not_equal :cpp, FileType['test.c']
+ assert_not_equal :cpp, FileType['test.h']
+ end
+
def test_html
assert_equal :html, FileType['test.htm']
assert_equal :xhtml, FileType['test.xhtml']