| 372 | |
| 373 | |
| 374 | void ObjectQueryTest::testParser() |
| 375 | { |
| 376 | ObjectQueryParser p; |
| 377 | |
| 378 | ObjectQuery q = ObjectQuery(ObjectQuery::OperatorSearch, QStringLiteral("1")); |
| 379 | QCOMPARE(p.parse(QStringLiteral("1")), q); |
| 380 | QCOMPARE(p.parse(QStringLiteral("\t \"1\" \t ")), q); |
| 381 | |
| 382 | q = ObjectQuery(QStringLiteral("A"), ObjectQuery::OperatorIs, QStringLiteral("1")); |
| 383 | QCOMPARE(p.parse(QStringLiteral("A = 1")), q); |
| 384 | QCOMPARE(p.parse(QStringLiteral("A = \"1\"")), q); |
| 385 | QCOMPARE(p.parse(QStringLiteral("\"A\" = 1")), q); |
| 386 | QCOMPARE(p.parse(QStringLiteral("\"A\"= 1")), q); |
| 387 | QCOMPARE(p.parse(QStringLiteral(" ( A = 1)\t")), q); |
| 388 | |
| 389 | q = ObjectQuery({ObjectQuery::OperatorSearch, QStringLiteral("1")}, |
| 390 | ObjectQuery::OperatorOr, |
| 391 | {ObjectQuery::OperatorSearch, QStringLiteral("2")}); |
| 392 | QCOMPARE(p.parse(QStringLiteral("1 OR 2")), q); |
| 393 | QCOMPARE(p.parse(QStringLiteral("\"1\" OR 2")), q); |
| 394 | QCOMPARE(p.parse(QStringLiteral("(1 OR \"2\")")), q); |
| 395 | QCOMPARE(p.parse(QStringLiteral("((1) OR (\"2\"))")), q); |
| 396 | |
| 397 | q = ObjectQuery({ObjectQuery::OperatorSearch, QStringLiteral("1")}, |
| 398 | ObjectQuery::OperatorOr, |
| 399 | {{ObjectQuery::OperatorSearch, QStringLiteral("2")}, |
| 400 | ObjectQuery::OperatorAnd, |
| 401 | {ObjectQuery::OperatorSearch, QStringLiteral("3")}}); |
| 402 | QCOMPARE(p.parse(QStringLiteral("1 OR 2 AND 3")), q); |
| 403 | QCOMPARE(p.parse(QStringLiteral("(1 OR 2 AND 3)")), q); |
| 404 | QCOMPARE(p.parse(QStringLiteral("1 OR (\"2\" AND 3)")), q); |
| 405 | |
| 406 | q = ObjectQuery({{ObjectQuery::OperatorSearch, QStringLiteral("1")}, |
| 407 | ObjectQuery::OperatorAnd, |
| 408 | {ObjectQuery::OperatorSearch, QStringLiteral("2")}}, |
| 409 | ObjectQuery::OperatorOr, |
| 410 | {ObjectQuery::OperatorSearch, QStringLiteral("3")}); |
| 411 | QCOMPARE(p.parse(QStringLiteral("1 AND 2 OR 3")), q); |
| 412 | QCOMPARE(p.parse(QStringLiteral("(1 AND 2) OR 3")), q); |
| 413 | |
| 414 | q = ObjectQuery({ObjectQuery::OperatorSearch, QStringLiteral("1")}, |
| 415 | ObjectQuery::OperatorAnd, |
| 416 | {{ObjectQuery::OperatorSearch, QStringLiteral("2")}, |
| 417 | ObjectQuery::OperatorOr, |
| 418 | {ObjectQuery::OperatorSearch, QStringLiteral("3")}}); |
| 419 | QCOMPARE(p.parse(QStringLiteral("1 AND (2 OR 3)")), q); |
| 420 | |
| 421 | QVERIFY(p.parse(QStringLiteral("1 AND (2 OR 3")).getOperator() == ObjectQuery::OperatorInvalid); |
| 422 | QVERIFY(p.parse(QStringLiteral("1 AND (2 OR 3))")).getOperator() == ObjectQuery::OperatorInvalid); |
| 423 | QVERIFY(p.parse(QStringLiteral("(1 AND (2 OR 3)")).getOperator() == ObjectQuery::OperatorInvalid); |
| 424 | |
| 425 | q = p.parse(QStringLiteral("AND 2")); |
| 426 | QVERIFY(q.getOperator() == ObjectQuery::OperatorInvalid); |
| 427 | QCOMPARE(p.errorPos(), 0); |
| 428 | |
| 429 | q = p.parse(QStringLiteral("1 2")); |
| 430 | QVERIFY(q.getOperator() == ObjectQuery::OperatorInvalid); |
| 431 | QCOMPARE(p.errorPos(), 2); |
nothing calls this directly
no test coverage detected