tests/auto/qregexp/tst_qregexp.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 37 758a864f9613
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   100     void rainersSlowRegExpCopyBug();
   100     void rainersSlowRegExpCopyBug();
   101     void nonExistingBackReferenceBug();
   101     void nonExistingBackReferenceBug();
   102 
   102 
   103     void reentrancy();
   103     void reentrancy();
   104     void threadsafeEngineCache();
   104     void threadsafeEngineCache();
       
   105 
       
   106     void QTBUG_7049_data();
       
   107     void QTBUG_7049();
   105 };
   108 };
   106 
   109 
   107 // Testing get/set functions
   110 // Testing get/set functions
   108 void tst_QRegExp::getSetCheck()
   111 void tst_QRegExp::getSetCheck()
   109 {
   112 {
  1331             QCOMPARE(rxtable[i] != rxtable[j], i / ELL != j / ELL);
  1334             QCOMPARE(rxtable[i] != rxtable[j], i / ELL != j / ELL);
  1332         }
  1335         }
  1333     }
  1336     }
  1334 }
  1337 }
  1335 
  1338 
       
  1339 void tst_QRegExp::QTBUG_7049_data()
       
  1340 {
       
  1341     QTest::addColumn<QString>("reStr");
       
  1342     QTest::addColumn<QString>("text");
       
  1343     QTest::addColumn<int>("matchIndex");
       
  1344 
       
  1345     QTest::addColumn<int>("pos0");
       
  1346     QTest::addColumn<int>("pos1");
       
  1347     QTest::addColumn<int>("pos2");
       
  1348 
       
  1349     QTest::addColumn<QString>("cap0");
       
  1350     QTest::addColumn<QString>("cap1");
       
  1351     QTest::addColumn<QString>("cap2");
       
  1352 
       
  1353     QTest::newRow("no match")
       
  1354         << QString("(a) (b)") << QString("b a") << -1
       
  1355         << -1 << -1 << -1 << QString() << QString() << QString();
       
  1356 
       
  1357     QTest::newRow("both captures match")
       
  1358         << QString("(a) (b)") << QString("a b") << 0
       
  1359         << 0 << 0 << 2 << QString("a b") << QString("a") << QString("b");
       
  1360 
       
  1361     QTest::newRow("first capture matches @0")
       
  1362         << QString("(a*)|(b*)") << QString("axx") << 0
       
  1363         << 0 << 0 << -1 << QString("a") << QString("a") << QString();
       
  1364     QTest::newRow("second capture matches @0")
       
  1365         << QString("(a*)|(b*)") << QString("bxx") << 0
       
  1366         << 0 << -1 << 0 << QString("b") << QString() << QString("b");
       
  1367     QTest::newRow("first capture empty match @0")
       
  1368         << QString("(a*)|(b*)") << QString("xx") << 0
       
  1369         << 0 << -1 << -1 << QString("") << QString() << QString();
       
  1370     QTest::newRow("second capture empty match @0")
       
  1371         << QString("(a)|(b*)") << QString("xx") << 0
       
  1372         << 0 << -1 << -1 << QString("") << QString() << QString();
       
  1373 
       
  1374     QTest::newRow("first capture matches @1")
       
  1375         << QString("x(?:(a*)|(b*))") << QString("-xa") << 1
       
  1376         << 1 << 2 << -1 << QString("xa") << QString("a") << QString();
       
  1377     QTest::newRow("second capture matches @1")
       
  1378         << QString("x(?:(a*)|(b*))") << QString("-xb") << 1
       
  1379         << 1 << -1 << 2 << QString("xb") << QString() << QString("b");
       
  1380     QTest::newRow("first capture empty match @1")
       
  1381         << QString("x(?:(a*)|(b*))") << QString("-xx") << 1
       
  1382         << 1 << -1 << -1 << QString("x") << QString() << QString();
       
  1383     QTest::newRow("second capture empty match @1")
       
  1384         << QString("x(?:(a)|(b*))") << QString("-xx") << 1
       
  1385         << 1 << -1 << -1 << QString("x") << QString() << QString();
       
  1386 
       
  1387     QTest::newRow("first capture matches @2")
       
  1388         << QString("(a)|(b)") << QString("xxa") << 2
       
  1389         << 2 << 2 << -1 << QString("a") << QString("a") << QString();
       
  1390     QTest::newRow("second capture matches @2")
       
  1391         << QString("(a)|(b)") << QString("xxb") << 2
       
  1392         << 2 << -1 << 2 << QString("b") << QString() << QString("b");
       
  1393     QTest::newRow("no match - with options")
       
  1394         << QString("(a)|(b)") << QString("xx") << -1
       
  1395         << -1 << -1 << -1 << QString() << QString() << QString();
       
  1396 
       
  1397 }
       
  1398 
       
  1399 void tst_QRegExp::QTBUG_7049()
       
  1400 {
       
  1401     QFETCH( QString, reStr );
       
  1402     QFETCH( QString, text );
       
  1403     QFETCH( int, matchIndex );
       
  1404     QFETCH( int, pos0 );
       
  1405     QFETCH( int, pos1 );
       
  1406     QFETCH( int, pos2 );
       
  1407     QFETCH( QString, cap0 );
       
  1408     QFETCH( QString, cap1 );
       
  1409     QFETCH( QString, cap2 );
       
  1410 
       
  1411     QRegExp re(reStr);
       
  1412     QCOMPARE(re.numCaptures(), 2);
       
  1413     QCOMPARE(re.capturedTexts().size(), 3);
       
  1414 
       
  1415     QCOMPARE(re.indexIn(text), matchIndex);
       
  1416 
       
  1417     QCOMPARE( re.pos(0), pos0 );
       
  1418     QCOMPARE( re.pos(1), pos1 );
       
  1419     QCOMPARE( re.pos(2), pos2 );
       
  1420 
       
  1421     QCOMPARE( re.cap(0).isNull(), cap0.isNull() );
       
  1422     QCOMPARE( re.cap(0), cap0 );
       
  1423     QCOMPARE( re.cap(1).isNull(), cap1.isNull() );
       
  1424     QCOMPARE( re.cap(1), cap1 );
       
  1425     QCOMPARE( re.cap(2).isNull(), cap2.isNull() );
       
  1426     QCOMPARE( re.cap(2), cap2 );
       
  1427 }
       
  1428 
  1336 QTEST_APPLESS_MAIN(tst_QRegExp)
  1429 QTEST_APPLESS_MAIN(tst_QRegExp)
  1337 #include "tst_qregexp.moc"
  1430 #include "tst_qregexp.moc"