Skip to content

Commit cd01fad

Browse files
author
David Morán
committed
Added regular expression test for named substrings
1 parent 8f1f678 commit cd01fad

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎Foundation/testsuite/src/RegularExpressionTest.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ void RegularExpressionTest::testError()
264264
}
265265
}
266266

267+
void RegularExpressionTest::testGroup()
268+
{
269+
RegularExpression::MatchVec matches;
270+
RegularExpression re("(?P<group1>[a-z]+) (?P<group2>[0-9]+)");
271+
assert (re.match("abcd 1234", 0, matches) == 3);
272+
assert (matches[0].name == "");
273+
assert (matches[1].name == "group1");
274+
assert (matches[2].name == "group2");
275+
}
276+
267277

268278
void RegularExpressionTest::setUp()
269279
{
@@ -294,6 +304,7 @@ CppUnit::Test* RegularExpressionTest::suite()
294304
CppUnit_addTest(pSuite, RegularExpressionTest, testSubst3);
295305
CppUnit_addTest(pSuite, RegularExpressionTest, testSubst4);
296306
CppUnit_addTest(pSuite, RegularExpressionTest, testError);
307+
CppUnit_addTest(pSuite, RegularExpressionTest, testGroup);
297308

298309
return pSuite;
299310
}

‎Foundation/testsuite/src/RegularExpressionTest.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class RegularExpressionTest: public CppUnit::TestCase
4141
void testSubst3();
4242
void testSubst4();
4343
void testError();
44+
void testGroup();
4445

4546
void setUp();
4647
void tearDown();

0 commit comments

Comments
 (0)