Skip to content

Commit

Permalink
Add hasRepoVarsEmbedded test for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandres committed Dec 15, 2023
1 parent 1faba2a commit 82d408f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/repo/RepoVariables_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void helperGenRepVarExpandResults()
}
}

void RepVarExpandTest( const std::string & string_r, const std::string & allUndef_r, const std::string & allDef_r )
void RepVarExpandTest( const std::string & string_r, const std::string & allUndef_r, const std::string & allDef_r, bool hasVars=true )
{
std::map<std::string,std::string> vartable;
bool varsoff = true;
Expand All @@ -140,17 +140,18 @@ void RepVarExpandTest( const std::string & string_r, const std::string & allUnde
return &val;
};

BOOST_CHECK_EQUAL( repo::hasRepoVarsEmbedded( string_r ), hasVars );
varsoff = true;
BOOST_CHECK_EQUAL( repo::RepoVarExpand()( string_r, varLookup ), allUndef_r );
varsoff = false;
BOOST_CHECK_EQUAL( repo::RepoVarExpand()( string_r, varLookup ), allDef_r );
}

BOOST_AUTO_TEST_CASE(RepVarExpand)
{ // ( STRING , REPLACED_all_vars_undef , REPLACED_all_vars_defined )
RepVarExpandTest( "" , "" , "" );
RepVarExpandTest( "$" , "$" , "$" );
RepVarExpandTest( "$${}" , "$${}" , "$${}" );
{ // ( STRING , REPLACED_all_vars_undef , REPLACED_all_vars_defined STRING has Vars)
RepVarExpandTest( "" , "" , "" , false );
RepVarExpandTest( "$" , "$" , "$" , false );
RepVarExpandTest( "$${}" , "$${}" , "$${}" , false );
RepVarExpandTest( "$_:" , "$_:" , "[_]:" );
RepVarExpandTest( "$_A:" , "$_A:" , "[_A]:" );
RepVarExpandTest( "$_A_:" , "$_A_:" , "[_A_]:" );
Expand All @@ -163,7 +164,7 @@ BOOST_AUTO_TEST_CASE(RepVarExpand)
RepVarExpandTest( "${C:+a\\${B\\}ba}" , "" , "a${B}ba" );
RepVarExpandTest( "${C:+a\\${B}ba}" , "ba}" , "a${Bba}" );
RepVarExpandTest( "${C:-a$Bba}" , "a$Bba" , "[C]" );
RepVarExpandTest( "${_A_B\\}" , "${_A_B\\}" , "${_A_B\\}" );
RepVarExpandTest( "${_A_B\\}" , "${_A_B\\}" , "${_A_B\\}" , false );
RepVarExpandTest( "${_A_B}" , "${_A_B}" , "[_A_B]" );
RepVarExpandTest( "\\${_A_B}" , "\\${_A_B}" , "\\[_A_B]" );
RepVarExpandTest( "__${D:+\\$X--{${E:-==\\$X{o\\}==} }--}__\\${B}${}__", "__--}__\\${B}${}__" , "__$X--{[E] --}__\\[B]${}__" );
Expand Down
3 changes: 3 additions & 0 deletions zypp/repo/RepoVariables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ namespace zypp
} // namespace
///////////////////////////////////////////////////////////////////

bool hasRepoVarsEmbedded( const std::string & str_r )
{ return FindVar( str_r, 0 ).nextVar(); }

std::string RepoVarExpand::operator()( const std::string & value_r, VarRetriever varRetriever_r ) const
{ return expand( value_r, 0, varRetriever_r ); }

Expand Down
3 changes: 3 additions & 0 deletions zypp/repo/RepoVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace zypp
///////////////////////////////////////////////////////////////////
namespace repo
{
/** Return whether \a str_r has embedded variables. */
bool hasRepoVarsEmbedded( const std::string & str_r );

///////////////////////////////////////////////////////////////////
/// \class RepoVarExpand
/// \brief Functor expanding repo variables in a string
Expand Down

0 comments on commit 82d408f

Please sign in to comment.