コード例 #1
0
void
Test_KCompletion::substringCompletion_Weighted()
{
	KCompletion completion;
	completion.setSoundsEnabled(false);
	completion.setCompletionMode(KGlobalSettings::CompletionAuto);

	completion.setOrder(KCompletion::Weighted);
	completion.setItems(wstrings);
	QVERIFY(completion.items().count() == 4);

	QStringList matches = completion.substringCompletion("c");
	QVERIFY(matches.count() == 4);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], clampet);
	QCOMPARE(matches[2], coolcat);
	QCOMPARE(matches[3], carp);

	matches = completion.substringCompletion("ca");
	QVERIFY(matches.count() == 3);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], coolcat);
	QCOMPARE(matches[2], carp);

	matches = completion.substringCompletion("car");
	QVERIFY(matches.count() == 2);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], carp);

	matches = completion.substringCompletion("pet");
	QVERIFY(matches.count() == 2);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], clampet);
}
コード例 #2
0
void
Test_KCompletion::substringCompletion_Insertion()
{
    KCompletion completion;
    completion.setSoundsEnabled(false);
    completion.setCompletionMode(KCompletion::CompletionAuto);

    completion.setOrder(KCompletion::Insertion);
    completion.setItems(strings);
    QVERIFY(completion.items().count() == 4);

    QStringList matches = completion.substringCompletion(QStringLiteral("c"));
    QVERIFY(matches.count() == 4);
    QCOMPARE(matches[0], clampet);
    QCOMPARE(matches[1], coolcat);
    QCOMPARE(matches[2], carpet);
    QCOMPARE(matches[3], carp);

    matches = completion.substringCompletion(QStringLiteral("ca"));
    QVERIFY(matches.count() == 3);
    QCOMPARE(matches[0], coolcat);
    QCOMPARE(matches[1], carpet);
    QCOMPARE(matches[2], carp);

    matches = completion.substringCompletion(QStringLiteral("car"));
    QVERIFY(matches.count() == 2);
    QCOMPARE(matches[0], carpet);
    QCOMPARE(matches[1], carp);

    matches = completion.substringCompletion(QStringLiteral("pet"));
    QVERIFY(matches.count() == 2);
    QCOMPARE(matches[0], clampet);
    QCOMPARE(matches[1], carpet);
}
コード例 #3
0
void
Test_KCompletion::weightedOrder()
{
	KCompletion completion;
	completion.setSoundsEnabled(false);
	QSignalSpy spy1(&completion, SIGNAL(match(QString)));
	QSignalSpy spy3(&completion, SIGNAL(multipleMatches()));

	completion.setOrder(KCompletion::Weighted);
	QVERIFY(completion.order() == KCompletion::Weighted);

	completion.setItems(wstrings);
	QVERIFY(completion.items().count() == 4);

	completion.setCompletionMode(KGlobalSettings::CompletionShell);
	QCOMPARE(completion.makeCompletion("ca"), QString("carp"));
	spy1.takeFirst(); // empty the list
	QVERIFY(spy3.count() == 1); spy3.takeFirst();

	QSignalSpy spy2(&completion, SIGNAL(matches(QStringList)));
	completion.makeCompletion("ca");
	QCOMPARE(spy2.count(), 1);
	QVERIFY(spy3.count() == 0); // shouldn't be signaled on 2nd call

	QStringList matches = spy2.takeFirst().at(0).toStringList();
	QVERIFY(matches.count() == 2);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], carp);

	completion.setCompletionMode(KGlobalSettings::CompletionAuto);
	QCOMPARE(completion.makeCompletion("ca"), carpet);

	matches = completion.substringCompletion("ca");
	QVERIFY(matches.count() == 3);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], coolcat);
	QCOMPARE(matches[2], carp);
}