Beispiel #1
0
void
Test_KCompletion::sortedOrder()
{
	KCompletion completion;
	completion.setSoundsEnabled(false);
	QSignalSpy spy1(&completion, SIGNAL(match(QString)));
	QSignalSpy spy3(&completion, SIGNAL(multipleMatches()));

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

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

	completion.setCompletionMode(KGlobalSettings::CompletionShell);
	QCOMPARE(completion.makeCompletion("ca"), QString("carp"));
	QVERIFY(spy1.count() == 1);
	QCOMPARE(spy1.takeFirst().at(0).toString(), QString("carp"));
	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], carp);
	QCOMPARE(matches[1], carpet);

	completion.setCompletionMode(KGlobalSettings::CompletionAuto);
	QCOMPARE(completion.makeCompletion("ca"), carp);
	QVERIFY(spy1.count() == 1);
	QCOMPARE(spy1.takeFirst().at(0).toString(), carp);
}
Beispiel #2
0
void
Test_KCompletion::allMatches_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.allMatches("c");
	QVERIFY(matches.count() == 4);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], clampet);
	QCOMPARE(matches[2], coolcat);
	QCOMPARE(matches[3], carp);

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

	matches = completion.allMatches("pet");
	QVERIFY(matches.count() == 0);
}
Beispiel #3
0
void
Test_KCompletion::isEmpty()
{
	KCompletion completion;
	QVERIFY(completion.isEmpty());
	QVERIFY(completion.items().isEmpty());
}
Beispiel #4
0
void
Test_KCompletion::substringCompletion_Insertion()
{
	KCompletion completion;
	completion.setSoundsEnabled(false);
	completion.setCompletionMode(KGlobalSettings::CompletionAuto);

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

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

	matches = completion.substringCompletion("ca");
	QVERIFY(matches.count() == 3);
	QCOMPARE(matches[0], coolcat);
	QCOMPARE(matches[1], carpet);
	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], clampet);
	QCOMPARE(matches[1], carpet);
}
void
Test_KCompletion::allMatches_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.allMatches(QStringLiteral("c"));
    QVERIFY(matches.count() == 4);
    QCOMPARE(matches[0], clampet);
    QCOMPARE(matches[1], coolcat);
    QCOMPARE(matches[2], carpet);
    QCOMPARE(matches[3], carp);

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

    matches = completion.allMatches(QStringLiteral("pet"));
    QVERIFY(matches.count() == 0);
}
void
Test_KCompletion::substringCompletion_Weighted()
{
    KCompletion completion;
    completion.setSoundsEnabled(false);
    completion.setCompletionMode(KCompletion::CompletionAuto);

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

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

    matches = completion.substringCompletion(QStringLiteral("ca"));
    QVERIFY(matches.count() == 3);
    QCOMPARE(matches[0], carpet);
    QCOMPARE(matches[1], coolcat);
    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], carpet);
    QCOMPARE(matches[1], clampet);
}
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(KCompletion::CompletionShell);
    QCOMPARE(completion.makeCompletion(QStringLiteral("ca")), QStringLiteral("carp"));
    spy1.takeFirst(); // empty the list
    QVERIFY(spy3.count() == 1); spy3.takeFirst();

    QSignalSpy spy2(&completion, SIGNAL(matches(QStringList)));
    completion.makeCompletion(QStringLiteral("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(KCompletion::CompletionAuto);
    QCOMPARE(completion.makeCompletion(QStringLiteral("ca")), carpet);

    matches = completion.substringCompletion(QStringLiteral("ca"));
    QVERIFY(matches.count() == 3);
    QCOMPARE(matches[0], carpet);
    QCOMPARE(matches[1], coolcat);
    QCOMPARE(matches[2], carp);
}
void ConsoleDockWidget::executeCommand( const QString &_commandString )
{
    if ( _commandString.isEmpty() ) {
        kDebug() << "No command given";
        return;
    }

    Project *project = m_projectModel->activeProject();
    if ( !project ) {
        kDebug() << "No active project";
        return;
    }

    setState( EvaluatingResult );

    // Check if the command string ends with a '\'. If it does, add the command to the current
    // multiline command and wait for more input. If not, check if there are entered multiline
    // command lines.
    QString commandString = _commandString;
    if ( commandString.endsWith('\\') ) {
        const QString correctedCommandString = commandString.left( commandString.length() - 1 );
        if ( m_enteredMultilineCommandLines.isEmpty() ) {
            // Write first line of a multiline command to console
            appendToConsole( QString("<b> &gt; %1</b>").arg(encodeInput(correctedCommandString)) );
        } else {
            // Write following line of a multiline command to console
            appendToConsole( QString("<b>   %1</b>").arg(encodeInput(correctedCommandString)) );
        }
        m_enteredMultilineCommandLines << correctedCommandString;
        setState( WaitingForInput );
        return;
    } else if ( !m_enteredMultilineCommandLines.isEmpty() ) {
        // Write last line of a multiline command to console
        appendToConsole( QString("<b>   %1</b>").arg(encodeInput(commandString)) );

        // Prepend already entered lines
        commandString.prepend( m_enteredMultilineCommandLines.join("\n") + '\n' );
        m_enteredMultilineCommandLines.clear();
    } else {
        // Write executed command to console
        appendToConsole( QString("<b> &gt; %1</b>").arg(encodeInput(commandString)) );
    }

    // Store executed command in history (use up/down keys)
    if ( m_consoleHistory.isEmpty() || m_consoleHistory.first() != commandString ) {
        m_consoleHistory.prepend( commandString );
    }
    m_consoleHistoryIndex = -1;

    // Add executed command to completion object
    KCompletion *completion = m_commandLineEdit->completionObject();
    if ( !completion->items().contains(commandString) ) {
        completion->addItem( commandString );
    }

    // Check if commandString contains a command of the form ".<command> ..."
    Debugger::ConsoleCommand command = Debugger::ConsoleCommand::fromString( commandString );
    if ( command.isValid() )  {
        if ( command.command() == ConsoleCommand::ClearCommand ) {
            // The clear command cannot be executed in the debugger,
            // simply clear the console history here
            m_consoleWidget->clear();
            setState( WaitingForInput );
        } else {
            // Execute the command
            project->debugger()->executeCommand( command );
        }
    } else {
        // No command given, execute string as script code
        project->debugger()->evaluateInContext( commandString,
                                                i18nc("@info/plain", "Console Command (%1)", commandString) );
    }
}