4c75f9e
/*
4c75f9e
    Copyright (c) 2014, Lukas Holecek <hluk@email.cz>
4c75f9e
4c75f9e
    This file is part of CopyQ.
4c75f9e
4c75f9e
    CopyQ is free software: you can redistribute it and/or modify
4c75f9e
    it under the terms of the GNU General Public License as published by
4c75f9e
    the Free Software Foundation, either version 3 of the License, or
4c75f9e
    (at your option) any later version.
4c75f9e
4c75f9e
    CopyQ is distributed in the hope that it will be useful,
4c75f9e
    but WITHOUT ANY WARRANTY; without even the implied warranty of
4c75f9e
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c75f9e
    GNU General Public License for more details.
4c75f9e
4c75f9e
    You should have received a copy of the GNU General Public License
4c75f9e
    along with CopyQ.  If not, see <http://www.gnu.org/licenses/>.
4c75f9e
*/
4c75f9e
4c75f9e
#include "itemfakevimtests.h"
4c75f9e
4c75f9e
#include "tests/test_utils.h"
4c75f9e
4c75f9e
#include <QDir>
4c75f9e
4c75f9e
ItemFakeVimTests::ItemFakeVimTests(const TestInterfacePtr &test, QObject *parent)
4c75f9e
    : QObject(parent)
4c75f9e
    , m_test(test)
4c75f9e
{
4c75f9e
}
4c75f9e
4c75f9e
QString ItemFakeVimTests::fileNameToSource()
4c75f9e
{
4c75f9e
    return QDir::tempPath() + "/itemfakevim.rc";
4c75f9e
}
4c75f9e
4c75f9e
void ItemFakeVimTests::initTestCase()
4c75f9e
{
4c75f9e
    TEST(m_test->initTestCase());
4c75f9e
}
4c75f9e
4c75f9e
void ItemFakeVimTests::cleanupTestCase()
4c75f9e
{
4c75f9e
    TEST(m_test->cleanupTestCase());
4c75f9e
}
4c75f9e
4c75f9e
void ItemFakeVimTests::init()
4c75f9e
{
4c75f9e
    TEST(m_test->init());
4c75f9e
4c75f9e
    // Don't use default external editor.
4c75f9e
    RUN("config" << "editor" << "", "\n");
4c75f9e
}
4c75f9e
4c75f9e
void ItemFakeVimTests::cleanup()
4c75f9e
{
4c75f9e
    TEST( m_test->cleanup() );
4c75f9e
}
4c75f9e
4c75f9e
void ItemFakeVimTests::createItem()
4c75f9e
{
4c75f9e
    const QString tab1 = testTab(1);
4c75f9e
    const Args args = Args() << "tab" << tab1;
4c75f9e
4c75f9e
    RUN(args << "size", "0\n");
4c75f9e
4c75f9e
    RUN(args << "edit", "");
4c75f9e
    RUN(args << "keys" << ":iABC" << "ENTER" << ":DEF"
4c75f9e
        << "ESC" << "::wq" << "ENTER", "");
4c75f9e
4c75f9e
    RUN(args << "read" << "0", "ABC\nDEF");
4c75f9e
4c75f9e
    SKIP("Command :w saves item and the editor widget is destroyed because data changed.");
4c75f9e
    RUN(args << "keys" << "F2" << ":GccXYZ" << "ESC" << "::w" << "ENTER", "");
4c75f9e
    RUN(args << "read" << "0", "ABC\nXYZ");
4c75f9e
    RUN(args << "keys" << ":p:wq" << "ENTER", "");
4c75f9e
    RUN(args << "read" << "0", "ABC\nXYZ\nDEF");
4c75f9e
}
4c75f9e
4c75f9e
void ItemFakeVimTests::blockSelection()
4c75f9e
{
4c75f9e
    const QString tab1 = testTab(1);
4c75f9e
    const Args args = Args() << "tab" << tab1;
4c75f9e
4c75f9e
    RUN(args << "edit", "");
4c75f9e
    RUN(args << "keys"
4c75f9e
        << ":iABC" << "ENTER" << ":DEF" << "ENTER" << ":GHI" << "ESC" << "::wq" << "ENTER", "");
4c75f9e
    RUN(args << "read" << "0", "ABC\nDEF\nGHI");
4c75f9e
4c75f9e
    RUN(args << "edit" << "0", "");
4c75f9e
    RUN(args << "keys"
4c75f9e
        << ":ggl" << "CTRL+V" << ":jjs_" << "ESC" << "::wq" << "ENTER", "");
4c75f9e
    RUN(args << "read" << "0", "A_C\nD_F\nG_I");
4c75f9e
}
4c75f9e
4c75f9e
void ItemFakeVimTests::search()
4c75f9e
{
4c75f9e
    const QString tab1 = testTab(1);
4c75f9e
    const Args args = Args() << "tab" << tab1;
4c75f9e
4c75f9e
    RUN(args << "edit", "");
4c75f9e
    RUN(args << "keys"
4c75f9e
        << ":iABC" << "ENTER" << ":DEF" << "ENTER" << ":GHI" << "ESC" << "::wq" << "ENTER", "");
4c75f9e
    RUN(args << "read" << "0", "ABC\nDEF\nGHI");
4c75f9e
4c75f9e
    RUN(args << "edit" << "0", "");
4c75f9e
    RUN(args << "keys"
4c75f9e
        << ":gg/[EH]" << "ENTER" << ":r_nr_" << "F2", "");
4c75f9e
    RUN(args << "read" << "0", "ABC\nD_F\nG_I");
4c75f9e
}