Exemple #1
0
    def test_multiple_line_comments_at_the_start_of_invocation(self):
        args = arguments().add(newlines(1)) \
            .add(line_ending('# first line', 1)) \
            .add(line_ending('# second line', 1)) \
            .add(unquoted_argument('TARGET')) \
            .add(newlines(1))

        root = file().add(command_invocation('add_custom_target(', args))

        expected_formatting = """add_custom_target(
  # first line
  # second line
  TARGET
)"""
        self.assertFormatting(expected_formatting, root)
Exemple #2
0
    def test_splitting_long_line_with_multiple_arguments_and_properties(self):
        self.settings['line_length'] = 30
        self.settings['closing_parentheses_in_newline_when_split'] = True

        args = arguments().add(unquoted_argument('abcd')) \
            .add(spaces('    ')) \
            .add(line_ending('# comment', 1)) \
            .add(unquoted_argument('some_target')) \
            .add(spaces('    ')) \
            .add(unquoted_argument('PROPERTIES')) \
            .add(spaces('    ')) \
            .add(unquoted_argument('TARGET')) \
            .add(spaces('    ')) \
            .add(unquoted_argument('def')) \
            .add(spaces('    ')) \
            .add(unquoted_argument('TARGET')) \
            .add(spaces('    ')) \
            .add(unquoted_argument('def'))

        root = file().add(command_invocation('some_name(', args))

        expected_formatting = """some_name(abcd # comment
  some_target
  PROPERTIES
    TARGET
      def
    TARGET
      def
)"""
        self.assertFormatting(expected_formatting, root)
Exemple #3
0
    def test_multiple_line_comments_before_value(self):
        args = arguments().add(unquoted_argument('abc')) \
            .add(spaces('    ')) \
            .add(unquoted_argument('TARGET')) \
            .add(newlines(1)) \
            .add(line_ending('# first line', 1)) \
            .add(line_ending('# second line', 1)) \
            .add(unquoted_argument('${PROJECT_NAME}')) \
            .add(newlines(1))

        root = file().add(command_invocation('add_custom_target(', args))

        expected_formatting = """add_custom_target(abc
  TARGET
    # first line
    # second line
    ${PROJECT_NAME}
)"""
        self.assertFormatting(expected_formatting, root)
Exemple #4
0
    def test_special_handling_of_set_property_with_line_comments(self):
        self.settings['keyword_and_single_value_in_one_line'] = False
        self.settings['line_length'] = 5

        args = arguments().add(newlines(1)) \
            .add(unquoted_argument('GLOBAL')) \
            .add(newlines(1)) \
            .add(unquoted_argument('PROPERTY')) \
            .add(spaces('    ')) \
            .add(line_ending('# oh', 1)) \
            .add(unquoted_argument('CONFIGURATION_MSVC_RELEASE_SECURE_PREPARE')) \
            .add(spaces('    ')) \
            .add(line_ending('# oh', 1)) \
            .add(unquoted_argument('FALSE')) \
            .add(newlines(1))

        root = file().add(command_invocation('set_property(', args))

        expected_formatting = """set_property(
  GLOBAL PROPERTY # oh
    CONFIGURATION_MSVC_RELEASE_SECURE_PREPARE # oh
      FALSE
)"""
        self.assertFormatting(expected_formatting, root)
Exemple #5
0
    def test_invocation_splitting_with_line_comments(self):
        self.settings['line_length'] = 5
        args = arguments().add(unquoted_argument('abc')) \
            .add(spaces('    ')) \
            .add(line_ending('# comment', 1)) \
            .add(unquoted_argument('TARGET')) \
            .add(spaces('    ')) \
            .add(unquoted_argument('def'))

        root = file().add(command_invocation('function(', args))

        expected_formatting = """function(abc # comment
  TARGET
    def)"""

        self.assertFormatting(expected_formatting, root)
Exemple #6
0
    def test_invocation_when_keyword_and_single_values_keep_in_single_line_comments_case_at_the_end(
            self):
        self.settings['keyword_and_single_value_in_one_line'] = True
        args = arguments().add(newlines(1)) \
            .add(unquoted_argument('FILES')) \
            .add(spaces('    ')) \
            .add(unquoted_argument('file.cpp')) \
            .add(spaces('    ')) \
            .add(line_ending('# comment', 1))

        root = file().add(command_invocation('install(', args))

        expected_formatting = """install(
  FILES file.cpp # comment
)"""
        self.assertFormatting(expected_formatting, root)
