def test_always_wrap(self): self.source_str = """\ foo(nonkwarg_a HEADERS a.h SOURCES a.cc DEPENDS foo) """ with self.subTest(always_wrap=False): # assert_format(self, self.source_str) pass self.config.always_wrap = ['foo'] with self.subTest(always_wrap=True): assert_format( self, self.source_str, """\ foo(nonkwarg_a HEADERS a.h SOURCES a.cc DEPENDS foo) """)
def test_command_case(self): with self.subTest(): assert_format(self, """\ FOO(bar baz) """, """\ foo(bar baz) """) config_dict = self.config.as_dict() config_dict['command_case'] = 'upper' self.config = configuration.Configuration(**config_dict) with self.subTest(): assert_format(self, """\ foo(bar baz) """, """\ FOO(bar baz) """) config_dict = self.config.as_dict() config_dict['command_case'] = 'unchanged' self.config = configuration.Configuration(**config_dict) with self.subTest(): assert_format(self, """\ FoO(bar baz) """, """\ FoO(bar baz) """)
def test_keyword_case(self): config_dict = self.config.as_dict() config_dict['keyword_case'] = 'upper' self.config = configuration.Configuration(**config_dict) with self.subTest(): assert_format(self, """\ foo(bar baz) """, """\ foo(BAR BAZ) """) config_dict = self.config.as_dict() config_dict['keyword_case'] = 'lower' self.config = configuration.Configuration(**config_dict) with self.subTest(): assert_format(self, """\ foo(bar baz) """, """\ foo(bar baz) """) config_dict = self.config.as_dict() config_dict['command_case'] = 'unchanged' self.config = configuration.Configuration(**config_dict) with self.subTest(): assert_format(self, """\ foo(BaR bAz) """, """\ foo(bar baz) """)
def test_preserve_separator(self): self.source_str = """\ # -------------------- # This is some # text that I expect # to reflow # -------------------- """ self.expect_format = """\ # -------------------- # This is some text that I expect to reflow # -------------------- """ with self.subTest(sub="a"): assert_format(self, self.source_str, self.expect_format) self.source_str = """\ # !@#$^&*!@#$%^&*!@#$%^&*!@#$%^&* # This is some # text that I expect # to reflow # !@#$^&*!@#$%^&*!@#$%^&*!@#$%^&* """ self.expect_format = """\ # !@#$^&*!@#$%^&*!@#$%^&*!@#$%^&* # This is some text that I expect to reflow # !@#$^&*!@#$%^&*!@#$%^&*!@#$%^&* """ with self.subTest(sub="b"): assert_format(self, self.source_str, self.expect_format) self.source_str = """\ # ----Not Supported---- # This is some # text that I expect # to reflow # ----Not Supported---- """ self.expect_format = """\ # ----Not Supported---- # This is some text that I expect to reflow # ----Not Supported---- """ with self.subTest(sub="c"): assert_format(self, self.source_str, self.expect_format)
def test_arg_just_fits(self): """ Ensure that if an argument *just* fits that it isn't superfluously wrapped """ self.source_str = """\ message(FATAL_ERROR "81 character line ----------------------------------------") """ self.expect_format = """\ message( FATAL_ERROR "81 character line ----------------------------------------") """ with self.subTest(): assert_format(self, self.source_str, self.expect_format) self.source_str = """\ message(FATAL_ERROR "100 character line ----------------------------------------------------------" ) # Closing parenthesis is indented one space! """ self.expect_format = """\ message( FATAL_ERROR "100 character line ----------------------------------------------------------" ) # Closing parenthesis is indented one space! """ with self.subTest(): assert_format(self, self.source_str, self.expect_format) self.source_str = """\ message( "100 character line ----------------------------------------------------------------------" ) # Closing parenthesis is indented one space! """ self.expect_format = """\ message( "100 character line ----------------------------------------------------------------------" ) # Closing parenthesis is indented one space! """ with self.subTest(): assert_format(self, self.source_str, self.expect_format) self.source_str = self.expect_format = None
def test_config_hashruler_minlength(self): # make sure changing hashruler_min_length works correctly # self.config.enable_markup = False for min_width in {3, 5, 7, 9}: self.config.markup.hashruler_min_length = min_width # NOTE(josh): these tests use short rulers that wont be picked up by # the default pattern self.config.markup.ruler_pattern = (r'#{%d}#*' % (min_width - 1)) just_shy = '#' * (min_width - 1) just_right = '#' * min_width longer = '#' * (min_width + 2) full_line = '#' * (self.config.format.line_width - 2) assert_format( self, """ # A comment: min_width={min_width}, just_shy {just_shy} """.format(min_width=min_width, just_shy=just_shy), """\ # A comment: min_width={min_width}, just_shy # """.format(min_width=min_width)) assert_format( self, """ # A comment: min_width={min_width}, just_right {just_right} """.format(min_width=min_width, just_right=just_right), """\ # A comment: min_width={min_width}, just_right # {full_line} """.format(min_width=min_width, full_line=full_line)) assert_format( self, """ # A comment: min_width={min_width}, longer {longer} """.format(min_width=min_width, longer=longer), """\ # A comment: min_width={min_width}, longer # {full_line} """.format(min_width=min_width, full_line=full_line))
def test_comment_hashrulers(self): self.config.line_width = 74 with self.subTest(): assert_format( self, """ ################## # This comment has a long block before it. ############# """, """\ # ######################################################################## # This comment has a long block before it. # ######################################################################## """) with self.subTest(): assert_format( self, """ ############################################### # This is a section in the CMakeLists.txt file. ############ # This stuff below here # should get re-flowed like # normal comments. Across multiple # lines and # beyond. """, """\ # ######################################################################## # This is a section in the CMakeLists.txt file. # ######################################################################## # This stuff below here should get re-flowed like normal comments. Across # multiple lines and beyond. """) # verify the original behavior is as described (they truncate to one #) self.config.hashruler_min_length = 1000 with self.subTest(): assert_format( self, """ ########################################################################## # This comment has a long block before it. ########################################################################## """, """\ # # This comment has a long block before it. # """) with self.subTest(): assert_format( self, """ ########################################################################## # This is a section in the CMakeLists.txt file. ########################################################################## # This stuff below here # should get re-flowed like # normal comments. Across multiple # lines and # beyond. """, """\ # # This is a section in the CMakeLists.txt file. # # This stuff below here should get re-flowed like normal comments. Across # multiple lines and beyond. """) # make sure changing hashruler_min_length works correctly # self.config.enable_markup = False for min_width in {3, 5, 7, 9}: self.config.hashruler_min_length = min_width # NOTE(josh): these tests use short rulers that wont be picked up by # the default pattern self.config.ruler_pattern = (r'#{%d}#*' % (min_width - 1)) just_shy = '#' * (min_width - 1) just_right = '#' * min_width longer = '#' * (min_width + 2) full_line = '#' * (self.config.line_width - 2) assert_format( self, """ # A comment: min_width={min_width}, just_shy {just_shy} """.format(min_width=min_width, just_shy=just_shy), """\ # A comment: min_width={min_width}, just_shy # """.format(min_width=min_width)) assert_format( self, """ # A comment: min_width={min_width}, just_right {just_right} """.format(min_width=min_width, just_right=just_right), """\ # A comment: min_width={min_width}, just_right # {full_line} """.format(min_width=min_width, full_line=full_line)) assert_format( self, """ # A comment: min_width={min_width}, longer {longer} """.format(min_width=min_width, longer=longer), """\ # A comment: min_width={min_width}, longer # {full_line} """.format(min_width=min_width, full_line=full_line))
def test_dangle_parens(self): self.config.dangle_parens = True self.config.max_subargs_per_line = 6 with self.subTest(): assert_format( self, """\ foo_command() foo_command(arg1) foo_command(arg1) # comment """, """\ foo_command() foo_command(arg1) foo_command(arg1) # comment """) with self.subTest(): assert_format( self, """\ some_long_command_name(longargname longargname longargname longargname longargname) """, """\ some_long_command_name( longargname longargname longargname longargname longargname ) """) with self.subTest(): assert_format( self, """\ if(foo) some_long_command_name(longargname longargname longargname longargname longargname) endif() """, """\ if(foo) some_long_command_name( longargname longargname longargname longargname longargname ) endif() """) with self.subTest(): assert_format( self, """\ some_long_command_name(longargname longargname longargname longargname longargname longargname longargname longargname) """, """\ some_long_command_name( longargname longargname longargname longargname longargname longargname longargname longargname ) """) with self.subTest(): assert_format( self, """\ target_include_directories(target INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>) """, """\ target_include_directories( target INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/> ) """)