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'))
def test_matching_spacing_tokens(self): self.assertFalse(Tokens.is_line_comment('')) self.assertTrue(Tokens.is_spacing_token(' ')) self.assertTrue(Tokens.is_spacing_token('\t ')) self.assertTrue(Tokens.is_spacing_token('\t \n')) self.assertTrue(Tokens.is_spacing_token(f'\t {Tokens.remove_spaces()}\n')) self.assertFalse(Tokens.is_spacing_token('\t d')) self.assertFalse(Tokens.is_spacing_token(f'\t {Tokens.reindent(1)}'))
def __merge_line_comments_with_whitespaces_before(args: List[str]) -> list: merged = [] for i in range(len(args) - 1): if Tokens.is_spacing_token(args[i]) and Tokens.is_line_comment( args[i + 1]): args[i + 1] = args[i] + args[i + 1] else: merged.append(args[i]) return merged + [args[-1]] if args else []
def __is_argument(data: str) -> bool: return not (Tokens.is_line_comment(data) or Tokens.is_spacing_token(data))
def __is_value_realignable(self, args, position): return not Tokens.is_line_comment(args[position + 2]) and \ self.__get_number_of_arguments(args, position) == 1
def __is_property_followed_by_name(args: list, i: int) -> bool: return KeywordVerifier.is_first_class_keyword(args[i]) and not Tokens.is_line_comment(args[i + 2])
def __is_last_element_newline(invocation: dict) -> bool: return Tokens.is_spacing_token(invocation['arguments'][-1]) or \ Tokens.is_line_comment(invocation['arguments'][-1])
def __reindent_all_previous_comments(args: list, start: int) -> None: for i in reversed(range(start)): if Tokens.is_line_comment(args[i]): args[i] = Tokens.reindent(1) + args[i] else: break