[libcalamares] Expand tests for Variant access
- document that getStringList() also handles strings as 1-element lists
This commit is contained in:
parent
46f2d72b4c
commit
88be947f6c
@ -46,26 +46,27 @@ private Q_SLOTS:
|
|||||||
|
|
||||||
void testCommands();
|
void testCommands();
|
||||||
|
|
||||||
/** @brief Test that all the UMask objects work correctly. */
|
/** @section Test that all the UMask objects work correctly. */
|
||||||
void testUmask();
|
void testUmask();
|
||||||
|
|
||||||
/** @brief Tests the entropy functions. */
|
/** @section Tests the entropy functions. */
|
||||||
void testEntropy();
|
void testEntropy();
|
||||||
void testPrintableEntropy();
|
void testPrintableEntropy();
|
||||||
void testOddSizedPrintable();
|
void testOddSizedPrintable();
|
||||||
|
|
||||||
/** @brief Tests the RAII bits. */
|
/** @section Tests the RAII bits. */
|
||||||
void testBoolSetter();
|
void testBoolSetter();
|
||||||
void testPointerSetter();
|
void testPointerSetter();
|
||||||
|
|
||||||
/** @brief Tests the Traits bits. */
|
/** @section Tests the Traits bits. */
|
||||||
void testTraits();
|
void testTraits();
|
||||||
|
|
||||||
|
/** @section Testing the variants-methods */
|
||||||
void testVariantStringListCode();
|
void testVariantStringListCode();
|
||||||
void testVariantStringListYAMLDashed();
|
void testVariantStringListYAMLDashed();
|
||||||
void testVariantStringListYAMLBracketed();
|
void testVariantStringListYAMLBracketed();
|
||||||
|
|
||||||
/** @brief Test smart string truncation. */
|
/** @section Test smart string truncation. */
|
||||||
void testStringTruncation();
|
void testStringTruncation();
|
||||||
void testStringTruncationShorter();
|
void testStringTruncationShorter();
|
||||||
void testStringTruncationDegenerate();
|
void testStringTruncationDegenerate();
|
||||||
@ -476,17 +477,31 @@ LibCalamaresTests::testVariantStringListCode()
|
|||||||
QCOMPARE( getStringList( m, key ), QStringList {} );
|
QCOMPARE( getStringList( m, key ), QStringList {} );
|
||||||
m.insert( key, 17 );
|
m.insert( key, 17 );
|
||||||
QCOMPARE( getStringList( m, key ), QStringList {} );
|
QCOMPARE( getStringList( m, key ), QStringList {} );
|
||||||
m.insert( key, QString( "more strings" ) );
|
|
||||||
QCOMPARE( getStringList( m, key ),
|
|
||||||
QStringList { "more strings" } ); // A single string **can** be considered a stringlist!
|
|
||||||
m.insert( key, QVariant {} );
|
m.insert( key, QVariant {} );
|
||||||
QCOMPARE( getStringList( m, key ), QStringList {} );
|
QCOMPARE( getStringList( m, key ), QStringList {} );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Things that are stringlists
|
// Things that are **like** stringlists
|
||||||
|
QVariantMap m;
|
||||||
|
m.insert( key, QString( "astring" ) );
|
||||||
|
QCOMPARE( getStringList( m, key ).count(), 1 );
|
||||||
|
QCOMPARE( getStringList( m, key ),
|
||||||
|
QStringList { "astring" } ); // A single string **can** be considered a stringlist!
|
||||||
|
m.insert( key, QString( "more strings" ) );
|
||||||
|
QCOMPARE( getStringList( m, key ).count(), 1 );
|
||||||
|
QCOMPARE( getStringList( m, key ),
|
||||||
|
QStringList { "more strings" } );
|
||||||
|
m.insert( key, QString() );
|
||||||
|
QCOMPARE( getStringList( m, key ).count(), 1 );
|
||||||
|
QCOMPARE( getStringList( m, key ), QStringList { QString() } );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Things that are definitely stringlists
|
||||||
QVariantMap m;
|
QVariantMap m;
|
||||||
m.insert( key, QStringList { "aap", "noot" } );
|
m.insert( key, QStringList { "aap", "noot" } );
|
||||||
|
QCOMPARE( getStringList( m, key ).count(), 2 );
|
||||||
QVERIFY( getStringList( m, key ).contains( "aap" ) );
|
QVERIFY( getStringList( m, key ).contains( "aap" ) );
|
||||||
QVERIFY( !getStringList( m, key ).contains( "mies" ) );
|
QVERIFY( !getStringList( m, key ).contains( "mies" ) );
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,17 @@ namespace CalamaresUtils
|
|||||||
*/
|
*/
|
||||||
DLLEXPORT bool getBool( const QVariantMap& map, const QString& key, bool d = false );
|
DLLEXPORT bool getBool( const QVariantMap& map, const QString& key, bool d = false );
|
||||||
|
|
||||||
/**
|
/** @brief Get a string value from a mapping with a given key; returns @p d if no value.
|
||||||
* Get a string value from a mapping with a given key; returns @p d if no value.
|
*
|
||||||
|
* The value must be an actual string; numbers are not automatically converted to strings,
|
||||||
|
* nor are lists flattened or converted.
|
||||||
*/
|
*/
|
||||||
DLLEXPORT QString getString( const QVariantMap& map, const QString& key, const QString& d = QString() );
|
DLLEXPORT QString getString( const QVariantMap& map, const QString& key, const QString& d = QString() );
|
||||||
|
|
||||||
/**
|
/** @brief Get a string list from a mapping with a given key; returns @p d if no value.
|
||||||
* Get a string list from a mapping with a given key; returns @p d if no value.
|
*
|
||||||
|
* This is slightly more lenient that getString(), and a single-string value will
|
||||||
|
* be returned as a 1-item list.
|
||||||
*/
|
*/
|
||||||
DLLEXPORT QStringList getStringList( const QVariantMap& map, const QString& key, const QStringList& d = QStringList() );
|
DLLEXPORT QStringList getStringList( const QVariantMap& map, const QString& key, const QStringList& d = QStringList() );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user