TestSimplifyUsing; code cleanup

This commit is contained in:
Daniel Marjamäki 2021-08-21 10:39:53 +02:00
parent ca50dea97d
commit e4f0096255
1 changed files with 59 additions and 59 deletions

View File

@ -95,7 +95,7 @@ private:
TEST_CASE(scopeInfo2); TEST_CASE(scopeInfo2);
} }
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) { std::string tok(const char code[], Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
errout.str(""); errout.str("");
settings0.certainty.enable(Certainty::inconclusive); settings0.certainty.enable(Certainty::inconclusive);
@ -106,7 +106,7 @@ private:
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
return tokenizer.tokens()->stringifyList(nullptr, !simplify); return tokenizer.tokens()->stringifyList(nullptr);
} }
void simplifyUsing1() { void simplifyUsing1() {
@ -137,7 +137,7 @@ private:
"a . foo ( ) ; " "a . foo ( ) ; "
"wchar_t c ; c = 0 ; " "wchar_t c ; c = 0 ; "
"}"; "}";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing2() { void simplifyUsing2() {
@ -207,7 +207,7 @@ private:
"unsigned int uvar ; uvar = 2 ; " "unsigned int uvar ; uvar = 2 ; "
"return uvar / ivar ; " "return uvar / ivar ; "
"}"; "}";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing5() { void simplifyUsing5() {
@ -224,7 +224,7 @@ private:
"struct yy_buffer_state * state ; " "struct yy_buffer_state * state ; "
"}"; "}";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing6() { void simplifyUsing6() {
@ -240,14 +240,14 @@ private:
"float fast_atan2 ( float y , float x ) { } " "float fast_atan2 ( float y , float x ) { } "
"}"; "}";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing7() { void simplifyUsing7() {
const char code[] = "using abc = int; " const char code[] = "using abc = int; "
"Fred :: abc f ;"; "Fred :: abc f ;";
const char expected[] = "Fred :: abc f ;"; const char expected[] = "Fred :: abc f ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing8() { void simplifyUsing8() {
@ -278,7 +278,7 @@ private:
"const int & trci ; " "const int & trci ; "
"const unsigned int & trcui ;"; "const unsigned int & trcui ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing9() { void simplifyUsing9() {
@ -309,7 +309,7 @@ private:
"struct U * v ; " "struct U * v ; "
"struct Unnamed0 * w ;"; "struct Unnamed0 * w ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing10() { void simplifyUsing10() {
@ -340,7 +340,7 @@ private:
"union U * v ; " "union U * v ; "
"union Unnamed0 * w ;"; "union Unnamed0 * w ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing11() { void simplifyUsing11() {
@ -354,7 +354,7 @@ private:
"enum abc e1 ; " "enum abc e1 ; "
"enum xyz e2 ;"; "enum xyz e2 ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing12() { void simplifyUsing12() {
@ -372,7 +372,7 @@ private:
"std :: vector < std :: vector < int > > v3 ; " "std :: vector < std :: vector < int > > v3 ; "
"std :: list < int > :: iterator iter ;"; "std :: list < int > :: iterator iter ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing13() { void simplifyUsing13() {
@ -386,7 +386,7 @@ private:
"std :: vector < std :: pair < int ( * ) ( void * ) , void * > > q ; " "std :: vector < std :: pair < int ( * ) ( void * ) , void * > > q ; "
"}"; "}";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -403,7 +403,7 @@ private:
" FP_M(val);" " FP_M(val);"
"};"; "};";
TODO_ASSERT_THROW(tok(code, true, Settings::Native, false), InternalError); // TODO: Do not throw AST validation exception TODO_ASSERT_THROW(tok(code, Settings::Native, false), InternalError); // TODO: Do not throw AST validation exception
//ASSERT_EQUALS("", errout.str()); //ASSERT_EQUALS("", errout.str());
} }
@ -414,7 +414,7 @@ private:
const char expected[] = "char f [ 10 ] ;"; const char expected[] = "char f [ 10 ] ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
{ {
@ -423,7 +423,7 @@ private:
const char expected[] = "unsigned char f [ 10 ] ;"; const char expected[] = "unsigned char f [ 10 ] ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
} }
@ -440,7 +440,7 @@ private:
"} ; " "} ; "
"struct STRFOO s ;"; "struct STRFOO s ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -465,12 +465,12 @@ private:
"class S3 s3 ; " "class S3 s3 ; "
"class S4 s4 ;"; "class S4 s4 ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing18() { void simplifyUsing18() {
const char code[] = "{ { { using a = a; using a; } } }"; const char code[] = "{ { { using a = a; using a; } } }";
tok(code, false); // don't crash tok(code); // don't crash
} }
void simplifyUsing19() { void simplifyUsing19() {
@ -482,7 +482,7 @@ private:
" using b = float;\n" " using b = float;\n"
"}\n" "}\n"
"}"; "}";
tok(code, false); // don't hang tok(code); // don't hang
} }
void simplifyUsing20() { void simplifyUsing20() {
@ -526,13 +526,13 @@ private:
" return nullptr;\n" " return nullptr;\n"
"}\n" "}\n"
"}}}}}}}"; "}}}}}}}";
tok(code, false); // don't hang tok(code); // don't hang
} }
void simplifyUsing21() { void simplifyUsing21() {
const char code[] = "using a = b;\n" const char code[] = "using a = b;\n"
"enum {}"; "enum {}";
tok(code, false); // don't crash tok(code); // don't crash
} }
void simplifyUsing22() { void simplifyUsing22() {
@ -557,7 +557,7 @@ private:
"fff :: fff ( ) : m_icm ( icm ) { " "fff :: fff ( ) : m_icm ( icm ) { "
"} " "} "
"} } } } }"; "} } } } }";
ASSERT_EQUALS(expected, tok(code, false)); // don't hang ASSERT_EQUALS(expected, tok(code)); // don't hang
} }
void simplifyUsing23() { void simplifyUsing23() {
@ -587,14 +587,14 @@ private:
": m_icm ( icm ) " ": m_icm ( icm ) "
", m_rt { rt :: UNKNOWN_ } { " ", m_rt { rt :: UNKNOWN_ } { "
"}"; "}";
ASSERT_EQUALS(expected, tok(code, false)); // don't hang ASSERT_EQUALS(expected, tok(code)); // don't hang
} }
void simplifyUsing24() { void simplifyUsing24() {
const char code[] = "using value_type = const ValueFlow::Value;\n" const char code[] = "using value_type = const ValueFlow::Value;\n"
"value_type vt;"; "value_type vt;";
const char expected[] = "const ValueFlow :: Value vt ;"; const char expected[] = "const ValueFlow :: Value vt ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing25() { void simplifyUsing25() {
@ -612,7 +612,7 @@ private:
"namespace vtkm { " "namespace vtkm { "
"struct VecTraits<UnusualType> : VecTraits < vtkm :: Id > { } ; " "struct VecTraits<UnusualType> : VecTraits < vtkm :: Id > { } ; "
"}"; "}";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing8970() { void simplifyUsing8970() {
@ -625,7 +625,7 @@ private:
"std :: vector < int > p ; " "std :: vector < int > p ; "
"} ;"; "} ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing8971() { void simplifyUsing8971() {
@ -649,7 +649,7 @@ private:
"std :: vector < int > v2_ ; " "std :: vector < int > v2_ ; "
"} ;"; "} ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyUsing8976() { void simplifyUsing8976() {
@ -665,11 +665,11 @@ private:
const char exp[] = "int i ;"; const char exp[] = "int i ;";
ASSERT_EQUALS(exp, tok(code, true, Settings::Unix32)); ASSERT_EQUALS(exp, tok(code, Settings::Unix32));
ASSERT_EQUALS(exp, tok(code, true, Settings::Unix64)); ASSERT_EQUALS(exp, tok(code, Settings::Unix64));
ASSERT_EQUALS(exp, tok(code, true, Settings::Win32A)); ASSERT_EQUALS(exp, tok(code, Settings::Win32A));
ASSERT_EQUALS(exp, tok(code, true, Settings::Win32W)); ASSERT_EQUALS(exp, tok(code, Settings::Win32W));
ASSERT_EQUALS(exp, tok(code, true, Settings::Win64)); ASSERT_EQUALS(exp, tok(code, Settings::Win64));
} }
void simplifyUsing9042() { void simplifyUsing9042() {
@ -689,7 +689,7 @@ private:
"} ; " "} ; "
"template < class T > class s { } ;"; "template < class T > class s { } ;";
ASSERT_EQUALS(exp, tok(code, true, Settings::Win64)); ASSERT_EQUALS(exp, tok(code, Settings::Win64));
} }
void simplifyUsing9191() { void simplifyUsing9191() {
@ -716,7 +716,7 @@ private:
"signed long long A ; " "signed long long A ; "
"}"; "}";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
} }
void simplifyUsing9381() { void simplifyUsing9381() {
@ -740,7 +740,7 @@ private:
"} " "} "
"}"; "}";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
} }
void simplifyUsing9385() { void simplifyUsing9385() {
@ -764,7 +764,7 @@ private:
"A :: A ( int ) { } " "A :: A ( int ) { } "
"A :: ~ A ( ) { int foo ; } " "A :: ~ A ( ) { int foo ; } "
"void A :: func ( int ) { }"; "void A :: func ( int ) { }";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
} }
{ {
const char code[] = "class A {\n" const char code[] = "class A {\n"
@ -790,7 +790,7 @@ private:
"A :: B :: B ( int ) { } " "A :: B :: B ( int ) { } "
"A :: B :: ~ B ( ) { int foo ; } " "A :: B :: ~ B ( ) { int foo ; } "
"void A :: B :: func ( int ) { }"; "void A :: B :: func ( int ) { }";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
} }
} }
@ -808,7 +808,7 @@ private:
"int & t_ ; " "int & t_ ; "
"} ; " "} ; "
"A :: A ( int & t ) : t_ ( t ) { }"; "A :: A ( int & t ) : t_ ( t ) { }";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
} }
void simplifyUsing9518() { void simplifyUsing9518() {
@ -818,7 +818,7 @@ private:
const char exp[] = "namespace a { " const char exp[] = "namespace a { "
"enum a { } ; " "enum a { } ; "
"}"; "}";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
} }
void simplifyUsing9757() { void simplifyUsing9757() {
@ -834,7 +834,7 @@ private:
"class MappedType<Type_t::Nil> { } ; " "class MappedType<Type_t::Nil> { } ; "
"std :: string to_string ( Example :: Type_t type ) { " "std :: string to_string ( Example :: Type_t type ) { "
"switch ( type ) { } }"; "switch ( type ) { } }";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
} }
void simplifyUsing10008() { void simplifyUsing10008() {
@ -849,7 +849,7 @@ private:
"static void f ( ) { " "static void f ( ) { "
"const std :: vector < int > arr ; " "const std :: vector < int > arr ; "
"}"; "}";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
} }
void simplifyUsing10054() { // debug: Executable scope 'x' with unknown function. void simplifyUsing10054() { // debug: Executable scope 'x' with unknown function.
@ -885,7 +885,7 @@ private:
"void A :: f ( external :: ns1 :: B<1> ) { } " "void A :: f ( external :: ns1 :: B<1> ) { } "
"} " "} "
"struct external :: ns1 :: B<1> { } ;"; "struct external :: ns1 :: B<1> { } ;";
ASSERT_EQUALS(exp, tok(code, true)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{ {
@ -918,7 +918,7 @@ private:
"void A :: f ( external :: ns1 :: B<1> ) { } " "void A :: f ( external :: ns1 :: B<1> ) { } "
"} " "} "
"struct external :: ns1 :: B<1> { } ;"; "struct external :: ns1 :: B<1> { } ;";
ASSERT_EQUALS(exp, tok(code, true)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{ {
@ -953,7 +953,7 @@ private:
"void A :: f ( external :: ns1 :: B<1> ) { } " "void A :: f ( external :: ns1 :: B<1> ) { } "
"} " "} "
"struct external :: ns1 :: B<1> { } ;"; "struct external :: ns1 :: B<1> { } ;";
ASSERT_EQUALS(exp, tok(code, true)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{ {
@ -988,7 +988,7 @@ private:
"void A :: f ( external :: ns1 :: B<1> ) { } " "void A :: f ( external :: ns1 :: B<1> ) { } "
"} " "} "
"struct external :: ns1 :: B<1> { } ;"; "struct external :: ns1 :: B<1> { } ;";
ASSERT_EQUALS(exp, tok(code, true)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{ {
@ -1018,7 +1018,7 @@ private:
"void A :: f ( external :: B<1> ) { } " "void A :: f ( external :: B<1> ) { } "
"} " "} "
"struct external :: B<1> { } ;"; "struct external :: B<1> { } ;";
ASSERT_EQUALS(exp, tok(code, true)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{ {
@ -1046,7 +1046,7 @@ private:
"void A :: f ( B<1> ) { } " "void A :: f ( B<1> ) { } "
"} " "} "
"struct B<1> { } ;"; "struct B<1> { } ;";
ASSERT_EQUALS(exp, tok(code, true)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
} }
@ -1072,7 +1072,7 @@ private:
"void f ( const std :: vector < char > & ) const override ; " "void f ( const std :: vector < char > & ) const override ; "
"} ; " "} ; "
"void A :: f ( const std :: vector < char > & ) const { }"; "void A :: f ( const std :: vector < char > & ) const { }";
ASSERT_EQUALS(exp, tok(code, true)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{ {
@ -1131,7 +1131,7 @@ private:
"a . f ( v ) ; " "a . f ( v ) ; "
"c . f ( v ) ; " "c . f ( v ) ; "
"}"; "}";
ASSERT_EQUALS(exp, tok(code, true)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{ {
@ -1159,7 +1159,7 @@ private:
" auto ret = foo::ResultCodes_e::NO_ERROR;\n" " auto ret = foo::ResultCodes_e::NO_ERROR;\n"
" return ret;\n" " return ret;\n"
"}"; "}";
tok(code, true); // don't crash tok(code); // don't crash
} }
} }
@ -1191,7 +1191,7 @@ private:
"namespace ns { " "namespace ns { "
"void B :: f ( const std :: vector < unsigned char > & ) const { } " "void B :: f ( const std :: vector < unsigned char > & ) const { } "
"}"; "}";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -1220,7 +1220,7 @@ private:
"namespace ns { " "namespace ns { "
"void B :: f ( std :: function < void ( ) > ) { } " "void B :: f ( std :: function < void ( ) > ) { } "
"}"; "}";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{ {
@ -1255,7 +1255,7 @@ private:
"void B :: f ( std :: function < void ( ) > ) { } " "void B :: f ( std :: function < void ( ) > ) { } "
"} " "} "
"}"; "}";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
} }
@ -1281,7 +1281,7 @@ private:
"void bar ( ) { " "void bar ( ) { "
"Pr < st > p ; " "Pr < st > p ; "
"}"; "}";
ASSERT_EQUALS(exp, tok(code, true)); ASSERT_EQUALS(exp, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{ {
@ -1304,7 +1304,7 @@ private:
"void xxx :: foobar ( ) { " "void xxx :: foobar ( ) { "
"} " "} "
"}"; "}";
ASSERT_EQUALS(exp, tok(code, true)); ASSERT_EQUALS(exp, tok(code));
} }
} }
@ -1312,7 +1312,7 @@ private:
const char code[] = "using uint8_t = unsigned char;\n" const char code[] = "using uint8_t = unsigned char;\n"
"enum E : uint8_t { E0 };"; "enum E : uint8_t { E0 };";
const char exp[] = "enum E : unsigned char { E0 } ;"; const char exp[] = "enum E : unsigned char { E0 } ;";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code));
} }
void scopeInfo1() { void scopeInfo1() {
@ -1322,7 +1322,7 @@ private:
"\n" "\n"
"namespace spdlog { class logger; }\n" "namespace spdlog { class logger; }\n"
"using LoggerPtr = std::shared_ptr<spdlog::logger>;"; "using LoggerPtr = std::shared_ptr<spdlog::logger>;";
tok(code, true); tok(code);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -1334,7 +1334,7 @@ private:
"\n" "\n"
"static void getInitialProgramState(const A::Map& vars = A::Map {})\n" "static void getInitialProgramState(const A::Map& vars = A::Map {})\n"
"{}\n"; "{}\n";
tok(code, true); tok(code);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
}; };