From cd01fad4780f0287ecd62241dc17a9d47a30a80f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mor=C3=A1n?= Date: Mon, 28 Sep 2015 12:13:59 +0200 Subject: [PATCH] Added regular expression test for named substrings --- Foundation/testsuite/src/RegularExpressionTest.cpp | 11 +++++++++++ Foundation/testsuite/src/RegularExpressionTest.h | 1 + 2 files changed, 12 insertions(+) diff --git a/Foundation/testsuite/src/RegularExpressionTest.cpp b/Foundation/testsuite/src/RegularExpressionTest.cpp index 8f395c5c5..cd6c1fb13 100644 --- a/Foundation/testsuite/src/RegularExpressionTest.cpp +++ b/Foundation/testsuite/src/RegularExpressionTest.cpp @@ -264,6 +264,16 @@ void RegularExpressionTest::testError() } } +void RegularExpressionTest::testGroup() +{ + RegularExpression::MatchVec matches; + RegularExpression re("(?P[a-z]+) (?P[0-9]+)"); + assert (re.match("abcd 1234", 0, matches) == 3); + assert (matches[0].name == ""); + assert (matches[1].name == "group1"); + assert (matches[2].name == "group2"); +} + void RegularExpressionTest::setUp() { @@ -294,6 +304,7 @@ CppUnit::Test* RegularExpressionTest::suite() CppUnit_addTest(pSuite, RegularExpressionTest, testSubst3); CppUnit_addTest(pSuite, RegularExpressionTest, testSubst4); CppUnit_addTest(pSuite, RegularExpressionTest, testError); + CppUnit_addTest(pSuite, RegularExpressionTest, testGroup); return pSuite; } diff --git a/Foundation/testsuite/src/RegularExpressionTest.h b/Foundation/testsuite/src/RegularExpressionTest.h index 3ab98e29d..ef49ae344 100644 --- a/Foundation/testsuite/src/RegularExpressionTest.h +++ b/Foundation/testsuite/src/RegularExpressionTest.h @@ -41,6 +41,7 @@ public: void testSubst3(); void testSubst4(); void testError(); + void testGroup(); void setUp(); void tearDown();