Improve C vs C++ vs Objective-C language detection
This commit is contained in:
parent
71920995bf
commit
12cd40aae2
7 changed files with 19 additions and 7 deletions
0
tests/samples/codefiles/c_and_cpp/cpp.h
Normal file
0
tests/samples/codefiles/c_and_cpp/cpp.h
Normal file
0
tests/samples/codefiles/c_and_cpp/objective-c.h
Normal file
0
tests/samples/codefiles/c_and_cpp/objective-c.h
Normal file
0
tests/samples/codefiles/c_and_cpp/objective-c.m
Normal file
0
tests/samples/codefiles/c_and_cpp/objective-c.m
Normal file
0
tests/samples/codefiles/c_and_cpp/objective-cpp.h
Normal file
0
tests/samples/codefiles/c_and_cpp/objective-cpp.h
Normal file
0
tests/samples/codefiles/c_and_cpp/objective-cpp.mm
Normal file
0
tests/samples/codefiles/c_and_cpp/objective-cpp.mm
Normal file
|
@ -65,7 +65,7 @@ class LanguagesTestCase(utils.TestCase):
|
||||||
def test_cpp_language_detected_for_header_with_c_and_cpp_files_in_folder(self):
|
def test_cpp_language_detected_for_header_with_c_and_cpp_files_in_folder(self):
|
||||||
self.shared(
|
self.shared(
|
||||||
expected_language='C++',
|
expected_language='C++',
|
||||||
entity='c_and_cpp/empty.h',
|
entity='c_and_cpp/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):
|
||||||
|
@ -80,12 +80,24 @@ class LanguagesTestCase(utils.TestCase):
|
||||||
entity='c_and_cpp/empty.m',
|
entity='c_and_cpp/empty.m',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_objectivec_language_detected_when_m_files_in_folder(self):
|
||||||
|
self.shared(
|
||||||
|
expected_language='Objective-C',
|
||||||
|
entity='c_and_cpp/objective-c.h',
|
||||||
|
)
|
||||||
|
|
||||||
def test_objectivecpp_language_detected_when_header_files_in_folder(self):
|
def test_objectivecpp_language_detected_when_header_files_in_folder(self):
|
||||||
self.shared(
|
self.shared(
|
||||||
expected_language='Objective-C++',
|
expected_language='Objective-C++',
|
||||||
entity='c_and_cpp/empty.mm',
|
entity='c_and_cpp/empty.mm',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_objectivecpp_language_detected_when_m_files_in_folder(self):
|
||||||
|
self.shared(
|
||||||
|
expected_language='Objective-C++',
|
||||||
|
entity='c_and_cpp/objective-cpp.h',
|
||||||
|
)
|
||||||
|
|
||||||
def test_guess_language(self):
|
def test_guess_language(self):
|
||||||
with utils.mock.patch('wakatime.stats.smart_guess_lexer') as mock_guess_lexer:
|
with utils.mock.patch('wakatime.stats.smart_guess_lexer') as mock_guess_lexer:
|
||||||
mock_guess_lexer.return_value = None
|
mock_guess_lexer.return_value = None
|
||||||
|
|
|
@ -177,18 +177,18 @@ def get_language_from_extension(file_name):
|
||||||
if os.path.exists(u('{0}{1}').format(u(filepart), u('.c'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.C'))):
|
if os.path.exists(u('{0}{1}').format(u(filepart), u('.c'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.C'))):
|
||||||
return 'C'
|
return 'C'
|
||||||
|
|
||||||
available_extensions = extensions_in_same_folder(file_name)
|
|
||||||
if '.cpp' in available_extensions:
|
|
||||||
return 'C++'
|
|
||||||
if '.c' in available_extensions:
|
|
||||||
return 'C'
|
|
||||||
|
|
||||||
if os.path.exists(u('{0}{1}').format(u(filepart), u('.m'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.M'))):
|
if os.path.exists(u('{0}{1}').format(u(filepart), u('.m'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.M'))):
|
||||||
return 'Objective-C'
|
return 'Objective-C'
|
||||||
|
|
||||||
if os.path.exists(u('{0}{1}').format(u(filepart), u('.mm'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.MM'))):
|
if os.path.exists(u('{0}{1}').format(u(filepart), u('.mm'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.MM'))):
|
||||||
return 'Objective-C++'
|
return 'Objective-C++'
|
||||||
|
|
||||||
|
available_extensions = extensions_in_same_folder(file_name)
|
||||||
|
if '.cpp' in available_extensions:
|
||||||
|
return 'C++'
|
||||||
|
if '.c' in available_extensions:
|
||||||
|
return 'C'
|
||||||
|
|
||||||
if re.match(r'\.m$', extension, re.IGNORECASE) and (os.path.exists(u('{0}{1}').format(u(filepart), u('.h'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.H')))):
|
if re.match(r'\.m$', extension, re.IGNORECASE) and (os.path.exists(u('{0}{1}').format(u(filepart), u('.h'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.H')))):
|
||||||
return 'Objective-C'
|
return 'Objective-C'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue