Changeset View
Changeset View
Standalone View
Standalone View
autotests/src/vimode/completion.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | |||||
100 | //END: CodeCompletionInterface | 100 | //END: CodeCompletionInterface | ||
101 | 101 | | |||
102 | //BEGIN: CompletionTest | 102 | //BEGIN: CompletionTest | ||
103 | 103 | | |||
104 | void CompletionTest::FakeCodeCompletionTests() | 104 | void CompletionTest::FakeCodeCompletionTests() | ||
105 | { | 105 | { | ||
106 | // Test that FakeCodeCompletionTestModel behaves similar to the code-completion in e.g. KDevelop. | 106 | // Test that FakeCodeCompletionTestModel behaves similar to the code-completion in e.g. KDevelop. | ||
107 | const bool oldStealKeys = KateViewConfig::global()->viInputModeStealKeys(); | 107 | const bool oldStealKeys = KateViewConfig::global()->viInputModeStealKeys(); | ||
108 | KateViewConfig::global()->setViInputModeStealKeys(true); // For Ctrl-P, Ctrl-N etc | 108 | KateViewConfig::global()->setValue(KateViewConfig::ViInputModeStealKeys, true); // For Ctrl-P, Ctrl-N etc | ||
109 | ensureKateViewVisible(); // KTextEditor::ViewPrivate needs to be visible for the completion widget. | 109 | ensureKateViewVisible(); // KTextEditor::ViewPrivate needs to be visible for the completion widget. | ||
110 | FakeCodeCompletionTestModel *fakeCodeCompletionModel = new FakeCodeCompletionTestModel(kate_view); | 110 | FakeCodeCompletionTestModel *fakeCodeCompletionModel = new FakeCodeCompletionTestModel(kate_view); | ||
111 | kate_view->registerCompletionModel(fakeCodeCompletionModel); | 111 | kate_view->registerCompletionModel(fakeCodeCompletionModel); | ||
112 | fakeCodeCompletionModel->setCompletions({ "completionA", "completionB", "completionC" }); | 112 | fakeCodeCompletionModel->setCompletions({ "completionA", "completionB", "completionC" }); | ||
113 | DoTest("", "i\\ctrl-p\\enter", "completionC"); | 113 | DoTest("", "i\\ctrl-p\\enter", "completionC"); | ||
114 | DoTest("", "i\\ctrl-p\\ctrl-p\\enter", "completionB"); | 114 | DoTest("", "i\\ctrl-p\\ctrl-p\\enter", "completionB"); | ||
115 | DoTest("", "i\\ctrl-p\\ctrl-p\\ctrl-p\\enter", "completionA"); | 115 | DoTest("", "i\\ctrl-p\\ctrl-p\\ctrl-p\\enter", "completionA"); | ||
116 | DoTest("", "i\\ctrl-p\\ctrl-p\\ctrl-p\\ctrl-p\\enter", "completionC"); | 116 | DoTest("", "i\\ctrl-p\\ctrl-p\\ctrl-p\\ctrl-p\\enter", "completionC"); | ||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | |||||
427 | fakeCodeCompletionModel->setCompletions({ "functionCall();" }); | 427 | fakeCodeCompletionModel->setCompletions({ "functionCall();" }); | ||
428 | TestPressKey("ifun\\ctrl- \\enterX"); | 428 | TestPressKey("ifun\\ctrl- \\enterX"); | ||
429 | FinishTest("functionCall();X(<-old bracket"); | 429 | FinishTest("functionCall();X(<-old bracket"); | ||
430 | BeginTest("(<-old bracket"); | 430 | BeginTest("(<-old bracket"); | ||
431 | fakeCodeCompletionModel->setCompletions({ "functionCall(...);" }); | 431 | fakeCodeCompletionModel->setCompletions({ "functionCall(...);" }); | ||
432 | TestPressKey("ifun\\ctrl- \\enterX"); | 432 | TestPressKey("ifun\\ctrl- \\enterX"); | ||
433 | FinishTest("functionCall(X);(<-old bracket"); | 433 | FinishTest("functionCall(X);(<-old bracket"); | ||
434 | 434 | | |||
435 | KateViewConfig::global()->setViInputModeStealKeys(oldStealKeys); | 435 | KateViewConfig::global()->setValue(KateViewConfig::ViInputModeStealKeys, oldStealKeys); | ||
436 | kate_view->hide(); | 436 | kate_view->hide(); | ||
437 | mainWindow->hide(); | 437 | mainWindow->hide(); | ||
438 | kate_view->unregisterCompletionModel(fakeCodeCompletionModel); | 438 | kate_view->unregisterCompletionModel(fakeCodeCompletionModel); | ||
439 | delete fakeCodeCompletionModel; | 439 | delete fakeCodeCompletionModel; | ||
440 | } | 440 | } | ||
441 | 441 | | |||
442 | void CompletionTest::CompletionTests() | 442 | void CompletionTest::CompletionTests() | ||
443 | { | 443 | { | ||
444 | const bool oldRemoveTailOnCompletion = KateViewConfig::global()->wordCompletionRemoveTail(); | 444 | const bool oldRemoveTailOnCompletion = KateViewConfig::global()->wordCompletionRemoveTail(); | ||
445 | // For these tests, assume we don't swallow the tail on completion. | 445 | // For these tests, assume we don't swallow the tail on completion. | ||
446 | KateViewConfig::global()->setWordCompletionRemoveTail(false); | 446 | KateViewConfig::global()->setValue(KateViewConfig::WordCompletionRemoveTail, false); | ||
447 | 447 | | |||
448 | KateViewConfig::global()->setViInputModeStealKeys(true); // For Ctrl-P, Ctrl-N etc | 448 | KateViewConfig::global()->setValue(KateViewConfig::ViInputModeStealKeys, true); // For Ctrl-P, Ctrl-N etc | ||
449 | ensureKateViewVisible(); // KTextEditor::ViewPrivate needs to be visible for the completion widget. | 449 | ensureKateViewVisible(); // KTextEditor::ViewPrivate needs to be visible for the completion widget. | ||
450 | VimCodeCompletionTestModel *testModel = new VimCodeCompletionTestModel(kate_view); | 450 | VimCodeCompletionTestModel *testModel = new VimCodeCompletionTestModel(kate_view); | ||
451 | 451 | | |||
452 | BeginTest(""); | 452 | BeginTest(""); | ||
453 | TestPressKey("i\\ctrl-p"); | 453 | TestPressKey("i\\ctrl-p"); | ||
454 | waitForCompletionWidgetToActivate(); | 454 | waitForCompletionWidgetToActivate(); | ||
455 | TestPressKey("\\return"); | 455 | TestPressKey("\\return"); | ||
456 | FinishTest("completion3"); | 456 | FinishTest("completion3"); | ||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | |||||
549 | QVERIFY(!kate_view->completionWidget()->isCompletionActive()); | 549 | QVERIFY(!kate_view->completionWidget()->isCompletionActive()); | ||
550 | FinishTest("c"); | 550 | FinishTest("c"); | ||
551 | kate_view->unregisterCompletionModel(testModel); | 551 | kate_view->unregisterCompletionModel(testModel); | ||
552 | 552 | | |||
553 | // Check that the repeat-last-change handles Completions in the same way as Macros do | 553 | // Check that the repeat-last-change handles Completions in the same way as Macros do | ||
554 | // i.e. fairly intelligently :) | 554 | // i.e. fairly intelligently :) | ||
555 | FakeCodeCompletionTestModel *fakeCodeCompletionModel = new FakeCodeCompletionTestModel(kate_view); | 555 | FakeCodeCompletionTestModel *fakeCodeCompletionModel = new FakeCodeCompletionTestModel(kate_view); | ||
556 | fakeCodeCompletionModel->setRemoveTailOnComplete(true); | 556 | fakeCodeCompletionModel->setRemoveTailOnComplete(true); | ||
557 | KateViewConfig::global()->setWordCompletionRemoveTail(true); | 557 | KateViewConfig::global()->setValue(KateViewConfig::WordCompletionRemoveTail, true); | ||
558 | kate_view->registerCompletionModel(fakeCodeCompletionModel); | 558 | kate_view->registerCompletionModel(fakeCodeCompletionModel); | ||
559 | clearAllMacros(); | 559 | clearAllMacros(); | ||
560 | BeginTest("funct\nnoa\ncomtail\ncomtail"); | 560 | BeginTest("funct\nnoa\ncomtail\ncomtail"); | ||
561 | fakeCodeCompletionModel->setCompletions({ "completionA", "functionwithargs(...)", "noargfunction()" }); | 561 | fakeCodeCompletionModel->setCompletions({ "completionA", "functionwithargs(...)", "noargfunction()" }); | ||
562 | fakeCodeCompletionModel->setFailTestOnInvocation(false); | 562 | fakeCodeCompletionModel->setFailTestOnInvocation(false); | ||
563 | // Record 'a'. | 563 | // Record 'a'. | ||
564 | TestPressKey("i\\right\\right\\right\\right\\right\\ctrl- \\enterfirstArg"); // Function with args. | 564 | TestPressKey("i\\right\\right\\right\\right\\right\\ctrl- \\enterfirstArg"); // Function with args. | ||
565 | TestPressKey("\\home\\down\\right\\right\\right\\ctrl- \\enter"); // Function no args. | 565 | TestPressKey("\\home\\down\\right\\right\\right\\ctrl- \\enter"); // Function no args. | ||
566 | fakeCodeCompletionModel->setRemoveTailOnComplete(true); | 566 | fakeCodeCompletionModel->setRemoveTailOnComplete(true); | ||
567 | KateViewConfig::global()->setWordCompletionRemoveTail(true); | 567 | KateViewConfig::global()->setValue(KateViewConfig::WordCompletionRemoveTail, true); | ||
568 | TestPressKey("\\home\\down\\right\\right\\right\\ctrl- \\enter"); // Cut off tail. | 568 | TestPressKey("\\home\\down\\right\\right\\right\\ctrl- \\enter"); // Cut off tail. | ||
569 | fakeCodeCompletionModel->setRemoveTailOnComplete(false); | 569 | fakeCodeCompletionModel->setRemoveTailOnComplete(false); | ||
570 | KateViewConfig::global()->setWordCompletionRemoveTail(false); | 570 | KateViewConfig::global()->setValue(KateViewConfig::WordCompletionRemoveTail, false); | ||
571 | TestPressKey("\\home\\down\\right\\right\\right\\ctrl- \\enter\\ctrl-c"); // Don't cut off tail. | 571 | TestPressKey("\\home\\down\\right\\right\\right\\ctrl- \\enter\\ctrl-c"); // Don't cut off tail. | ||
572 | fakeCodeCompletionModel->setRemoveTailOnComplete(true); | 572 | fakeCodeCompletionModel->setRemoveTailOnComplete(true); | ||
573 | KateViewConfig::global()->setWordCompletionRemoveTail(true); | 573 | KateViewConfig::global()->setValue(KateViewConfig::WordCompletionRemoveTail, true); | ||
574 | // Replay. | 574 | // Replay. | ||
575 | fakeCodeCompletionModel->setFailTestOnInvocation(true); | 575 | fakeCodeCompletionModel->setFailTestOnInvocation(true); | ||
576 | kate_document->setText("funct\nnoa\ncomtail\ncomtail"); | 576 | kate_document->setText("funct\nnoa\ncomtail\ncomtail"); | ||
577 | TestPressKey("gg."); | 577 | TestPressKey("gg."); | ||
578 | FinishTest("functionwithargs(firstArg)\nnoargfunction()\ncompletionA\ncompletionAtail"); | 578 | FinishTest("functionwithargs(firstArg)\nnoargfunction()\ncompletionA\ncompletionAtail"); | ||
579 | 579 | | |||
580 | // Clear our log of completions for each change. | 580 | // Clear our log of completions for each change. | ||
581 | BeginTest(""); | 581 | BeginTest(""); | ||
582 | fakeCodeCompletionModel->setCompletions({ "completionA" }); | 582 | fakeCodeCompletionModel->setCompletions({ "completionA" }); | ||
583 | fakeCodeCompletionModel->setFailTestOnInvocation(false); | 583 | fakeCodeCompletionModel->setFailTestOnInvocation(false); | ||
584 | TestPressKey("ciw\\ctrl- \\enter\\ctrl-c"); | 584 | TestPressKey("ciw\\ctrl- \\enter\\ctrl-c"); | ||
585 | fakeCodeCompletionModel->setCompletions({ "completionB" }); | 585 | fakeCodeCompletionModel->setCompletions({ "completionB" }); | ||
586 | TestPressKey("ciw\\ctrl- \\enter\\ctrl-c"); | 586 | TestPressKey("ciw\\ctrl- \\enter\\ctrl-c"); | ||
587 | fakeCodeCompletionModel->setFailTestOnInvocation(true); | 587 | fakeCodeCompletionModel->setFailTestOnInvocation(true); | ||
588 | TestPressKey("."); | 588 | TestPressKey("."); | ||
589 | FinishTest("completionB"); | 589 | FinishTest("completionB"); | ||
590 | 590 | | |||
591 | kate_view->unregisterCompletionModel(fakeCodeCompletionModel); | 591 | kate_view->unregisterCompletionModel(fakeCodeCompletionModel); | ||
592 | delete fakeCodeCompletionModel; | 592 | delete fakeCodeCompletionModel; | ||
593 | KateViewConfig::global()->setWordCompletionRemoveTail(oldRemoveTailOnCompletion); | 593 | KateViewConfig::global()->setValue(KateViewConfig::WordCompletionRemoveTail, oldRemoveTailOnCompletion); | ||
594 | 594 | | |||
595 | // Hide the kate_view for subsequent tests. | 595 | // Hide the kate_view for subsequent tests. | ||
596 | kate_view->hide(); | 596 | kate_view->hide(); | ||
597 | mainWindow->hide(); | 597 | mainWindow->hide(); | ||
598 | } | 598 | } | ||
599 | 599 | | |||
600 | void CompletionTest::waitForCompletionWidgetToActivate() | 600 | void CompletionTest::waitForCompletionWidgetToActivate() | ||
601 | { | 601 | { | ||
Show All 9 Lines |