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_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))
def test_parse_set_normal_variable_using_other_variable_in_quotes(self): givenAst = ast.Ast() result = givenAst.parse("set(TabsPls_Source \"${other_var}\")") expected_result = ast.SetNormalVariable( "TabsPls_Source", ast.CMakeStringList([ast.VariableUse("other_var")])) self.assertTrue(list(result)[0].is_same(expected_result))
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)