Exemple #1
0
 def test_matching_line_comment_tokens(self):
     self.assertTrue(Tokens.is_line_comment('# comment'))
     self.assertTrue(Tokens.is_line_comment('#comment'))
     self.assertTrue(Tokens.is_line_comment(Tokens.reindent(1) + '#comment'))
     self.assertTrue(Tokens.is_line_comment(Tokens.remove_spaces() + Tokens.reindent(1) + '#comment'))
     self.assertTrue(Tokens.is_line_comment('\t # something'))
     self.assertTrue(Tokens.is_line_comment('\t #'))
     self.assertFalse(Tokens.is_line_comment('_# not a comment'))
     self.assertFalse(Tokens.is_line_comment('comment'))
Exemple #2
0
 def __cleanup_whitespaces_at_line_ends(processed: str) -> str:
     return re.sub('[ \t]*' + Tokens.remove_spaces(), '', processed)
Exemple #3
0
 def test_ignore_remove_spaces_tokens(self):
     self.assertEqual(0, self.calculator.calculate(Tokens.remove_spaces()))
     self.assertEqual(4, self.calculator.calculate(f'piwo{Tokens.remove_spaces()}'))
Exemple #4
0
 def __format_newlines(self, number_of_newlines: int) -> str:
     return Tokens.remove_spaces() + '\n' * min(self.__settings['succeeding_newlines'], number_of_newlines)
Exemple #5
0
 def calculate(self, invocation: str) -> int:
     invocation = invocation.replace('\t',
                                     ' ' * self.__settings['tab_size'])
     invocation = re.sub(Tokens.get_reindent_regex(), '', invocation)
     invocation = re.sub(Tokens.remove_spaces(), '', invocation)
     return len(invocation)