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