Detect C++ language from all C++ file extensions
This commit is contained in:
parent
9b2eabe568
commit
540557e998
15 changed files with 21 additions and 2 deletions
0
tests/samples/codefiles/c_and_cxx/cpp.h
Normal file
0
tests/samples/codefiles/c_and_cxx/cpp.h
Normal file
0
tests/samples/codefiles/c_and_cxx/empty.h
Normal file
0
tests/samples/codefiles/c_and_cxx/empty.h
Normal file
0
tests/samples/codefiles/c_and_cxx/empty.m
Normal file
0
tests/samples/codefiles/c_and_cxx/empty.m
Normal file
0
tests/samples/codefiles/c_and_cxx/empty.mm
Normal file
0
tests/samples/codefiles/c_and_cxx/empty.mm
Normal file
0
tests/samples/codefiles/c_and_cxx/foo.cxx
Normal file
0
tests/samples/codefiles/c_and_cxx/foo.cxx
Normal file
8
tests/samples/codefiles/c_and_cxx/non_empty.cxx
Normal file
8
tests/samples/codefiles/c_and_cxx/non_empty.cxx
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <openssl/rand.h>
|
||||||
|
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
printf("Hello World\n");
|
||||||
|
return 0;
|
||||||
|
}
|
0
tests/samples/codefiles/c_and_cxx/non_empty.h
Normal file
0
tests/samples/codefiles/c_and_cxx/non_empty.h
Normal file
0
tests/samples/codefiles/c_and_cxx/objective-c.h
Normal file
0
tests/samples/codefiles/c_and_cxx/objective-c.h
Normal file
0
tests/samples/codefiles/c_and_cxx/objective-c.m
Normal file
0
tests/samples/codefiles/c_and_cxx/objective-c.m
Normal file
0
tests/samples/codefiles/c_and_cxx/objective-cpp.h
Normal file
0
tests/samples/codefiles/c_and_cxx/objective-cpp.h
Normal file
0
tests/samples/codefiles/c_and_cxx/objective-cpp.mm
Normal file
0
tests/samples/codefiles/c_and_cxx/objective-cpp.mm
Normal file
0
tests/samples/codefiles/c_and_cxx/see.c
Normal file
0
tests/samples/codefiles/c_and_cxx/see.c
Normal file
0
tests/samples/codefiles/c_and_cxx/see.h
Normal file
0
tests/samples/codefiles/c_and_cxx/see.h
Normal file
|
@ -69,6 +69,12 @@ class LanguagesTestCase(utils.TestCase):
|
||||||
entity='c_and_cpp/cpp.h',
|
entity='c_and_cpp/cpp.h',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_cpp_language_detected_for_header_with_c_and_cxx_files_in_folder(self):
|
||||||
|
self.shared(
|
||||||
|
expected_language='C++',
|
||||||
|
entity='c_and_cxx/cpp.h',
|
||||||
|
)
|
||||||
|
|
||||||
def test_c_not_detected_for_non_header_with_c_files_in_folder(self):
|
def test_c_not_detected_for_non_header_with_c_files_in_folder(self):
|
||||||
self.shared(
|
self.shared(
|
||||||
expected_language='Python',
|
expected_language='Python',
|
||||||
|
|
|
@ -25,6 +25,7 @@ from .packages.pygments.lexers import (
|
||||||
_fn_matches,
|
_fn_matches,
|
||||||
basename,
|
basename,
|
||||||
ClassNotFound,
|
ClassNotFound,
|
||||||
|
CppLexer,
|
||||||
find_lexer_class,
|
find_lexer_class,
|
||||||
get_lexer_by_name,
|
get_lexer_by_name,
|
||||||
)
|
)
|
||||||
|
@ -181,8 +182,12 @@ def get_language_from_extension(file_name):
|
||||||
return 'Objective-C++'
|
return 'Objective-C++'
|
||||||
|
|
||||||
available_extensions = extensions_in_same_folder(file_name)
|
available_extensions = extensions_in_same_folder(file_name)
|
||||||
if '.cpp' in available_extensions:
|
|
||||||
return 'C++'
|
for ext in CppLexer.filenames:
|
||||||
|
ext = ext.lstrip('*')
|
||||||
|
if ext in available_extensions:
|
||||||
|
return 'C++'
|
||||||
|
|
||||||
if '.c' in available_extensions:
|
if '.c' in available_extensions:
|
||||||
return 'C'
|
return 'C'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue