Skip to content

Commit

Permalink
Merge pull request #391 from salman-javed-nz/master
Browse files Browse the repository at this point in the history
Fix parsing of C++14  ' separator with 0x and 0b
  • Loading branch information
terryyin authored Oct 7, 2024
2 parents c05b8e9 + c17ccbb commit 71fcb94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lizard_languages/code_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def _generate_tokens(source, add, flags=re.NOFLAG):
r"\/\*.*?\*\/" +
add +
r"|(?:\d+\')+\d+" +
r"|0x(?:[0-9A-Fa-f]+\')+[0-9A-Fa-f]+" +
r"|0b(?:[01]+\')+[01]+" +
r"|\w+" +
r"|\"(?:\\.|[^\"\\])*\"" +
r"|\'(?:\\.|[^\'\\])*?\'" +
Expand Down
14 changes: 14 additions & 0 deletions test/test_languages/testCAndCPP.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ def test_number_with_thousands_separator_since_cpp14(self):
self.assertEqual(1, len(result))
self.assertEqual(2, result[0].cyclomatic_complexity)

def test_hex_number_with_thousands_separator_since_cpp14(self):
result = get_cpp_function_list("""int fun(){
int a= 0x12ab'34cd; if(b) c; return 0xEF56'7890'1A2B;
}""")
self.assertEqual(1, len(result))
self.assertEqual(2, result[0].cyclomatic_complexity)

def test_bin_number_with_thousands_separator_since_cpp14(self):
result = get_cpp_function_list("""int fun(){
int a= 0b0101'1100; if(b) c; return 0b1111'0000'1100'1110;
}""")
self.assertEqual(1, len(result))
self.assertEqual(2, result[0].cyclomatic_complexity)

def test_function_with_no_param_omitted(self):
result = get_cpp_function_list("int fun(){}")
self.assertEqual(0, result[0].parameter_count)
Expand Down

0 comments on commit 71fcb94

Please sign in to comment.