ENH: Fix INSERT to allow inserting to empty list

This commit is contained in:
Andy Cedilnik 2006-05-15 10:14:16 -04:00
parent cb2a9be622
commit ed1ea24cef
2 changed files with 23 additions and 16 deletions

View File

@ -205,14 +205,16 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
// expand the variable
int item = atoi(args[2].c_str());
std::vector<std::string> varArgsExpanded;
if ( !this->GetList(varArgsExpanded, listName.c_str()) && (item > 0 || item < -1))
if ( !this->GetList(varArgsExpanded, listName.c_str()) && item != 0)
{
cmOStringStream str;
str << "index: " << item << " out of range (-1, 0)";
str << "index: " << item << " out of range (0, 0)";
this->SetError(str.str().c_str());
return false;
}
if ( varArgsExpanded.size() != 0 )
{
size_t nitem = varArgsExpanded.size();
if ( item < 0 )
{
@ -223,10 +225,11 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
cmOStringStream str;
str << "index: " << item << " out of range (-"
<< varArgsExpanded.size() << ", "
<< varArgsExpanded.size()-1 << ")";
<< (varArgsExpanded.size() == 0?0:(varArgsExpanded.size()-1)) << ")";
this->SetError(str.str().c_str());
return false;
}
}
size_t cc;
size_t cnt = 0;
for ( cc = 3; cc < args.size(); ++ cc )

View File

@ -1,6 +1,6 @@
MACRO(TEST command expected)
IF("x${result}" STREQUAL "x${expected}")
MESSAGE("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
#MESSAGE("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
ELSE("x${result}" STREQUAL "x${expected}")
MESSAGE(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
ENDIF("x${result}" STREQUAL "x${expected}")
@ -41,7 +41,11 @@ TEST("APPEND result brad" "andy;brad")
LIST(APPEND "nonexiting_list3" brad)
SET(result "${nonexiting_list3}")
TEST("APPEND \"nonexiting_list1\" brad" "brad")
TEST("APPEND \"nonexiting_list3\" brad" "brad")
LIST(INSERT "nonexiting_list4" 0 andy bill brad ken)
SET(result "${nonexiting_list4}")
TEST("APPEND \"nonexiting_list4\" andy bill brad ken" "andy;bill;brad;ken")
SET(result andy brad)
LIST(INSERT result -1 bill ken)