ValueType: Added additional unit test (#4185)

Removed unnecessary library export

Backported from LCppC.
This commit is contained in:
PKEuS 2022-06-08 15:27:56 +02:00 committed by GitHub
parent d20ea41325
commit 898a3a25a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 3 deletions

View File

@ -1601,7 +1601,7 @@ const Library::SmartPointer* Library::detectSmartPointer(const Token* tok) const
return &it->second;
}
CPPCHECKLIB const Library::Container * getLibraryContainer(const Token * tok)
const Library::Container * getLibraryContainer(const Token * tok)
{
if (!tok)
return nullptr;

View File

@ -465,7 +465,8 @@ private:
TEST_CASE(executableScopeWithUnknownFunction);
TEST_CASE(valuetype);
TEST_CASE(valueType1);
TEST_CASE(valueType2);
TEST_CASE(variadic1); // #7453
TEST_CASE(variadic2); // #7649
@ -7331,7 +7332,7 @@ private:
return tok->valueType() ? tok->valueType()->str() : std::string();
}
void valuetype() {
void valueType1() {
// stringification
ASSERT_EQUALS("", ValueType().str());
@ -7784,6 +7785,49 @@ private:
}
}
void valueType2() {
GET_SYMBOL_DB("int i;\n"
"bool b;\n"
"Unknown u;\n"
"std::string s;\n"
"std::vector<int> v;\n"
"std::map<int, void*>::const_iterator it;\n"
"void* p;\n"
"\n"
"void f() {\n"
" func(i, b, u, s, v, it, p);\n"
"}");
const Token* tok = tokenizer.tokens();
for (int i = 0; i < 2; i++) {
tok = Token::findsimplematch(tok, "i");
ASSERT(tok && tok->valueType());
ASSERT_EQUALS("signed int", tok->valueType()->str());
tok = Token::findsimplematch(tok, "b");
ASSERT(tok && tok->valueType());
ASSERT_EQUALS("bool", tok->valueType()->str());
tok = Token::findsimplematch(tok, "u");
ASSERT(tok && !tok->valueType());
tok = Token::findsimplematch(tok, "s");
ASSERT(tok && tok->valueType());
ASSERT_EQUALS("container(std :: string|wstring|u16string|u32string)", tok->valueType()->str());
ASSERT(tok->valueType()->container && tok->valueType()->container->stdStringLike);
tok = Token::findsimplematch(tok, "v");
ASSERT(tok && tok->valueType());
ASSERT_EQUALS("container(std :: vector <)", tok->valueType()->str());
ASSERT(tok->valueType()->container && !tok->valueType()->container->stdStringLike);
tok = Token::findsimplematch(tok, "it");
ASSERT(tok && tok->valueType());
ASSERT_EQUALS("iterator(std :: map|unordered_map <)", tok->valueType()->str());
}
}
void variadic1() { // #7453
{
GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"