MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / createLinks

Method createLinks

test/testtokenize.cpp:3189–3465  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3187 }
3188
3189 void createLinks() {
3190 {
3191 const char code[] = "class A{\n"
3192 " void f() {}\n"
3193 "};";
3194 SimpleTokenizer tokenizer(settingsDefault, *this);
3195 ASSERT(tokenizer.tokenize(code));
3196 const Token *tok = tokenizer.tokens();
3197 // A body {}
3198 ASSERT_EQUALS(true, tok->linkAt(2) == tok->tokAt(9));
3199 ASSERT_EQUALS(true, tok->linkAt(9) == tok->tokAt(2));
3200
3201 // f body {}
3202 ASSERT_EQUALS(true, tok->linkAt(7) == tok->tokAt(8));
3203 ASSERT_EQUALS(true, tok->linkAt(8) == tok->tokAt(7));
3204
3205 // f ()
3206 ASSERT_EQUALS(true, tok->linkAt(5) == tok->tokAt(6));
3207 ASSERT_EQUALS(true, tok->linkAt(6) == tok->tokAt(5));
3208
3209 ASSERT_EQUALS("", errout_str());
3210 }
3211
3212 {
3213 const char code[] = "void f(){\n"
3214 " char a[10];\n"
3215 " char *b ; b = new char[a[0]];\n"
3216 "};";
3217 SimpleTokenizer tokenizer(settingsDefault, *this);
3218 ASSERT(tokenizer.tokenize(code));
3219 const Token *tok = tokenizer.tokens();
3220 // a[10]
3221 ASSERT_EQUALS(true, tok->linkAt(7) == tok->tokAt(9));
3222 ASSERT_EQUALS(true, tok->linkAt(9) == tok->tokAt(7));
3223
3224 // new char[]
3225 ASSERT_EQUALS(true, tok->linkAt(19) == tok->tokAt(24));
3226 ASSERT_EQUALS(true, tok->linkAt(24) == tok->tokAt(19));
3227
3228 // a[0]
3229 ASSERT_EQUALS(true, tok->linkAt(21) == tok->tokAt(23));
3230 ASSERT_EQUALS(true, tok->linkAt(23) == tok->tokAt(21));
3231
3232 ASSERT_EQUALS("", errout_str());
3233 }
3234
3235 {
3236 const char code[] = "void f(){\n"
3237 " foo(g());\n"
3238 "};";
3239 SimpleTokenizer tokenizer(settingsDefault, *this);
3240 ASSERT(tokenizer.tokenize(code));
3241 const Token *tok = tokenizer.tokens();
3242 // foo(
3243 ASSERT_EQUALS(true, tok->linkAt(6) == tok->tokAt(10));
3244 ASSERT_EQUALS(true, tok->linkAt(10) == tok->tokAt(6));
3245
3246 // g(

Callers 13

simplifyTypedefMethod · 0.45
simplifyTypedefPMethod · 0.45
simplifyTypedefCMethod · 0.45
dumpTypedefInfoMethod · 0.45
testAstMethod · 0.45
templateParametersMethod · 0.45

Calls 3

tokenizeMethod · 0.80
linkAtMethod · 0.80
tokAtMethod · 0.45

Tested by

no test coverage detected