TestSymbolDatabase: Code cleanup

This commit is contained in:
Daniel Marjamäki 2018-06-24 17:06:51 +02:00
parent 3155f15325
commit ea6a9c965d
1 changed files with 36 additions and 39 deletions

View File

@ -49,18 +49,16 @@ class TestSymbolDatabase: public TestFixture {
public:
TestSymbolDatabase()
:TestFixture("TestSymbolDatabase")
,si(nullptr, nullptr, nullptr)
,nullScope(nullptr, nullptr, nullptr)
,vartok(nullptr)
,typetok(nullptr)
,t(nullptr)
,found(false) {
}
private:
const Scope si;
const Scope nullScope;
const Token* vartok;
const Token* typetok;
const Token* t;
bool found;
Settings settings1;
Settings settings2;
@ -68,7 +66,6 @@ private:
void reset() {
vartok = nullptr;
typetok = nullptr;
t = nullptr;
found = false;
}
@ -412,7 +409,7 @@ private:
void test_isVariableDeclarationCanHandleNull() {
reset();
bool result = si.isVariableDeclaration(nullptr, vartok, typetok);
bool result = nullScope.isVariableDeclaration(nullptr, vartok, typetok);
ASSERT_EQUALS(false, result);
ASSERT(nullptr == vartok);
ASSERT(nullptr == typetok);
@ -422,7 +419,7 @@ private:
void test_isVariableDeclarationIdentifiesSimpleDeclaration() {
reset();
givenACodeSampleToTokenize simpleDeclaration("int x;");
bool result = si.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("x", vartok->str());
ASSERT_EQUALS("int", typetok->str());
@ -435,7 +432,7 @@ private:
void test_isVariableDeclarationIdentifiesInitialization() {
reset();
givenACodeSampleToTokenize simpleDeclaration("int x (1);");
bool result = si.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("x", vartok->str());
ASSERT_EQUALS("int", typetok->str());
@ -448,7 +445,7 @@ private:
void test_isVariableDeclarationIdentifiesCpp11Initialization() {
reset();
givenACodeSampleToTokenize simpleDeclaration("int x {1};");
bool result = si.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("x", vartok->str());
ASSERT_EQUALS("int", typetok->str());
@ -461,7 +458,7 @@ private:
void test_isVariableDeclarationIdentifiesScopedDeclaration() {
reset();
givenACodeSampleToTokenize ScopedDeclaration("::int x;");
bool result = si.isVariableDeclaration(ScopedDeclaration.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(ScopedDeclaration.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("x", vartok->str());
ASSERT_EQUALS("int", typetok->str());
@ -474,7 +471,7 @@ private:
void test_isVariableDeclarationIdentifiesStdDeclaration() {
reset();
givenACodeSampleToTokenize StdDeclaration("std::string x;");
bool result = si.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("x", vartok->str());
ASSERT_EQUALS("string", typetok->str());
@ -487,7 +484,7 @@ private:
void test_isVariableDeclarationIdentifiesScopedStdDeclaration() {
reset();
givenACodeSampleToTokenize StdDeclaration("::std::string x;");
bool result = si.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("x", vartok->str());
ASSERT_EQUALS("string", typetok->str());
@ -500,7 +497,7 @@ private:
void test_isVariableDeclarationIdentifiesManyScopes() {
reset();
givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE x;");
bool result = si.isVariableDeclaration(manyScopes.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(manyScopes.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("x", vartok->str());
ASSERT_EQUALS("EE", typetok->str());
@ -513,7 +510,7 @@ private:
void test_isVariableDeclarationIdentifiesPointers() {
reset();
givenACodeSampleToTokenize pointer("int* p;");
bool result1 = si.isVariableDeclaration(pointer.tokens(), vartok, typetok);
bool result1 = nullScope.isVariableDeclaration(pointer.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result1);
ASSERT_EQUALS("p", vartok->str());
ASSERT_EQUALS("int", typetok->str());
@ -532,7 +529,7 @@ private:
reset();
givenACodeSampleToTokenize pointerconst("int* const p;");
bool result2 = si.isVariableDeclaration(pointerconst.tokens(), vartok, typetok);
bool result2 = nullScope.isVariableDeclaration(pointerconst.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result2);
ASSERT_EQUALS("p", vartok->str());
ASSERT_EQUALS("int", typetok->str());
@ -546,7 +543,7 @@ private:
void test_isVariableDeclarationDoesNotIdentifyConstness() {
reset();
givenACodeSampleToTokenize constness("const int* cp;");
bool result = si.isVariableDeclaration(constness.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(constness.tokens(), vartok, typetok);
ASSERT_EQUALS(false, result);
ASSERT(nullptr == vartok);
ASSERT(nullptr == typetok);
@ -555,7 +552,7 @@ private:
void test_isVariableDeclarationIdentifiesFirstOfManyVariables() {
reset();
givenACodeSampleToTokenize multipleDeclaration("int first, second;");
bool result = si.isVariableDeclaration(multipleDeclaration.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(multipleDeclaration.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("first", vartok->str());
ASSERT_EQUALS("int", typetok->str());
@ -568,7 +565,7 @@ private:
void test_isVariableDeclarationIdentifiesScopedPointerDeclaration() {
reset();
givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE* p;");
bool result = si.isVariableDeclaration(manyScopes.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(manyScopes.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("p", vartok->str());
ASSERT_EQUALS("EE", typetok->str());
@ -581,7 +578,7 @@ private:
void test_isVariableDeclarationIdentifiesDeclarationWithIndirection() {
reset();
givenACodeSampleToTokenize pointerToPointer("int** pp;");
bool result = si.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("pp", vartok->str());
ASSERT_EQUALS("int", typetok->str());
@ -594,7 +591,7 @@ private:
void test_isVariableDeclarationIdentifiesDeclarationWithMultipleIndirection() {
reset();
givenACodeSampleToTokenize pointerToPointer("int***** p;");
bool result = si.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("p", vartok->str());
ASSERT_EQUALS("int", typetok->str());
@ -607,7 +604,7 @@ private:
void test_isVariableDeclarationIdentifiesArray() {
reset();
givenACodeSampleToTokenize arr("::std::string v[3];");
bool result = si.isVariableDeclaration(arr.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(arr.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("v", vartok->str());
ASSERT_EQUALS("string", typetok->str());
@ -621,7 +618,7 @@ private:
void test_isVariableDeclarationIdentifiesPointerArray() {
reset();
givenACodeSampleToTokenize arr("A *a[5];");
bool result = si.isVariableDeclaration(arr.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(arr.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("a", vartok->str());
ASSERT_EQUALS("A", typetok->str());
@ -636,7 +633,7 @@ private:
void test_isVariableDeclarationIdentifiesOfArrayPointers() {
reset();
givenACodeSampleToTokenize arr("A (*a)[5];");
bool result = si.isVariableDeclaration(arr.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(arr.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("a", vartok->str());
ASSERT_EQUALS("A", typetok->str());
@ -651,7 +648,7 @@ private:
void isVariableDeclarationIdentifiesTemplatedPointerVariable() {
reset();
givenACodeSampleToTokenize var("std::set<char>* chars;");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("chars", vartok->str());
ASSERT_EQUALS("set", typetok->str());
@ -664,7 +661,7 @@ private:
void isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable() {
reset();
givenACodeSampleToTokenize var("std::deque<int>*** ints;");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("ints", vartok->str());
ASSERT_EQUALS("deque", typetok->str());
@ -677,7 +674,7 @@ private:
void isVariableDeclarationIdentifiesTemplatedArrayVariable() {
reset();
givenACodeSampleToTokenize var("std::deque<int> ints[3];");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("ints", vartok->str());
ASSERT_EQUALS("deque", typetok->str());
@ -690,7 +687,7 @@ private:
void isVariableDeclarationIdentifiesTemplatedVariable() {
reset();
givenACodeSampleToTokenize var("std::vector<int> ints;");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("ints", vartok->str());
ASSERT_EQUALS("vector", typetok->str());
@ -703,7 +700,7 @@ private:
void isVariableDeclarationIdentifiesTemplatedVariableIterator() {
reset();
givenACodeSampleToTokenize var("std::list<int>::const_iterator floats;");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("floats", vartok->str());
ASSERT_EQUALS("const_iterator", typetok->str());
@ -716,7 +713,7 @@ private:
void isVariableDeclarationIdentifiesNestedTemplateVariable() {
reset();
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("intsets", vartok->str());
ASSERT_EQUALS("deque", typetok->str());
@ -729,7 +726,7 @@ private:
void isVariableDeclarationIdentifiesReference() {
reset();
givenACodeSampleToTokenize var1("int& foo;");
bool result1 = si.isVariableDeclaration(var1.tokens(), vartok, typetok);
bool result1 = nullScope.isVariableDeclaration(var1.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result1);
Variable v1(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings1);
ASSERT(false == v1.isArray());
@ -738,7 +735,7 @@ private:
reset();
givenACodeSampleToTokenize var2("foo*& bar;");
bool result2 = si.isVariableDeclaration(var2.tokens(), vartok, typetok);
bool result2 = nullScope.isVariableDeclaration(var2.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result2);
Variable v2(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings1);
ASSERT(false == v2.isArray());
@ -747,7 +744,7 @@ private:
reset();
givenACodeSampleToTokenize var3("std::vector<int>& foo;");
bool result3 = si.isVariableDeclaration(var3.tokens(), vartok, typetok);
bool result3 = nullScope.isVariableDeclaration(var3.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result3);
Variable v3(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings1);
ASSERT(false == v3.isArray());
@ -758,21 +755,21 @@ private:
void isVariableDeclarationDoesNotIdentifyTemplateClass() {
reset();
givenACodeSampleToTokenize var("template <class T> class SomeClass{};");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(false, result);
}
void isVariableDeclarationDoesNotIdentifyCppCast() {
reset();
givenACodeSampleToTokenize var("reinterpret_cast <char *> (code)[0] = 0;");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(false, result);
}
void isVariableDeclarationPointerConst() {
reset();
givenACodeSampleToTokenize var("std::string const* s;");
bool result = si.isVariableDeclaration(var.tokens()->next(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(var.tokens()->next(), vartok, typetok);
ASSERT_EQUALS(true, result);
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings1);
ASSERT(false == v.isArray());
@ -783,7 +780,7 @@ private:
void isVariableDeclarationRValueRef() {
reset();
givenACodeSampleToTokenize var("int&& i;");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings1);
ASSERT(false == v.isArray());
@ -905,7 +902,7 @@ private:
std::istringstream code("std::string s;");
TokenList list(nullptr);
list.createTokens(code, "test.cpp");
bool result = si.isVariableDeclaration(list.front(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(list.front(), vartok, typetok);
ASSERT_EQUALS(true, result);
Variable v(vartok, list.front(), list.back(), 0, Public, 0, 0, &settings1);
static const std::set<std::string> types = { "string", "wstring" };
@ -921,7 +918,7 @@ private:
TokenList list(nullptr);
list.createTokens(code, "test.cpp");
list.front()->tokAt(3)->link(list.front()->tokAt(5));
bool result = si.isVariableDeclaration(list.front(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(list.front(), vartok, typetok);
ASSERT_EQUALS(true, result);
Variable v(vartok, list.front(), list.back(), 0, Public, 0, 0, &settings1);
static const std::set<std::string> types = { "bitset", "set", "vector", "wstring" };
@ -936,7 +933,7 @@ private:
std::istringstream code("SomeClass s;");
TokenList list(nullptr);
list.createTokens(code, "test.cpp");
bool result = si.isVariableDeclaration(list.front(), vartok, typetok);
bool result = nullScope.isVariableDeclaration(list.front(), vartok, typetok);
ASSERT_EQUALS(true, result);
Variable v(vartok, list.front(), list.back(), 0, Public, 0, 0, &settings1);
static const std::set<std::string> types = { "bitset", "set", "vector" };