[Libreoffice-commits] core.git: sw/qa

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Thu Dec 19 08:17:25 UTC 2019


 sw/qa/extras/uiwriter/uiwriter.cxx |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

New commits:
commit fd8f926b0e409d49d235409daaf8f7aa8532cc40
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu Dec 19 10:09:11 2019 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu Dec 19 09:16:30 2019 +0100

    tdf#75806: extend SwUiWriterTest::testTextSearch to test relevant regexes
    
    Change-Id: Iafcfc8367fba83b3882c83a7b88dd893b1f98af2
    Reviewed-on: https://gerrit.libreoffice.org/85472
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 6932e6992e81..cc51519f61fd 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -2254,6 +2254,36 @@ void SwUiWriterTest::testTextSearch()
     //Now performing search again for BOLD words, count should be 3 due to replacement
     uno::Reference<container::XIndexAccess> xIndex2(xReplace->findAll(xSearchDes));
     CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndex2->getCount());
+    // regex tests
+    xReplaceDes->setPropertyValue("SearchRegularExpression", uno::makeAny(true));
+    // regex: test correct match of paragraph start
+    xReplaceDes->setSearchString("^."); // should only match first character of the paragraph
+    xReplaceDes->setReplaceString("C");
+    ReplaceCount = xReplace->replaceAll(xReplaceDes);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount);
+    // regex: test correct match of word start
+    xReplaceDes->setSearchString("\\b\\w"); // should match all words' first characters
+    xReplaceDes->setReplaceString("x&");
+    ReplaceCount = xReplace->replaceAll(xReplaceDes);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(6), ReplaceCount);
+    // regex: test negative look-behind assertion
+    xReplaceDes->setSearchString("(?<!xCelly xW)o"); // only "o" in "xCello", not in "xWorld"
+    xReplaceDes->setReplaceString("y");
+    ReplaceCount = xReplace->replaceAll(xReplaceDes);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount);
+    // regex: test positive look-behind assertion
+    xReplaceDes->setSearchString("(?<=xCelly xWorld xTh)i"); // only "i" in "xThis", not in "xis"
+    xReplaceDes->setReplaceString("z");
+    ReplaceCount = xReplace->replaceAll(xReplaceDes);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount);
+    // regex: use capturing group to test reference
+    xReplaceDes->setSearchString("\\b(\\w\\w\\w\\w)\\w");
+    xReplaceDes->setReplaceString("$1q"); // only fifth characters in words should change
+    ReplaceCount = xReplace->replaceAll(xReplaceDes);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(4), ReplaceCount);
+    // check of the end result
+    CPPUNIT_ASSERT_EQUAL(OUString("xCelqy xWorqd xThzq xis xa xtasq"),
+                         pCursor->GetNode().GetTextNode()->GetText());
 }
 
 void SwUiWriterTest::testTdf69282()


More information about the Libreoffice-commits mailing list