Fix single %op% operator not working at all

When parsing the Token::Match pattern, we accesed
the wrong character in the pattern and never
executed the %op% check.

In addition the unit test function for %op%
wasn't registered in the test suite. Ups.

All fixed now and also provide a complete
check for all operators %op% supports.
This commit is contained in:
Thomas Jarosch 2011-11-06 18:02:18 +01:00
parent 6e2f2816de
commit 19c9c97608
2 changed files with 24 additions and 5 deletions

View File

@ -561,7 +561,7 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
if (tok->str() != "|") if (tok->str() != "|")
return false; return false;
p += 4; p += 4;
} else if (p[3] == 'p') { } else if (p[2] == 'p') {
if (!tok->isOp()) if (!tok->isOp())
return false; return false;
p += 4; p += 4;

View File

@ -47,6 +47,7 @@ private:
TEST_CASE(matchNumeric); TEST_CASE(matchNumeric);
TEST_CASE(matchBoolean); TEST_CASE(matchBoolean);
TEST_CASE(matchOr); TEST_CASE(matchOr);
TEST_CASE(matchOp);
TEST_CASE(updateProperties) TEST_CASE(updateProperties)
TEST_CASE(updatePropertiesConcatStr) TEST_CASE(updatePropertiesConcatStr)
@ -248,12 +249,12 @@ private:
void matchOr() { void matchOr() {
givenACodeSampleToTokenize bitwiseOr("|"); givenACodeSampleToTokenize bitwiseOr("|");
ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%or%")); ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%or%"));
ASSERT_EQUALS(false, Token::Match(bitwiseOr.tokens(), "%op%")); ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%op%"));
ASSERT_EQUALS(false, Token::Match(bitwiseOr.tokens(), "%oror%")); ASSERT_EQUALS(false, Token::Match(bitwiseOr.tokens(), "%oror%"));
givenACodeSampleToTokenize logicalOr("||"); givenACodeSampleToTokenize logicalOr("||");
ASSERT_EQUALS(false, Token::Match(logicalOr.tokens(), "%or%")); ASSERT_EQUALS(false, Token::Match(logicalOr.tokens(), "%or%"));
ASSERT_EQUALS(false, Token::Match(logicalOr.tokens(), "%op%")); ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%oror%")); ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%oror%"));
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "&&|%oror%")); ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "&&|%oror%"));
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%oror%|&&")); ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%oror%|&&"));
@ -265,8 +266,26 @@ private:
} }
void matchOp() { void matchOp() {
givenACodeSampleToTokenize op("+"); ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("<<").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(op.tokens(), "%op%")); ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize(">>").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("+").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("-").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("*").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("/").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("%").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("&&").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("||").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("==").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("!=").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("<").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("<=").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize(">").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize(">=").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("&").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("|").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("^").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("~").tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("!").tokens(), "%op%"));
} }
void updateProperties() { void updateProperties() {