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

Method testTokenRange

test/testtokenrange.cpp:46–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44 }
45
46 static std::string testTokenRange(ConstTokenRange range, const Token* start, const Token* end) {
47 auto tokenToString = [](const Token* t) {
48 return t ? t->str() : "<null>";
49 };
50 int index = 0;
51 const Token* expected = start;
52 for (const Token* t : range) {
53 if (expected != t) {
54 std::ostringstream message;
55 message << "Failed to match token " << tokenToString(expected) << " at position " << index << ". Got " << tokenToString(t) << " instead";
56 return message.str();
57 }
58 index++;
59 expected = expected->next();
60 }
61 if (expected != end) {
62 std::ostringstream message;
63 message << "Failed to terminate on " << tokenToString(end) << ". Instead terminated on " << tokenToString(expected) << " at position " << index << ".";
64 return message.str();
65 }
66 return "";
67 }
68
69 void enumerationToEnd() const {
70 const char code[] = "void a(){} void main(){ if(true){a();} }";

Callers

nothing calls this directly

Calls 3

tokenToStringFunction · 0.85
nextMethod · 0.80
strMethod · 0.45

Tested by

no test coverage detected