Unit test for Token::isArithmeticalOp() and Token::isStandardType()

This commit is contained in:
Thomas Jarosch 2011-11-06 18:55:02 +01:00
parent d7ce892c06
commit 7ef1107a55
1 changed files with 76 additions and 0 deletions

View File

@ -52,8 +52,10 @@ private:
TEST_CASE(matchOr); TEST_CASE(matchOr);
TEST_CASE(matchOp); TEST_CASE(matchOp);
TEST_CASE(isArithmeticalOp);
TEST_CASE(isExtendedOp); TEST_CASE(isExtendedOp);
TEST_CASE(isAssignmentOp); TEST_CASE(isAssignmentOp);
TEST_CASE(isStandardType);
TEST_CASE(updateProperties) TEST_CASE(updateProperties)
TEST_CASE(updatePropertiesConcatStr) TEST_CASE(updatePropertiesConcatStr)
@ -328,6 +330,31 @@ private:
ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("!").tokens(), "%op%")); ASSERT_EQUALS(true, Token::Match(givenACodeSampleToTokenize("!").tokens(), "%op%"));
} }
void isArithmeticalOp() {
Token tok(NULL);
// Normal isOp()
tok.str("<<");
ASSERT_EQUALS(true, tok.isArithmeticalOp());
tok.str(">>");
ASSERT_EQUALS(true, tok.isArithmeticalOp());
tok.str("+");
ASSERT_EQUALS(true, tok.isArithmeticalOp());
tok.str("-");
ASSERT_EQUALS(true, tok.isArithmeticalOp());
tok.str("*");
ASSERT_EQUALS(true, tok.isArithmeticalOp());
tok.str("/");
ASSERT_EQUALS(true, tok.isArithmeticalOp());
tok.str("%");
// Negative test
tok.str("&");
ASSERT_EQUALS(false, tok.isArithmeticalOp());
tok.str("|");
ASSERT_EQUALS(false, tok.isArithmeticalOp());
}
void isExtendedOp() { void isExtendedOp() {
Token tok(NULL); Token tok(NULL);
@ -387,6 +414,31 @@ private:
tok.str("?"); tok.str("?");
ASSERT_EQUALS(true, tok.isExtendedOp()); ASSERT_EQUALS(true, tok.isExtendedOp());
tok.str(":"); tok.str(":");
ASSERT_EQUALS(true, tok.isExtendedOp());
// Negative test for assignment operators
tok.str("=");
ASSERT_EQUALS(false, tok.isExtendedOp());
tok.str("+=");
ASSERT_EQUALS(false, tok.isExtendedOp());
tok.str("-=");
ASSERT_EQUALS(false, tok.isExtendedOp());
tok.str("*=");
ASSERT_EQUALS(false, tok.isExtendedOp());
tok.str("/=");
ASSERT_EQUALS(false, tok.isExtendedOp());
tok.str("%=");
ASSERT_EQUALS(false, tok.isExtendedOp());
tok.str("&=");
ASSERT_EQUALS(false, tok.isExtendedOp());
tok.str("^=");
ASSERT_EQUALS(false, tok.isExtendedOp());
tok.str("|=");
ASSERT_EQUALS(false, tok.isExtendedOp());
tok.str("<<=");
ASSERT_EQUALS(false, tok.isExtendedOp());
tok.str(">>=");
ASSERT_EQUALS(false, tok.isExtendedOp());
} }
void isAssignmentOp() { void isAssignmentOp() {
@ -416,6 +468,30 @@ private:
ASSERT_EQUALS(true, tok.isAssignmentOp()); ASSERT_EQUALS(true, tok.isAssignmentOp());
} }
void isStandardType() {
Token tok(NULL);
tok.str("bool");
ASSERT_EQUALS(true, tok.isStandardType());
tok.str("char");
ASSERT_EQUALS(true, tok.isStandardType());
tok.str("short");
ASSERT_EQUALS(true, tok.isStandardType());
tok.str("int");
ASSERT_EQUALS(true, tok.isStandardType());
tok.str("long");
ASSERT_EQUALS(true, tok.isStandardType());
tok.str("float");
ASSERT_EQUALS(true, tok.isStandardType());
tok.str("double");
ASSERT_EQUALS(true, tok.isStandardType());
tok.str("size_t");
ASSERT_EQUALS(true, tok.isStandardType());
// Negative test
tok.str("string");
ASSERT_EQUALS(false, tok.isStandardType());
}
void updateProperties() { void updateProperties() {
Token tok(NULL); Token tok(NULL);
tok.str("foobar"); tok.str("foobar");