sc/qa/unit/ucalc_formula2.cxx |   48 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

New commits:
commit 0ca20dca3349daa303b89251443f550491968a39
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Fri May 3 23:17:45 2024 +0200
Commit:     Balazs Varga <balazs.varga.ext...@allotropia.de>
CommitDate: Tue May 7 13:14:03 2024 +0200

    Related: tdf#127293 Add unit test for xlookup regex search mode
    
    Add unit test for regex search mode in case of xlookup.
    
    Follow-up commit: 51abf44808c6793a184e986b62c0786753e11ded
    (Related: tdf#127293 Fix regex search mode in XLOOKUP wildcards mode)
    
    Change-Id: Id23c340ab6735c2c40defc8d231dc3da18c8694e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167192
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>

diff --git a/sc/qa/unit/ucalc_formula2.cxx b/sc/qa/unit/ucalc_formula2.cxx
index 180f283323ca..70f945a4ca5c 100644
--- a/sc/qa/unit/ucalc_formula2.cxx
+++ b/sc/qa/unit/ucalc_formula2.cxx
@@ -4640,6 +4640,54 @@ CPPUNIT_TEST_FIXTURE(TestFormula2, 
testFormulaAfterDeleteRows)
     ASSERT_DOUBLES_EQUAL_MESSAGE("Wrong value at A4", 3.0, 
m_pDoc->GetValue(aPos));
 }
 
+CPPUNIT_TEST_FIXTURE(TestFormula2, testRegexForXLOOKUP)
+{
+    sc::AutoCalcSwitch aACSwitch(*m_pDoc, true);
+
+    // Temporarily switch regex search mode.
+    bool bOldWildCard = false;
+    ScDocOptions aDocOpt = m_pDoc->GetDocOptions();
+    if (!aDocOpt.IsFormulaRegexEnabled())
+    {
+        aDocOpt.SetFormulaRegexEnabled(true);
+        m_pDoc->SetDocOptions(aDocOpt);
+        bOldWildCard = true;
+    }
+
+    m_pDoc->InsertTab(0, "Test1");
+
+    std::vector<std::vector<const char*>> aData = { { "Element", "Relative 
Atomic Mass" },
+                                                    { "Hydrogen", "1.008" },
+                                                    { "Helium", "4.003" },
+                                                    { "Lithium", "6.94" },
+                                                    { "Beryllium", "9.012" },
+                                                    { "Boron", "10.81" },
+                                                    { "Carbon", "12.011" },
+                                                    { "Nitrogen", "14.007" },
+                                                    { "Oxygen", "15.999" },
+                                                    { "Florine", "18.998" },
+                                                    { "Neon", "20.18" } };
+
+    insertRangeData(m_pDoc, ScAddress(0, 0, 0), aData); // A1:B11
+    m_pDoc->SetString(4, 14, 0, "^bo.*"); // E15 - search regex string
+
+    m_pDoc->SetFormula(ScAddress(5, 14, 0), 
"=XLOOKUP(E15;A$2:A$11;B$2:B$11;;2)",
+                       formula::FormulaGrammar::GRAM_NATIVE_UI); // F15
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 10.81
+    // - Actual  : 0
+    CPPUNIT_ASSERT_EQUAL(10.81, m_pDoc->GetValue(5, 14, 0));
+
+    // Switch back to wildcard mode if necessary.
+    if (bOldWildCard)
+    {
+        aDocOpt.SetFormulaWildcardsEnabled(true);
+        m_pDoc->SetDocOptions(aDocOpt);
+    }
+    m_pDoc->DeleteTab(0);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to