Skip to content

Commit

Permalink
testrunner: adjusted several Tokenizer creations
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Aug 7, 2023
1 parent 264f85c commit 1d0788a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions test/testlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ class TestLibrary : public TestFixture {
}
}

void function_method() const {
void function_method() {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"CString::Format\">\n"
Expand All @@ -580,21 +580,21 @@ class TestLibrary : public TestFixture {
ASSERT_EQUALS(library.functions.size(), 1U);

{
Tokenizer tokenizer(&settings, nullptr);
Tokenizer tokenizer(&settings, this);
std::istringstream istr("CString str; str.Format();");
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
ASSERT(library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format")));
}

{
Tokenizer tokenizer(&settings, nullptr);
Tokenizer tokenizer(&settings, this);
std::istringstream istr("HardDrive hd; hd.Format();");
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
ASSERT(!library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format")));
}
}

void function_baseClassMethod() const {
void function_baseClassMethod() {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"Base::f\">\n"
Expand All @@ -606,14 +606,14 @@ class TestLibrary : public TestFixture {
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));

{
Tokenizer tokenizer(&settings, nullptr);
Tokenizer tokenizer(&settings, this);
std::istringstream istr("struct X : public Base { void dostuff() { f(0); } };");
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
ASSERT(library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1));
}

{
Tokenizer tokenizer(&settings, nullptr);
Tokenizer tokenizer(&settings, this);
std::istringstream istr("struct X : public Base { void dostuff() { f(1,2); } };");
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
ASSERT(!library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1));
Expand Down
24 changes: 12 additions & 12 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5904,9 +5904,9 @@ class TestTokenizer : public TestFixture {
Z3
};

std::string testAst(const char code[], AstStyle style = AstStyle::Simple) const {
std::string testAst(const char code[], AstStyle style = AstStyle::Simple) {
// tokenize given code..
Tokenizer tokenList(&settings0, nullptr);
Tokenizer tokenList(&settings0, this);
std::istringstream istr(code);
if (!tokenList.list.createTokens(istr,"test.cpp"))
return "ERROR";
Expand Down Expand Up @@ -5953,7 +5953,7 @@ class TestTokenizer : public TestFixture {
return ret;
}

void astexpr() const { // simple expressions with arithmetical ops
void astexpr() { // simple expressions with arithmetical ops
ASSERT_EQUALS("12+3+", testAst("1+2+3"));
ASSERT_EQUALS("12*3+", testAst("1*2+3"));
ASSERT_EQUALS("123*+", testAst("1+2*3"));
Expand Down Expand Up @@ -6214,7 +6214,7 @@ class TestTokenizer : public TestFixture {
ASSERT_NO_THROW(tokenizeAndStringify(code));
}

void astnewdelete() const {
void astnewdelete() {
ASSERT_EQUALS("aintnew=", testAst("a = new int;"));
ASSERT_EQUALS("aint4[new=", testAst("a = new int[4];"));
ASSERT_EQUALS("aFoobar(new=", testAst("a = new Foo(bar);"));
Expand Down Expand Up @@ -6438,15 +6438,15 @@ class TestTokenizer : public TestFixture {
"}\n"));
}

void astbrackets() const { // []
void astbrackets() { // []
ASSERT_EQUALS("a23+[4+", testAst("a[2+3]+4"));
ASSERT_EQUALS("a1[0[", testAst("a[1][0]"));
ASSERT_EQUALS("ab0[=", testAst("a=(b)[0];"));
ASSERT_EQUALS("abc.0[=", testAst("a=b.c[0];"));
ASSERT_EQUALS("ab0[1[=", testAst("a=b[0][1];"));
}

void astvardecl() const {
void astvardecl() {
// Variable declaration
ASSERT_EQUALS("a1[\"\"=", testAst("char a[1]=\"\";"));
ASSERT_EQUALS("charp*(3[char5[3[new=", testAst("char (*p)[3] = new char[5][3];"));
Expand Down Expand Up @@ -6480,7 +6480,7 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("i(j=", testAst("(int&)(i) = j;"));
}

void astunaryop() const { // unary operators
void astunaryop() { // unary operators
ASSERT_EQUALS("1a--+", testAst("1 + --a"));
ASSERT_EQUALS("1a--+", testAst("1 + a--"));
ASSERT_EQUALS("ab+!", testAst("!(a+b)"));
Expand All @@ -6506,7 +6506,7 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("int0{1&return", testAst("int g() { return int{ 0 } & 1; }"));
}

void astfunction() const { // function calls
void astfunction() { // function calls
ASSERT_EQUALS("1f(+2+", testAst("1+f()+2"));
ASSERT_EQUALS("1f2(+3+", testAst("1+f(2)+3"));
ASSERT_EQUALS("1f23,(+4+", testAst("1+f(2,3)+4"));
Expand Down Expand Up @@ -6569,7 +6569,7 @@ class TestTokenizer : public TestFixture {
"}\n"));
}

void astcast() const {
void astcast() {
ASSERT_EQUALS("ac&(=", testAst("a = (long)&c;"));
ASSERT_EQUALS("ac*(=", testAst("a = (Foo*)*c;"));
ASSERT_EQUALS("ac-(=", testAst("a = (long)-c;"));
Expand Down Expand Up @@ -6742,14 +6742,14 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("sf.{(i[{={", testAst("void g(int i) { S s{ .f = { [i]() {} } }; }"));
}

void astcase() const {
void astcase() {
ASSERT_EQUALS("0case", testAst("case 0:"));
ASSERT_EQUALS("12+case", testAst("case 1+2:"));
ASSERT_EQUALS("xyz:?case", testAst("case (x?y:z):"));
ASSERT_EQUALS("switchx( 1case y++ 2case", testAst("switch(x){case 1:{++y;break;case 2:break;}}"));
}

void astrefqualifier() const {
void astrefqualifier() {
ASSERT_EQUALS("b(int.", testAst("class a { auto b() -> int&; };"));
ASSERT_EQUALS("b(int.", testAst("class a { auto b() -> int&&; };"));
ASSERT_EQUALS("b(", testAst("class a { void b() &&; };"));
Expand All @@ -6760,7 +6760,7 @@ class TestTokenizer : public TestFixture {

//Verify that returning a newly constructed object generates the correct AST even when the class name is scoped
//Addresses https://trac.cppcheck.net/ticket/9700
void astnewscoped() const {
void astnewscoped() {
ASSERT_EQUALS("(return (new A))", testAst("return new A;", AstStyle::Z3));
ASSERT_EQUALS("(return (new (( A)))", testAst("return new A();", AstStyle::Z3));
ASSERT_EQUALS("(return (new (( A true)))", testAst("return new A(true);", AstStyle::Z3));
Expand Down
4 changes: 2 additions & 2 deletions test/testtokenrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class TestTokenRange : public TestFixture {
ASSERT_EQUALS("", testTokenRange(ConstTokenRange{ start, end }, start, end));
}

void scopeExample() const {
void scopeExample() {
const Settings settings;
Tokenizer tokenizer{ &settings, nullptr };
Tokenizer tokenizer{ &settings, this };
std::istringstream sample("void a(){} void main(){ if(true){a();} }");
ASSERT(tokenizer.tokenize(sample, "test.cpp"));

Expand Down

0 comments on commit 1d0788a

Please sign in to comment.