def test_parse_quoted_list_item_containing_multiple_items(self): givenAst = ast.Ast() result = givenAst.parse("set(TabsPls_Source " \ + "\"anything can be put here, and it will be only one item, even with a ${variable}\"\n" + "main.cpp\n" \ + "${other_var}\n" \ + "\"${another_var_in_quotes}\"\n" \ + "#a comment that will be ignored\n" \ + '"a complete line with only text"\n' \ + ")" ) expected_result = ast.SetNormalVariable( "TabsPls_Source", ast.CMakeStringList([ ast.ListItemString( "\"anything can be put here, and it will be only one item, even with a ${variable}\"" ), ast.ListItemString("main.cpp"), ast.VariableUse("other_var"), ast.VariableUse("another_var_in_quotes"), ast.ListItemString('"a complete line with only text"') ])) self.assertTrue(list(result)[0].is_same(expected_result))
def test_parse_add_library(self): givenAst = ast.Ast() result = givenAst.parse("add_library(TabsPlsLib file.h file.cpp)") expected_result = ast.AddLibrary( "TabsPlsLib", ast.CMakeStringList( [ast.ListItemString("file.h"), ast.ListItemString("file.cpp")])) self.assertTrue(list(result)[0].is_same(expected_result))
def test_parse_add_library_with_type_and_flag(self): givenAst = ast.Ast() result = givenAst.parse( "add_library(TabsPlsLib STATIC EXCLUDE_FROM_ALL file.h file.cpp)") expected_result = ast.AddLibrary( "TabsPlsLib", ast.CMakeStringList( [ast.ListItemString("file.h"), ast.ListItemString("file.cpp")])) self.assertTrue(list(result)[0].is_same(expected_result))
def test_parse_set_normal_variable(self): givenAst = ast.Ast() result = givenAst.parse("set(TabsPls_Source main.cpp)") expected_result = ast.SetNormalVariable( "TabsPls_Source", ast.CMakeStringList([ast.ListItemString("main.cpp")])) self.assertTrue(list(result)[0].is_same(expected_result))
def test_add_empty_path_prefix_to_insert_action(self): given_insert_action = source_inserter.InsertAction(0, " header.h") path_provider = namedtuple("PathProvider", ["get_matched_reference_item"]) path_provider.get_matched_reference_item = lambda: ast.ListItemString( "other_header.h") source_inserter._add_path_prefix_to_insert_action( path_provider, given_insert_action) self.assertEqual(given_insert_action.content, " header.h")
def test_get_position_after_last_variable_use_list_item(self): given_cmake_string_list = ast.CMakeStringList([ ast.ListItemString("item1.cpp"), ast.VariableUse("Sources"), ast.VariableUseWithStartAndEndLocation( "Headers", 14, ast.VariableUseTerminator(22)) ]) self.assertEqual( source_inserter._get_position_after_last_list_item( given_cmake_string_list), 22)
def test_get_content_between_second_to_last_and_last_item_with_only_one_item( self): given_ast = ast.CMakeStringList([ast.ListItemString("file1.cpp")]) given_ast_empty = ast.CMakeStringList([]) self.assertRaises( whitespace_inserter.LessThanTwoItemsException, whitespace_inserter. get_content_between_second_to_last_and_last_item, "", given_ast) self.assertRaises( whitespace_inserter.LessThanTwoItemsException, whitespace_inserter. get_content_between_second_to_last_and_last_item, "", given_ast_empty)
def test_parse_quoted_list_item_containing_variable_use(self): givenAst = ast.Ast() result = givenAst.parse( "set(TabsPls_Source \"anything can be put here, and it will be only one item, even with a ${variable}\")" ) expected_result = ast.SetNormalVariable( "TabsPls_Source", ast.CMakeStringList([ ast.ListItemString( "\"anything can be put here, and it will be only one item, even with a ${variable}\"" ) ])) self.assertTrue(list(result)[0].is_same(expected_result))
def test_parse_add_executable_exclude_from_all_flag(self): givenAst = ast.Ast() result = givenAst.parse( "add_executable(TabsPls MACOSX_BUNDLE EXCLUDE_FROM_ALL ${TabsPls_Headers} ${TabsPls_Sources} main.cpp)" ) expected_result = ast.AddExecutable( "TabsPls", ast.CMakeStringList([ ast.VariableUse("TabsPls_Headers"), ast.VariableUse("TabsPls_Sources"), ast.ListItemString("main.cpp") ])) self.assertTrue(list(result)[0].is_same(expected_result))
def test_parse_add_executable_win32_flag(self): givenAst = ast.Ast() result = givenAst.parse( "add_executable(TabsPls WIN32 ${TabsPls_Headers} ${TabsPls_Sources} main.cpp)" ) expected_result = ast.AddExecutable( "TabsPls", ast.CMakeStringList([ ast.VariableUse("TabsPls_Headers"), ast.VariableUse("TabsPls_Sources"), ast.ListItemString("main.cpp") ])) self.assertTrue(list(result)[0].is_same(expected_result))