Skip to content

Commit

Permalink
Unit test for %varid% match
Browse files Browse the repository at this point in the history
Also run astyle.
  • Loading branch information
thomasjfox committed Nov 6, 2011
1 parent 05c4b97 commit d7ce892
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/testtoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TestToken : public TestFixture {
TEST_CASE(matchNothingOrAnyNotElse);
TEST_CASE(matchType);
TEST_CASE(matchStr);
TEST_CASE(matchVarid);
TEST_CASE(matchNumeric);
TEST_CASE(matchBoolean);
TEST_CASE(matchOr);
Expand Down Expand Up @@ -200,8 +201,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(false, Token::Match(ifSemicolonElse.tokens(), "if ; !!else"));
}

void matchType()
{
void matchType() {
givenACodeSampleToTokenize type("abc");
ASSERT_EQUALS(true, Token::Match(type.tokens(), "%type%"));

Expand All @@ -214,8 +214,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(false, Token::Match(noType.tokens(), "%type%"));
}

void matchStr()
{
void matchStr() {
givenACodeSampleToTokenize noStr1("abc");
ASSERT_EQUALS(false, Token::Match(noStr1.tokens(), "%str%"));

Expand All @@ -226,6 +225,17 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(true, Token::Match(str.tokens(), "%str%"));
}

void matchVarid() {
givenACodeSampleToTokenize var("int a ; int b ;");
ASSERT_EQUALS(false, Token::Match(var.tokens(), "%type% %varid% ; %type% %var%", 0));

ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %varid% ; %type% %var%", 1));
ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %var% ; %type% %varid%", 2));

// Try to match two different varids in one match call
ASSERT_EQUALS(false, Token::Match(var.tokens(), "%type% %varid% ; %type% %varid%", 2));
}

void matchNumeric() {
givenACodeSampleToTokenize nonNumeric("abc");
ASSERT_EQUALS(false, Token::Match(nonNumeric.tokens(), "%num%"));
Expand Down

0 comments on commit d7ce892

Please sign in to comment.