[libcalamares] Extend tests of string-truncation
This commit is contained in:
parent
67e96d2ce6
commit
3623e9aefc
@ -66,6 +66,7 @@ private Q_SLOTS:
|
|||||||
|
|
||||||
/** @brief Test smart string truncation. */
|
/** @brief Test smart string truncation. */
|
||||||
void testStringTruncation();
|
void testStringTruncation();
|
||||||
|
void testStringTruncationShorter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void recursiveCompareMap( const QVariantMap& a, const QVariantMap& b, int depth );
|
void recursiveCompareMap( const QVariantMap& a, const QVariantMap& b, int depth );
|
||||||
@ -573,11 +574,41 @@ LibCalamaresTests::testStringTruncation()
|
|||||||
auto firsttwo = truncateMultiLine( s, LinesStartEnd { 2, 0 }, CharCount { sufficientLength } );
|
auto firsttwo = truncateMultiLine( s, LinesStartEnd { 2, 0 }, CharCount { sufficientLength } );
|
||||||
auto lasttwo = truncateMultiLine( s, LinesStartEnd { 0, 2 }, CharCount { sufficientLength } );
|
auto lasttwo = truncateMultiLine( s, LinesStartEnd { 0, 2 }, CharCount { sufficientLength } );
|
||||||
QCOMPARE( firsttwo + lasttwo, s );
|
QCOMPARE( firsttwo + lasttwo, s );
|
||||||
|
QCOMPARE( firsttwo.count( '\n' ), 2 );
|
||||||
QVERIFY( longString.startsWith( firsttwo ) );
|
QVERIFY( longString.startsWith( firsttwo ) );
|
||||||
QVERIFY( longString.endsWith( lasttwo ) );
|
QVERIFY( longString.endsWith( lasttwo ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LibCalamaresTests::testStringTruncationShorter()
|
||||||
|
{
|
||||||
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
||||||
|
|
||||||
|
using namespace CalamaresUtils;
|
||||||
|
|
||||||
|
const QString longString( R"(Some strange string artifacts appeared, leading to `{1?}` being
|
||||||
|
displayed in various user-facing messages. These have been removed
|
||||||
|
and the translations updated.)" );
|
||||||
|
const char NEWLINE = '\n';
|
||||||
|
|
||||||
|
const int insufficientLength = 42;
|
||||||
|
// There's 2 newlines in all, no trailing newline
|
||||||
|
QVERIFY( !longString.endsWith( NEWLINE ) );
|
||||||
|
QCOMPARE( longString.count( NEWLINE ), 2 );
|
||||||
|
QVERIFY( longString.length() > insufficientLength );
|
||||||
|
|
||||||
|
// Grab first line, untruncated
|
||||||
|
{
|
||||||
|
|
||||||
|
auto s = truncateMultiLine( longString, LinesStartEnd { 1, 0 } );
|
||||||
|
QVERIFY( s.length() > 1 );
|
||||||
|
QVERIFY( longString.startsWith( s ) );
|
||||||
|
QVERIFY( s.endsWith( NEWLINE ) );
|
||||||
|
QVERIFY( s.endsWith( "being\n" ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN( LibCalamaresTests )
|
QTEST_GUILESS_MAIN( LibCalamaresTests )
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user