File: itemfakevimtests.cpp

package info (click to toggle)
copyq 13.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,964 kB
  • sloc: cpp: 63,306; sh: 992; xml: 452; python: 293; ruby: 152; makefile: 27; javascript: 25
file content (134 lines) | stat: -rw-r--r-- 3,694 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// SPDX-License-Identifier: GPL-3.0-or-later

#include "itemfakevimtests.h"

#include "tests/test_utils.h"

#include <QDir>

#ifdef Q_OS_DARWIN
#define FAKEVIM_CTRL "META"
#else
#define FAKEVIM_CTRL "CTRL"
#endif

ItemFakeVimTests::ItemFakeVimTests(const TestInterfacePtr &test, QObject *parent)
    : QObject(parent)
    , m_test(test)
{
}

QString ItemFakeVimTests::fileNameToSource()
{
    return QDir::tempPath() + "/itemfakevim.rc";
}

void ItemFakeVimTests::initTestCase()
{
    TEST(m_test->initTestCase());
}

void ItemFakeVimTests::cleanupTestCase()
{
    TEST(m_test->cleanupTestCase());
}

void ItemFakeVimTests::init()
{
    TEST(m_test->init());

    // Don't use default external editor.
    RUN("config" << "editor" << "", "\n");
}

void ItemFakeVimTests::cleanup()
{
    TEST( m_test->cleanup() );
}

void ItemFakeVimTests::createItem()
{
    const QString tab1 = testTab(1);
    const Args args = Args() << "tab" << tab1;

    RUN(args << "size", "0\n");

    RUN(args << "edit", "");
    RUN(args << "keys" << ":iABC" << "ENTER" << ":DEF"
        << "ESC" << "::wq" << "ENTER", "");

    RUN(args << "read" << "0", "ABC\nDEF");

    RUN(args << "keys" << "F2" << ":GccXYZ" << "ESC" << "::w" << "ENTER", "");
    RUN(args << "read" << "0", "ABC\nXYZ");
    RUN(args << "keys" << ":p:wq" << "ENTER", "");
    RUN(args << "read" << "0", "ABC\nXYZ\nDEF");
}

void ItemFakeVimTests::blockSelection()
{
    const QString tab1 = testTab(1);
    const Args args = Args() << "tab" << tab1;

    RUN(args << "edit", "");
    RUN(args << "keys"
        << ":iABC" << "ENTER" << ":DEF" << "ENTER" << ":GHI" << "ESC" << "::wq" << "ENTER", "");
    RUN(args << "read" << "0", "ABC\nDEF\nGHI");

    RUN(args << "edit" << "0", "");
    RUN(args << "keys"
        << ":ggl" << FAKEVIM_CTRL "+V" << ":jjs_" << "ESC" << "::wq" << "ENTER", "");
    RUN(args << "read" << "0", "A_C\nD_F\nG_I");
}

void ItemFakeVimTests::search()
{
    const QString tab1 = testTab(1);
    const Args args = Args() << "tab" << tab1;

    RUN(args << "edit", "");
    RUN(args << "keys"
        << ":iABC" << "ENTER" << ":DEF" << "ENTER" << ":GHI" << "ESC" << "::wq" << "ENTER", "");
    RUN(args << "read" << "0", "ABC\nDEF\nGHI");

    RUN(args << "edit" << "0", "");
    RUN(args << "keys"
        << ":gg/[EH]" << "ENTER" << ":r_nr_" << "F2", "");
    RUN(args << "read" << "0", "ABC\nD_F\nG_I");
}

void ItemFakeVimTests::incDecNumbers()
{
    const QString tab1 = testTab(1);
    const Args args = Args() << "tab" << tab1;

    RUN(args << "add" << " 0", "");
    RUN(args << "edit" << "0", "");
    RUN(args << "keys" << FAKEVIM_CTRL "+a" << "F2", "");
    RUN(args << "read" << "0", " 1");

    RUN(args << "add" << " -1", "");
    RUN(args << "edit" << "0", "");
    RUN(args << "keys" << FAKEVIM_CTRL "+a" << "F2", "");
    RUN(args << "read" << "0", " 0");

    RUN(args << "add" << " 0xff", "");
    RUN(args << "edit" << "0", "");
    RUN(args << "keys" << FAKEVIM_CTRL "+a" << "F2", "");
    RUN(args << "read" << "0", " 0x100");

    RUN(args << "add" << "9 9 9", "");
    RUN(args << "edit" << "0", "");
    RUN(args << "keys" << "l" << FAKEVIM_CTRL "+a" << "l" << FAKEVIM_CTRL "+a" << "F2", "");
    RUN(args << "read" << "0", "9 10 10");

    RUN(args << "add" << "-1 -1 -1", "");
    RUN(args << "edit" << "0", "");
    RUN(args << "keys" << ":ll" << "2" << FAKEVIM_CTRL "+a" << "l" << "3" << FAKEVIM_CTRL "+a" << "F2", "");
    RUN(args << "read" << "0", "-1 1 2");

    RUN(args << "add" << "1 1 1", "");
    RUN(args << "edit" << "0", "");
    RUN(args << "keys" << "l" << "2" << FAKEVIM_CTRL "+x" << "l" << "3" << FAKEVIM_CTRL "+x" << "F2", "");
    RUN(args << "read" << "0", "1 -1 -2");
}