Debian Codegraph @

src/tests/itemfakevimtests.cpp

raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include "itemfakevimtests.h"
4
5 #include "tests/test_utils.h"
6
7 #include <QDir>
8
9 #ifdef Q_OS_DARWIN
10 #define FAKEVIM_CTRL "META"
11 #else
12 #define FAKEVIM_CTRL "CTRL"
13 #endif
14
15 ItemFakeVimTests::ItemFakeVimTests(const TestInterfacePtr &test, QObject *parent)
16 : QObject(parent)
17 , m_test(test)
18 {
19 setProperty("CopyQ_test_id", QStringLiteral("itemfakevim"));
20 const QVariantMap settings{
21 {QStringLiteral("really_enable"), true},
22 {QStringLiteral("source_file"), QString(ItemFakeVimTests::fileNameToSource())},
23 };
24 setProperty("CopyQ_test_settings", settings);
25 }
26
27 QString ItemFakeVimTests::fileNameToSource()
28 {
29 return QDir::tempPath() + "/itemfakevim.rc";
30 }
31
32 void ItemFakeVimTests::initTestCase()
33 {
34 TEST(m_test->initTestCase());
35 }
36
37 void ItemFakeVimTests::cleanupTestCase()
38 {
39 TEST(m_test->cleanupTestCase());
40 }
41
42 void ItemFakeVimTests::init()
43 {
44 TEST(m_test->init());
45
46 // Don't use default external editor.
47 RUN("config" << "editor" << "", "\n");
48 }
49
50 void ItemFakeVimTests::cleanup()
51 {
52 TEST( m_test->cleanup() );
53 }
54
55 void ItemFakeVimTests::createItem()
56 {
57 const QString tab1 = testTab(1);
58 const Args args = Args() << "tab" << tab1;
59
60 RUN(args << "size", "0\n");
61
62 RUN(args << "edit", "");
63 KEYS(":iABC" << "ENTER" << ":DEF"
64 << "ESC" << "::wq" << "ENTER");
65
66 RUN(args << "read" << "0", "ABC\nDEF");
67
68 KEYS("F2" << ":GccXYZ" << "ESC" << "::w" << "ENTER");
69 RUN(args << "read" << "0", "ABC\nXYZ");
70 KEYS(":p:wq" << "ENTER");
71 RUN(args << "read" << "0", "ABC\nXYZ\nDEF");
72 }
73
74 void ItemFakeVimTests::blockSelection()
75 {
76 const QString tab1 = testTab(1);
77 const Args args = Args() << "tab" << tab1;
78
79 RUN(args << "edit", "");
80 KEYS(":iABC" << "ENTER" << ":DEF" << "ENTER" << ":GHI" << "ESC" << "::wq" << "ENTER");
81 RUN(args << "read" << "0", "ABC\nDEF\nGHI");
82
83 RUN(args << "edit" << "0", "");
84 KEYS(":ggl" << FAKEVIM_CTRL "+V" << ":jjs_" << "ESC" << "::wq" << "ENTER");
85 RUN(args << "read" << "0", "A_C\nD_F\nG_I");
86 }
87
88 void ItemFakeVimTests::search()
89 {
90 const QString tab1 = testTab(1);
91 const Args args = Args() << "tab" << tab1;
92
93 RUN(args << "edit", "");
94 KEYS(":iABC" << "ENTER" << ":DEF" << "ENTER" << ":GHI" << "ESC" << "::wq" << "ENTER");
95 RUN(args << "read" << "0", "ABC\nDEF\nGHI");
96
97 RUN(args << "edit" << "0", "");
98 KEYS(":gg/[EH]" << "ENTER" << ":r_nr_" << "F2");
99 RUN(args << "read" << "0", "ABC\nD_F\nG_I");
100 }
101
102 void ItemFakeVimTests::incDecNumbers()
103 {
104 const QString tab1 = testTab(1);
105 const Args args = Args() << "tab" << tab1;
106
107 RUN(args << "add" << " 0", "");
108 RUN(args << "edit" << "0", "");
109 KEYS(FAKEVIM_CTRL "+a" << "F2");
110 RUN(args << "read" << "0", " 1");
111
112 RUN(args << "add" << " -1", "");
113 RUN(args << "edit" << "0", "");
114 KEYS(FAKEVIM_CTRL "+a" << "F2");
115 RUN(args << "read" << "0", " 0");
116
117 RUN(args << "add" << " 0xff", "");
118 RUN(args << "edit" << "0", "");
119 KEYS(FAKEVIM_CTRL "+a" << "F2");
120 RUN(args << "read" << "0", " 0x100");
121
122 RUN(args << "add" << "9 9 9", "");
123 RUN(args << "edit" << "0", "");
124 KEYS("l" << FAKEVIM_CTRL "+a" << "l" << FAKEVIM_CTRL "+a" << "F2");
125 RUN(args << "read" << "0", "9 10 10");
126
127 RUN(args << "add" << "-1 -1 -1", "");
128 RUN(args << "edit" << "0", "");
129 KEYS(":ll" << "2" << FAKEVIM_CTRL "+a" << "l" << "3" << FAKEVIM_CTRL "+a" << "F2");
130 RUN(args << "read" << "0", "-1 1 2");
131
132 RUN(args << "add" << "1 1 1", "");
133 RUN(args << "edit" << "0", "");
134 KEYS("l" << "2" << FAKEVIM_CTRL "+x" << "l" << "3" << FAKEVIM_CTRL "+x" << "F2");
135 RUN(args << "read" << "0", "1 -1 -2");
136 }