ucalc_copypaste: improve readability and shorten

Desktop / LibreOffice - scito [scito.ch] - 14 June 2021 09:25 UTC

The tests are written in a simpler and shorter way. (The same, but 858 lines less.) I've transformed the code with several regex in VSCode. I've made a manual clean up at the end.

The regex are listed below in the form



search regex

replace regex



aString = m_pDoc->GetString\((\d+,\s*\d+,\s*\w+)\); \s*CPPUNIT_ASSERT_EQUAL\(OUString\("(.*)"\), aString\);

CPPUNIT_ASSERT_EQUAL(OUString("$2"), m_pDoc->GetString($1));



m_pDoc->GetFormula\((\d+, \d+, \w+), \w+\); \s*CPPUNIT_ASSERT_EQUAL\(OUString\("(.*)"\), \w+\);

CPPUNIT_ASSERT_EQUAL(OUString("$2"), getFormula($1));



m_pDoc->GetFormula\((\d+, \d+, \w+), \w+\); \s*CPPUNIT_ASSERT_EQUAL_MESSAGE\("(.+)", OUString\("(.+)"\), \w+\);

CPPUNIT_ASSERT_EQUAL_MESSAGE("$2", OUString("$3"), getFormula($1));



ScAddress \w+\((\d+, \d+, \d+)\);(\s*//.+)? \s*ScPostIt\* \w+ = m_pDoc->GetOrCreateNote\(\w+\); \s*\w+->SetText\(\w+, "(.*)"\);

setNote($1, "$3");$2



ScAddress (\w+)\((\d+, \d+, \d+)\);(\s*//.+)? \s*ScPostIt\* \w+ = m_pDoc->GetOrCreateNote\(\w+\); \s*\w+->SetText\(\w+, "(.*)"\);

ScAddress $1 = setNote($2, "$4");$3



ScAddress (\w+)\((\d+, \d+, \w+)\);(\s*//.+)? \s*ScPostIt\* \w+ = m_pDoc->GetOrCreateNote\(\w+\); \s*\w+->SetText\(\w+, "(.*)"\);

setNote($2, "$4");$3



m_pDoc->GetNote\(ScAddress\((\d+, \d+, (\d+|\w+))\)\)

m_pDoc->GetNote($1)



"There should be(\s+\w+) note on (\w+)

"$2:$1 note



HasNote\(ScAddress\((\d+, \d+, (\d+|\w+))\)\)

HasNote($1)



ASSERT_DOUBLES_EQUAL\((-?\d+),

CPPUNIT_ASSERT_EQUAL($1.0,



\w+ = m_pDoc->GetString\((\d+, \d+, (\d+|\w+))\); \s*CPPUNIT_ASSERT_EQUAL\(EMPTY_OUSTRING, \w+\);

CPPUNIT_ASSERT_EQUAL(EMPTY_OUSTRING, m_pDoc->GetString());



\w+ = m_pDoc->GetString\((\d+, \d+, (\d+|\w+))\);(\s*//.*)? \s*CPPUNIT_ASSERT_EQUAL_MESSAGE\("(.+)", EMPTY_OUSTRING, \w+\);

CPPUNIT_ASSERT_EQUAL_MESSAGE("$4", EMPTY_OUSTRING, m_pDoc->GetString($2));$3



fValue = m_pDoc->GetValue\((\d+, \d+, (\d+|\w+))\);(\s*//.*)? \s*ASSERT_DOUBLES_EQUAL_MESSAGE\("(.*)", (-?\d+), fValue\);

CPPUNIT_ASSERT_EQUAL_MESSAGE("$4", $5.0, m_pDoc->GetValue($1));



fValue = m_pDoc->GetValue\((\d+, \d+, (\d+|\w+))\);(\s*//.*)? \s*CPPUNIT_ASSERT_EQUAL\((-?\d+(\.0)?), fValue\);

CPPUNIT_ASSERT_EQUAL($4, m_pDoc->GetValue($1));$3



m_pDoc->GetFormula\((\d+, \d+, \w+), \w+\);(\s*//.*)? \s*CPPUNIT_ASSERT_EQUAL_MESSAGE\("(.+)", OUString\("(.+)"\), \w+\);

CPPUNIT_ASSERT_EQUAL_MESSAGE("$3", OUString("$4"), getFormula($1));



aStr = m_pDoc->GetString\((\d+, \d+, \w+)\);(\s*//.*)? \s*CPPUNIT_ASSERT_EQUAL_MESSAGE\("(.*)", OUString\("(.*)"\), aStr\);

CPPUNIT_ASSERT_EQUAL_MESSAGE("$3", OUString("$4"), m_pDoc->GetString($1));



m_pDoc->GetNote\((\d+, \d+, (\d+|\w+))\)->GetText\(\)

getNote($1)



Change-Id: I4000b7f89a0bee1d2d52abfd6c1b055470e39d02 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117085

213a6792990d ucalc_copypaste: improve readability and shorten
sc/qa/unit/ucalc_copypaste.cxx | 4234 ++++++++++++++++------------------------
1 file changed, 1688 insertions(+), 2546 deletions(-)

Upstream: cgit.freedesktop.org


  • Share