コード例 #1
0
 def __reindent_property_name(self, args: list, start_index: int) -> Tuple[list, int]:
     for i in range(start_index + 1, len(args)):
         if self.__is_argument(args[i]):
             if not args[i].startswith(Tokens.reindent(1)):
                 args[i] = Tokens.reindent(1) + args[i]
             return args, i
     return args, 0
コード例 #2
0
 def test_is_command_keyword(self):
     self.assertTrue(KeywordVerifier.is_command_keyword('COMMAND'))
     self.assertTrue(
         KeywordVerifier.is_command_keyword(Tokens.reindent(1) + 'COMMAND'))
     self.assertTrue(
         KeywordVerifier.is_command_keyword(Tokens.reindent(1) + 'ARGS'))
     self.assertFalse(KeywordVerifier.is_command_keyword('CMD'))
     self.assertFalse(
         KeywordVerifier.is_command_keyword(Tokens.reindent(2) + 'COMMAND'))
コード例 #3
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'))
コード例 #4
0
 def test_double_keywords(self):
     self.assertTrue(
         self.verify.is_double_keyword(
             Tokens.reindent(1) + 'RUNTIME', 'DESTINATION'))
     self.assertTrue(
         self.verify.is_double_keyword('ARCHIVE',
                                       Tokens.reindent(1) + 'DESTINATION'))
     self.assertTrue(self.verify.is_double_keyword('LIBRARY',
                                                   'DESTINATION'))
     self.assertFalse(self.verify.is_double_keyword('OUTPUT',
                                                    'DESTINATION'))
     self.assertFalse(self.verify.is_double_keyword('LIBRARY', 'OUTPUT'))
コード例 #5
0
 def test_whether_token_is_first_class_keyword(self):
     self.assertTrue(self.verify.is_first_class_keyword('PROPERTY'))
     self.assertTrue(self.verify.is_first_class_keyword('PROPERTIES'))
     self.assertTrue(
         self.verify.is_first_class_keyword(
             Tokens.reindent(1) + 'PROPERTY'))
     self.assertFalse(self.verify.is_first_class_keyword('PROPERTY2'))
     self.assertFalse(self.verify.is_first_class_keyword('proPERTY'))
コード例 #6
0
    def test_unquoted_arguments_with_uppercase_letters_only_are_keywords(self):
        self.settings['unquoted_uppercase_as_keyword'] = True
        self.verify = KeywordVerifier(self.settings)

        self.assertTrue(self.verify.is_keyword('OTHER'))
        self.assertTrue(self.verify.is_keyword(Tokens.reindent(1) + 'OTHER'))
        self.assertTrue(self.verify.is_keyword('WITH_SEPARATION'))

        self.assertFalse(self.verify.is_keyword('"$OTHER"'))
        self.assertFalse(self.verify.is_keyword('SOMeARG'))
        self.assertFalse(self.verify.is_keyword('a_ARGUMENT'))
        self.assertFalse(self.verify.is_keyword('NOT_'))
        self.assertFalse(self.verify.is_keyword('_SOME'))
コード例 #7
0
 def test_ignore_reindent_tokens(self):
     self.assertEqual(0, self.calculator.calculate(Tokens.reindent(3)))
     self.assertEqual(14, self.calculator.calculate(f'\tsome{Tokens.reindent(99)}\tso'))
コード例 #8
0
 def __call__(self, data: list) -> str:
     formatted = ''.join(data)
     if '\n' in data[1]:
         formatted = Tokens.reindent(99) + formatted
     return formatted
コード例 #9
0
 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
コード例 #10
0
 def is_property(self, data: str) -> bool:
     data = data.replace(Tokens.reindent(1), '')
     return data in KeywordVerifier.__PROPERTIES["properties_full_names"] or \
            self.__is_property_regex_starting(data) or \
            self.__is_property_ending_with(data)
コード例 #11
0
 def is_command_keyword(data: str) -> bool:
     data = data.replace(Tokens.reindent(1), '')
     return data == 'COMMAND' or data == 'ARGS'
コード例 #12
0
 def is_double_keyword(first: str, second: str) -> bool:
     first = first.replace(Tokens.reindent(1), '')
     second = second.replace(Tokens.reindent(1), '')
     return any(keyword.startswith(first) and keyword.endswith(second) \
                for keyword in KeywordVerifier.__PROPERTIES['double-keywords'])
コード例 #13
0
 def test_should_accept_keyword_when_on_the_list(self):
     self.assertTrue(self.verify.is_keyword('some'))
     self.assertTrue(self.verify.is_keyword(Tokens.reindent(1) + 'some'))
     self.assertFalse(self.verify.is_keyword('some2'))
     self.assertFalse(self.verify.is_keyword('${some}'))
コード例 #14
0
 def __format(self, data):
     if self.__state['has_first_class_keyword']:
         return Tokens.reindent(3) + data
     if self.__state['keyword_argument']:
         return Tokens.reindent(2) + data
     return Tokens.reindent(1) + data
コード例 #15
0
 def __format_data(self, data: str) -> str:
     if self.__keyword_argument_already_found and self.__is_reindent_needed(
             data):
         return Tokens.reindent(1) + data
     return data
コード例 #16
0
 def test_reindent_token_generation_and_matching(self):
     self.assertRegex(Tokens.reindent(1), Tokens.get_reindent_regex())
     self.assertRegex(Tokens.reindent(9), Tokens.get_reindent_regex())
     self.assertRegex(Tokens.reindent(), Tokens.get_reindent_regex())
コード例 #17
0
 def test_cmake_properties_with_reindent_token(self):
     self.assertTrue(
         self.verify.is_property(Tokens.reindent(1) + 'LINK_DIRECTORIES'))
コード例 #18
0
 def __cleanup_reindent_all(data: str) -> str:
     return re.sub('[ \t]*' + Tokens.reindent(), '', data)
コード例 #19
0
 def is_first_class_keyword(data: str) -> bool:
     data = data.replace(Tokens.reindent(1), '')
     return data in KeywordVerifier.__FIRST_CLASS_KEYWORDS
コード例 #20
0
 def is_keyword(self, data: str) -> bool:
     data = data.replace(Tokens.reindent(1), '')
     return self.__is_one_of_defined_keywords(data) or \
            self.__should_be_handled_as_keyword(data) or \
            self.is_first_class_keyword(data) or \
            self.__is_keyword_in_cmake(data)