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:
parent
6e2f2816de
commit
19c9c97608
|
@ -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;
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue