Exemplo n.º 1
0
void tst_ChangeSet::singleMove()
{
    {
        Utils::ChangeSet cs;
        QString test("abcdef");
        QVERIFY(cs.move(0, 2, 4));
        cs.apply(&test);
        QCOMPARE(test, QLatin1String("cdabef"));
    }
    {
        Utils::ChangeSet cs;
        QString test("abcdef");
        QVERIFY(cs.move(4, 6, 0));
        cs.apply(&test);
        QCOMPARE(test, QLatin1String("efabcd"));
    }
    {
        Utils::ChangeSet cs;
        QString test("abcdef");
        QVERIFY(cs.move(3, 13, 0));
        cs.apply(&test);
        QCOMPARE(test, QLatin1String("defabc"));
    }
    {
        Utils::ChangeSet cs;
        QString test("abcdef");
        QVERIFY(cs.move(3, 3, 0));
        cs.apply(&test);
        QCOMPARE(test, QLatin1String("abcdef"));
    }
    {
        Utils::ChangeSet cs;
        QString test("abcdef");
        QVERIFY(cs.move(0, 1, 10));
        cs.apply(&test);
        // ### maybe this should expand the string or error?
        QCOMPARE(test, QLatin1String("bcdef"));
    }
}
Exemplo n.º 2
0
void tst_ChangeSet::conflicts()
{
    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QCOMPARE(cs.replace(0, 2, "abc"), false);
    }
    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QCOMPARE(cs.replace(1, 4, "abc"), false);
    }
    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QCOMPARE(cs.replace(1, 2, "abc"), false);
    }
    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QCOMPARE(cs.replace(2, 2, "abc"), false);
    }
    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QCOMPARE(cs.replace(2, 3, "abc"), false);
    }
    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QCOMPARE(cs.replace(3, 3, "abc"), false);
    }
    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QCOMPARE(cs.replace(3, 4, "abc"), false);
    }
    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QCOMPARE(cs.replace(4, 6, "abc"), false);
    }

    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QVERIFY(cs.replace(0, 1, "bla"));
        QString test("abcdef");
        cs.apply(&test);
        QCOMPARE(test, QLatin1String("blaebcdf"));
    }
    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QVERIFY(cs.replace(4, 5, "bla"));
        QString test("abcdef");
        cs.apply(&test);
        QCOMPARE(test, QLatin1String("ablabcdf"));
    }
    {
        Utils::ChangeSet cs;
        QVERIFY(cs.move(1, 4, 5));
        QVERIFY(cs.replace(5, 6, "bla"));
        QString test("abcdef");
        cs.apply(&test);
        QCOMPARE(test, QLatin1String("aebcdbla"));
    }
}