tests/auto/qregexp/tst_qregexp.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   626     QCOMPARE(rx6.cap(2), QString(""));
   626     QCOMPARE(rx6.cap(2), QString(""));
   627 
   627 
   628     QRegExp rx7("([A-Za-z_])([A-Za-z_0-9]*)");
   628     QRegExp rx7("([A-Za-z_])([A-Za-z_0-9]*)");
   629     rx7.setCaseSensitivity(Qt::CaseSensitive);
   629     rx7.setCaseSensitivity(Qt::CaseSensitive);
   630     rx7.setPatternSyntax(QRegExp::RegExp);
   630     rx7.setPatternSyntax(QRegExp::RegExp);
   631     QCOMPARE(rx7.numCaptures(), 2);
   631     QCOMPARE(rx7.captureCount(), 2);
   632 
   632 
   633     int pos = rx7.indexIn("(10 + delta4) * 32");
   633     int pos = rx7.indexIn("(10 + delta4) * 32");
   634     QCOMPARE(pos, 6);
   634     QCOMPARE(pos, 6);
   635     QCOMPARE(rx7.matchedLength(), 6);
   635     QCOMPARE(rx7.matchedLength(), 6);
   636     QCOMPARE(rx7.cap(0), QString("delta4"));
   636     QCOMPARE(rx7.cap(0), QString("delta4"));
  1175     QRegExp rx1(rx0);
  1175     QRegExp rx1(rx0);
  1176 
  1176 
  1177     QCOMPARE(rx1.capturedTexts(), QStringList() << "" << "" << "" << "");
  1177     QCOMPARE(rx1.capturedTexts(), QStringList() << "" << "" << "" << "");
  1178     QCOMPARE(rx1.matchedLength(), -1);
  1178     QCOMPARE(rx1.matchedLength(), -1);
  1179     QCOMPARE(rx1.matchedLength(), -1);
  1179     QCOMPARE(rx1.matchedLength(), -1);
  1180     QCOMPARE(rx1.numCaptures(), 3);
  1180     QCOMPARE(rx1.captureCount(), 3);
  1181 
  1181 
  1182     QCOMPARE(rx1.exactMatch("foo"), true);
  1182     QCOMPARE(rx1.exactMatch("foo"), true);
  1183     QCOMPARE(rx1.matchedLength(), 3);
  1183     QCOMPARE(rx1.matchedLength(), 3);
  1184     QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o");
  1184     QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o");
  1185     QCOMPARE(rx1.numCaptures(), 3);
  1185     QCOMPARE(rx1.captureCount(), 3);
  1186     QCOMPARE(rx1.matchedLength(), 3);
  1186     QCOMPARE(rx1.matchedLength(), 3);
  1187     QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o");
  1187     QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o");
  1188     QCOMPARE(rx1.pos(3), 2);
  1188     QCOMPARE(rx1.pos(3), 2);
  1189 
  1189 
  1190     QCOMPARE(rx1.exactMatch("foo"), true);
  1190     QCOMPARE(rx1.exactMatch("foo"), true);
  1191     QCOMPARE(rx1.numCaptures(), 3);
  1191     QCOMPARE(rx1.captureCount(), 3);
  1192     QCOMPARE(rx1.matchedLength(), 3);
  1192     QCOMPARE(rx1.matchedLength(), 3);
  1193     QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o");
  1193     QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o");
  1194     QCOMPARE(rx1.pos(3), 2);
  1194     QCOMPARE(rx1.pos(3), 2);
  1195 
  1195 
  1196     QRegExp rx2 = rx1;
  1196     QRegExp rx2 = rx1;
  1197 
  1197 
  1198     QCOMPARE(rx1.numCaptures(), 3);
  1198     QCOMPARE(rx1.captureCount(), 3);
  1199     QCOMPARE(rx1.matchedLength(), 3);
  1199     QCOMPARE(rx1.matchedLength(), 3);
  1200     QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o");
  1200     QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o");
  1201     QCOMPARE(rx1.pos(3), 2);
  1201     QCOMPARE(rx1.pos(3), 2);
  1202 
  1202 
  1203     QCOMPARE(rx2.numCaptures(), 3);
  1203     QCOMPARE(rx2.captureCount(), 3);
  1204     QCOMPARE(rx2.matchedLength(), 3);
  1204     QCOMPARE(rx2.matchedLength(), 3);
  1205     QCOMPARE(rx2.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o");
  1205     QCOMPARE(rx2.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o");
  1206     QCOMPARE(rx2.pos(3), 2);
  1206     QCOMPARE(rx2.pos(3), 2);
  1207 
  1207 
  1208     QCOMPARE(rx1.exactMatch("fo"), true);
  1208     QCOMPARE(rx1.exactMatch("fo"), true);
  1209     QCOMPARE(rx1.numCaptures(), 3);
  1209     QCOMPARE(rx1.captureCount(), 3);
  1210     QCOMPARE(rx1.matchedLength(), 2);
  1210     QCOMPARE(rx1.matchedLength(), 2);
  1211     QCOMPARE(rx1.capturedTexts(), QStringList() << "fo" << "f" << "o" << "");
  1211     QCOMPARE(rx1.capturedTexts(), QStringList() << "fo" << "f" << "o" << "");
  1212     QCOMPARE(rx1.pos(2), 1);
  1212     QCOMPARE(rx1.pos(2), 1);
  1213 #if 0
  1213 #if 0
  1214     QCOMPARE(rx1.pos(3), -1); // ###
  1214     QCOMPARE(rx1.pos(3), -1); // ###
  1243     QVERIFY(rx11.exactMatch("]["));
  1243     QVERIFY(rx11.exactMatch("]["));
  1244     QCOMPARE(rx11.matchedLength(), 2);
  1244     QCOMPARE(rx11.matchedLength(), 2);
  1245 
  1245 
  1246     rx11.setPatternSyntax(QRegExp::Wildcard);
  1246     rx11.setPatternSyntax(QRegExp::Wildcard);
  1247     QVERIFY(!rx11.isValid());
  1247     QVERIFY(!rx11.isValid());
  1248     QCOMPARE(rx11.numCaptures(), 0);
  1248     QCOMPARE(rx11.captureCount(), 0);
  1249     QCOMPARE(rx11.matchedLength(), -1);
  1249     QCOMPARE(rx11.matchedLength(), -1);
  1250 
  1250 
  1251     rx11.setPatternSyntax(QRegExp::RegExp);
  1251     rx11.setPatternSyntax(QRegExp::RegExp);
  1252     QVERIFY(!rx11.isValid());
  1252     QVERIFY(!rx11.isValid());
  1253     QCOMPARE(rx11.numCaptures(), 0);
  1253     QCOMPARE(rx11.captureCount(), 0);
  1254     QCOMPARE(rx11.matchedLength(), -1);
  1254     QCOMPARE(rx11.matchedLength(), -1);
  1255 
  1255 
  1256     rx11.setPattern("(foo)");
  1256     rx11.setPattern("(foo)");
  1257     QVERIFY(rx11.isValid());
  1257     QVERIFY(rx11.isValid());
  1258     QCOMPARE(rx11.numCaptures(), 1);
  1258     QCOMPARE(rx11.captureCount(), 1);
  1259     QCOMPARE(rx11.matchedLength(), -1);
  1259     QCOMPARE(rx11.matchedLength(), -1);
  1260 
  1260 
  1261     QCOMPARE(rx11.indexIn("ofoo"), 1);
  1261     QCOMPARE(rx11.indexIn("ofoo"), 1);
  1262     QCOMPARE(rx11.numCaptures(), 1);
  1262     QCOMPARE(rx11.captureCount(), 1);
  1263     QCOMPARE(rx11.matchedLength(), 3);
  1263     QCOMPARE(rx11.matchedLength(), 3);
  1264 
  1264 
  1265     rx11.setPatternSyntax(QRegExp::RegExp);
  1265     rx11.setPatternSyntax(QRegExp::RegExp);
  1266     QCOMPARE(rx11.numCaptures(), 1);
  1266     QCOMPARE(rx11.captureCount(), 1);
  1267     QCOMPARE(rx11.matchedLength(), 3);
  1267     QCOMPARE(rx11.matchedLength(), 3);
  1268 
  1268 
  1269     /*
  1269     /*
  1270         This behavior isn't entirely consistent with setPatter(),
  1270         This behavior isn't entirely consistent with setPatter(),
  1271         setPatternSyntax(), and setCaseSensitivity(), but I'm testing
  1271         setPatternSyntax(), and setCaseSensitivity(), but I'm testing
  1276     QCOMPARE(rx11.matchedLength(), 3);
  1276     QCOMPARE(rx11.matchedLength(), 3);
  1277     rx11.setMinimal(false);
  1277     rx11.setMinimal(false);
  1278     QCOMPARE(rx11.matchedLength(), 3);
  1278     QCOMPARE(rx11.matchedLength(), 3);
  1279 
  1279 
  1280     rx11.setPatternSyntax(QRegExp::Wildcard);
  1280     rx11.setPatternSyntax(QRegExp::Wildcard);
  1281     QCOMPARE(rx11.numCaptures(), 0);
  1281     QCOMPARE(rx11.captureCount(), 0);
  1282     QCOMPARE(rx11.matchedLength(), -1);
  1282     QCOMPARE(rx11.matchedLength(), -1);
  1283 
  1283 
  1284     rx11.setPatternSyntax(QRegExp::RegExp);
  1284     rx11.setPatternSyntax(QRegExp::RegExp);
  1285     QCOMPARE(rx11.numCaptures(), 1);
  1285     QCOMPARE(rx11.captureCount(), 1);
  1286     QCOMPARE(rx11.matchedLength(), -1);
  1286     QCOMPARE(rx11.matchedLength(), -1);
  1287 }
  1287 }
  1288 
  1288 
  1289 void tst_QRegExp::operator_eq()
  1289 void tst_QRegExp::operator_eq()
  1290 {
  1290 {