Exemple #7
0
    def test_splitting_only_after_logical_operations_comments_excluded(self):
        self.settings['condition_splitting_move_and_or_to_newline'] = False
        self.settings['line_length'] = 10

        args = arguments() \
            .add(unquoted_argument('CMAKE_C_COMPILER_ID')).add(spaces(' ')) \
            .add(unquoted_argument('STREQUAL')).add(spaces(' ')) \
            .add(quoted_argument('GNU')).add(spaces(' ')) \
            .add(unquoted_argument('AND')).add(spaces(' ')) \
            .add(line_ending('# a comment', 1)) \
            .add(unquoted_argument('CMAKE_CXX_COMPILER_ID')).add(spaces(' ')) \
            .add(unquoted_argument('STREQUAL')).add(spaces(' ')) \
            .add(quoted_argument('GNU'))

        expected_formatting = """if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND # a comment
    CMAKE_CXX_COMPILER_ID STREQUAL "GNU")"""
        self.assertConditionFormatting(expected_formatting, args)
Exemple #8
0
    def test_command_with_line_comment(self):
        command = """add_test(
    NAME # a name
    CONFIGURATIONS)"""

        expected_args = arguments() \
            .add(newlines(1)) \
            .add(spaces('    ')) \
            .add(unquoted_argument('NAME')) \
            .add(spaces(' ')) \
            .add(line_ending('# a name', 1)) \
            .add(spaces('    ')) \
            .add(unquoted_argument('CONFIGURATIONS'))

        expected_parsed_structure = file().add(command_invocation('add_test(', expected_args))

        self.assertReprEqual(expected_parsed_structure, self.parser.parse(command))
Exemple #9
0
    def test_function_declaration_should_indent_correctly_within_its_scope(
            self):
        function_with_invocation_in_second_line = file() \
            .add(command_invocation('function(')) \
            .add(newlines(1)) \
            .add(line_ending('# comment', 1)) \
            .add(command_invocation('test(')) \
            .add(newlines(1)) \
            .add(command_invocation('endfunction(')) \
            .add(newlines(1)) \
            .add(command_invocation('test2('))
        expected_formatting = """function()
  # comment
  test()
endfunction()
test2()"""
        self.assertFormatting(expected_formatting,
                              function_with_invocation_in_second_line)
Exemple #10
0
    def test_invocation_when_keyword_and_single_values_keep_in_single_line_comments_case_in_the_middle(
            self):
        self.settings['keyword_and_single_value_in_one_line'] = True
        args = arguments().add(newlines(1)) \
            .add(unquoted_argument('DESTINATION')) \
            .add(spaces('    ')) \
            .add(quoted_argument('include/folder')) \
            .add(spaces('    ')) \
            .add(line_ending('# comment', 1)) \
            .add(unquoted_argument('NAMESPACE')) \
            .add(spaces('    ')) \
            .add(unquoted_argument('unofficial::graphicsmagick::')) \
            .add(newlines(1))

        root = file().add(command_invocation('install(', args))

        expected_formatting = """install(
  DESTINATION "include/folder" # comment
  NAMESPACE unofficial::graphicsmagick::
)"""
        self.assertFormatting(expected_formatting, root)
Exemple #11
0
 def test_command_invocation_should_be_by_default_lowercase(self):
     invocation = file() \
         .add(command_invocation('abc(')) \
         .add(spaces('   \t')) \
         .add(line_ending('# a comment', 1))
     self.assertFormatting('abc() # a comment\n', invocation)
Exemple #12
0
    def test_should_parse_line_comments(self):
        comment = '# cdaew9u32#$#@%#232cd a2o#@$@!'
        root = file() \
            .add(line_ending(comment, 1))

        self.assertReprEqual(root, self.parser.parse(comment + '\n'))
Exemple #13
0
    def test_should_handle_empty_comment(self):
        comment = '#'
        root = file().add(line_ending(comment, 2))

        self.assertReprEqual(root, self.parser.parse(comment + '\n\n'))