Skip to content

Commit 624ac70

Browse files
committed
Add array_filter tests
1 parent 81587e1 commit 624ac70

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tests/src/core/testqgsexpression.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,9 @@ class TestQgsExpression: public QObject
26912691
foreachExpected << QStringLiteral( "ABC" ) << QStringLiteral( "HELLO" );
26922692
QCOMPARE( QgsExpression( "array_foreach(array('abc', 'hello'), upper(@element))" ).evaluate( &context ), QVariant( foreachExpected ) );
26932693

2694+
QVariantList filterExpected() << QStringLiteral( "A: a" ) << QStringLiteral( "A: d" );
2695+
QCOMPARE( QgsExpression( "array_filter(array('A: a', 'B: b', 'C: c', 'A: d'), substr(@element, 1, 2) = 'A:')" ).evaluate( &context ), QVariant( filterExpected ) );
2696+
26942697
QCOMPARE( QgsExpression( "array_intersect(array('1', '2', '3', '4'), array('4', '0', '2', '5'))" ).evaluate( &context ), QVariant( true ) );
26952698
QCOMPARE( QgsExpression( "array_intersect(array('1', '2', '3', '4'), array('0', '5'))" ).evaluate( &context ), QVariant( false ) );
26962699

@@ -2774,6 +2777,9 @@ class TestQgsExpression: public QObject
27742777
foreachExpected << 10 << 20 << 40;
27752778
QCOMPARE( QgsExpression( "array_foreach(array(1, 2, 4), @element * 10)" ).evaluate( &context ), QVariant( foreachExpected ) );
27762779

2780+
QVariantList filterExpected() << 1 << 2;
2781+
QCOMPARE( QgsExpression( "array_filter(array(1, 2, 4), @element < 3)" ).evaluate( &context ), QVariant( filterExpected ) );
2782+
27772783
QgsExpression badArray( QStringLiteral( "array_get('not an array', 0)" ) );
27782784
QCOMPARE( badArray.evaluate( &context ), QVariant() );
27792785
QVERIFY( badArray.hasEvalError() );

0 commit comments

Comments
 (0)