Refactor test code

This commit is contained in:
Daniel Marjamäki 2018-10-10 14:35:58 +02:00
parent 25cbfe27cf
commit c048bd45f6
1 changed files with 62 additions and 62 deletions

View File

@ -5612,88 +5612,88 @@ private:
}
void simplifyNamespaceStd() {
const char *code;
const char *code, *expected;
static const char code1[] = "map<foo, bar> m;"; // namespace std is not used
ASSERT_EQUALS("map < foo , bar > m ;", tokenizeAndStringify(code1, false));
code = "map<foo, bar> m;"; // namespace std is not used
ASSERT_EQUALS("map < foo , bar > m ;", tokenizeAndStringify(code, false));
static const char code2[] = "using namespace std;\n"
"map<foo, bar> m;";
ASSERT_EQUALS("std :: map < foo , bar > m ;", tokenizeAndStringify(code2, false));
code = "using namespace std;\n"
"map<foo, bar> m;";
ASSERT_EQUALS("std :: map < foo , bar > m ;", tokenizeAndStringify(code, false));
static const char code3[] = "using namespace std;\n"
"string s;";
ASSERT_EQUALS("std :: string s ;", tokenizeAndStringify(code3, false));
code = "using namespace std;\n"
"string s;";
ASSERT_EQUALS("std :: string s ;", tokenizeAndStringify(code, false));
static const char code4[] = "using namespace std;\n"
"void foo() {swap(a, b); }";
ASSERT_EQUALS("void foo ( ) { std :: swap ( a , b ) ; }", tokenizeAndStringify(code4, false));
code = "using namespace std;\n"
"void foo() {swap(a, b); }";
ASSERT_EQUALS("void foo ( ) { std :: swap ( a , b ) ; }", tokenizeAndStringify(code, false));
code = "using namespace std;\n"
"void search() {}";
ASSERT_EQUALS("void search ( ) { }", tokenizeAndStringify(code, false));
static const char code5[] = "using namespace std;\n"
"void foo() {map(a, b); }"; // That's obviously not std::map<>
ASSERT_EQUALS("void foo ( ) { map ( a , b ) ; }", tokenizeAndStringify(code5, false));
code = "using namespace std;\n"
"void foo() {map(a, b); }"; // That's obviously not std::map<>
ASSERT_EQUALS("void foo ( ) { map ( a , b ) ; }", tokenizeAndStringify(code, false));
static const char code6[] = "using namespace std;\n"
"string<wchar_t> s;"; // That's obviously not std::string
ASSERT_EQUALS("string < wchar_t > s ;", tokenizeAndStringify(code6, false));
code = "using namespace std;\n"
"string<wchar_t> s;"; // That's obviously not std::string
ASSERT_EQUALS("string < wchar_t > s ;", tokenizeAndStringify(code, false));
static const char code7[] = "using namespace std;\n"
"swap s;"; // That's obviously not std::swap
ASSERT_EQUALS("swap s ;", tokenizeAndStringify(code7, false));
code = "using namespace std;\n"
"swap s;"; // That's obviously not std::swap
ASSERT_EQUALS("swap s ;", tokenizeAndStringify(code, false));
static const char code8[] = "using namespace std;\n"
"std::string s;";
ASSERT_EQUALS("std :: string s ;", tokenizeAndStringify(code8, false));
code = "using namespace std;\n"
"std::string s;";
ASSERT_EQUALS("std :: string s ;", tokenizeAndStringify(code, false));
static const char code9[] = "using namespace std;\n"
"tr1::function <void(int)> f;";
ASSERT_EQUALS("tr1 :: function < void ( int ) > f ;", tokenizeAndStringify(code9, false, true, Settings::Native, "test.cpp", false));
ASSERT_EQUALS("std :: function < void ( int ) > f ;", tokenizeAndStringify(code9, false, true, Settings::Native, "test.cpp", true));
code = "using namespace std;\n"
"tr1::function <void(int)> f;";
ASSERT_EQUALS("tr1 :: function < void ( int ) > f ;", tokenizeAndStringify(code, false, true, Settings::Native, "test.cpp", false));
ASSERT_EQUALS("std :: function < void ( int ) > f ;", tokenizeAndStringify(code, false, true, Settings::Native, "test.cpp", true));
static const char code10[] = "std::tr1::function <void(int)> f;";
ASSERT_EQUALS("std :: tr1 :: function < void ( int ) > f ;", tokenizeAndStringify(code10, false, true, Settings::Native, "test.cpp", false));
ASSERT_EQUALS("std :: function < void ( int ) > f ;", tokenizeAndStringify(code10, false, true, Settings::Native, "test.cpp", true));
code = "std::tr1::function <void(int)> f;";
ASSERT_EQUALS("std :: tr1 :: function < void ( int ) > f ;", tokenizeAndStringify(code, false, true, Settings::Native, "test.cpp", false));
ASSERT_EQUALS("std :: function < void ( int ) > f ;", tokenizeAndStringify(code, false, true, Settings::Native, "test.cpp", true));
// #4042 (Do not add 'std ::' to variables)
static const char code11[] = "using namespace std;\n"
"const char * string = \"Hi\";";
ASSERT_EQUALS("const char * string ; string = \"Hi\" ;", tokenizeAndStringify(code11, false));
code = "using namespace std;\n"
"const char * string = \"Hi\";";
ASSERT_EQUALS("const char * string ; string = \"Hi\" ;", tokenizeAndStringify(code, false));
static const char code12[] = "using namespace std;\n"
"string f(const char * string) {\n"
" cout << string << endl;\n"
" return string;\n"
"}";
static const char expected12[] = "std :: string f ( const char * string ) {\n"
"std :: cout << string << std :: endl ;\n"
"return string ;\n"
"}";
ASSERT_EQUALS(expected12, tokenizeAndStringify(code12, false));
code = "using namespace std;\n"
"string f(const char * string) {\n"
" cout << string << endl;\n"
" return string;\n"
"}";
expected = "std :: string f ( const char * string ) {\n"
"std :: cout << string << std :: endl ;\n"
"return string ;\n"
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, false));
static const char code13[] = "using namespace std;\n"
"try { }\n"
"catch(std::exception &exception) { }";
static const char expected13[] = "try { }\n"
"catch ( std :: exception & exception ) { }";
ASSERT_EQUALS(expected13, tokenizeAndStringify(code13, false));
code = "using namespace std;\n"
"try { }\n"
"catch(std::exception &exception) { }";
expected = "try { }\n"
"catch ( std :: exception & exception ) { }";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, false));
// #5773 (Don't prepend 'std ::' to function definitions)
static const char code14[] = "using namespace std;\n"
"class C {\n"
" void search() {}\n"
" void search() const {}\n"
" void search() THROW_MACRO {}\n"
"};";
static const char expected14[] = "class C {\n"
"void search ( ) { }\n"
"void search ( ) const { }\n"
"void search ( ) { }\n"
"} ;";
ASSERT_EQUALS(expected14, tokenizeAndStringify(code14, false));
code = "using namespace std;\n"
"class C {\n"
" void search() {}\n"
" void search() const {}\n"
" void search() THROW_MACRO {}\n"
"};";
expected = "class C {\n"
"void search ( ) { }\n"
"void search ( ) const { }\n"
"void search ( ) { }\n"
"} ;";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, false));
// Ticket #8091
ASSERT_EQUALS("enum Anonymous0 { string } ;",