File indexing completed on 2024-05-12 15:45:15
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2014 Miquel Sabaté Solà <mikisabate@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "modes.h" 0009 #include <inputmode/kateviinputmode.h> 0010 #include <katebuffer.h> 0011 #include <kateconfig.h> 0012 #include <katedocument.h> 0013 #include <kateview.h> 0014 #include <vimode/emulatedcommandbar/emulatedcommandbar.h> 0015 0016 using namespace KTextEditor; 0017 0018 QTEST_MAIN(ModesTest) 0019 0020 // BEGIN: Normal mode. 0021 0022 void ModesTest::NormalMotionsTests() 0023 { 0024 // Test moving around an empty document (nothing should happen) 0025 DoTest("", "jkhl", ""); 0026 DoTest("", "ggG$0", ""); 0027 0028 // Testing "l" 0029 DoTest("bar", "lx", "br"); 0030 DoTest("bar", "2lx", "ba"); 0031 DoTest("0123456789012345", "13lx", "012345678901245"); 0032 DoTest("bar", "10lx", "ba"); 0033 0034 // Testing "h" 0035 DoTest("bar", "llhx", "br"); 0036 DoTest("bar", "10l10hx", "ar"); 0037 DoTest("0123456789012345", "13l10hx", "012456789012345"); 0038 DoTest("bar", "ll5hx", "ar"); 0039 0040 // Testing "j" 0041 DoTest("bar\nbar", "jx", "bar\nar"); 0042 DoTest("bar\nbar", "10jx", "bar\nar"); 0043 DoTest("bar\nbara", "lljx", "bar\nbaa"); 0044 DoTest("0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n1\n2\n3\n4\n5\n", "13jx", "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n1\n2\n\n4\n5\n"); 0045 0046 // Testing "k" 0047 DoTest("bar\nbar", "jx", "bar\nar"); 0048 DoTest("bar\nbar\nbar", "jj100kx", "ar\nbar\nbar"); 0049 DoTest("0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n1\n2\n3\n4\n5\n", "13j10kx", "0\n1\n2\n\n4\n5\n6\n7\n8\n9\n0\n1\n2\n3\n4\n5\n"); 0050 0051 // Testing "w" 0052 DoTest("bar", "wx", "ba"); 0053 DoTest("foo bar", "wx", "foo ar"); 0054 DoTest("foo bar", "lwx", "foo ar"); 0055 DoTest("quux(foo, bar, baz);", "wxwxwxwx2wx", "quuxfoo ar baz;"); 0056 DoTest("foo\nbar\nbaz", "wxwx", "foo\nar\naz"); 0057 DoTest("1 2 3\n4 5 6", "ld3w", "1\n4 5 6"); 0058 DoTest("foo\nbar baz", "gU2w", "FOO\nBAR baz"); 0059 DoTest("FOO\nBAR BAZ", "gu2w", "foo\nbar BAZ"); 0060 DoTest("bar(\n123", "llwrX", "barX\n123"); 0061 0062 // Testing "W" 0063 DoTest("bar", "Wx", "ba"); 0064 DoTest("foo bar", "Wx", "foo ar"); 0065 DoTest("foo bar", "2lWx", "foo ar"); 0066 DoTest("quux(foo, bar, baz);", "WxWx", "quux(foo, ar, az);"); 0067 DoTest("foo\nbar\nbaz", "WxWx", "foo\nar\naz"); 0068 DoTest(" foo(bar xyz", "Wx", " oo(bar xyz"); 0069 0070 // Testing "b" 0071 DoTest("bar", "lbx", "ar"); 0072 DoTest("foo bar baz", "2wbx", "foo ar baz"); 0073 DoTest("foo bar", "w20bx", "oo bar"); 0074 DoTest("quux(foo, bar, baz);", "2W4l2bx2bx", "quux(foo, ar, az);"); 0075 DoTest("foo\nbar\nbaz", "WWbx", "foo\nar\nbaz"); 0076 DoTest(" foo", "lbrX", "X foo"); 0077 DoTest(" foo", "llbrX", "X foo"); 0078 0079 // Testing "B" 0080 DoTest("bar", "lBx", "ar"); 0081 DoTest("foo bar baz", "2wBx", "foo ar baz"); 0082 DoTest("foo bar", "w20Bx", "oo bar"); 0083 DoTest("quux(foo, bar, baz);", "2W4lBBx", "quux(foo, ar, baz);"); 0084 DoTest("foo\nbar", "WlBx", "foo\nar"); 0085 0086 // Testing "e" 0087 DoTest("quux(foo, bar, baz);", "exex2ex10ex", "quu(fo, bar baz)"); 0088 DoTest("", "ce", ""); 0089 DoTest(" ", "lceX", "X"); 0090 DoTest("", "cE", ""); 0091 0092 // Testing "E" 0093 DoTest("quux(foo, bar, baz);", "ExEx10Ex", "quux(foo bar baz)"); 0094 0095 // Testing "$" 0096 DoTest("foo\nbar\nbaz", "$x3$x", "fo\nbar\nba"); 0097 0098 // Testing "0" 0099 DoTest(" foo", "$0x", "foo"); 0100 0101 // Testing "#" & "*" 0102 DoTest("1 1 1", "2#x", "1 1"); 0103 DoTest("foo bar foo bar", "#xlll#x", "foo ar oo bar"); 0104 DoTest("(foo (bar (foo( bar))))", "#xll#x", "(foo (ar (oo( bar))))"); 0105 DoTest("(foo (bar (foo( bar))))", "*x", "(foo (bar (oo( bar))))"); 0106 DoTest("foo bar foobar foo", "*rX", "foo bar foobar Xoo"); // Whole word only. 0107 DoTest("foo bar foobar foo", "$#rX", "Xoo bar foobar foo"); // Whole word only. 0108 DoTest("fOo foo fOo", "*rX", "fOo Xoo fOo"); // Case insensitive. 0109 DoTest("fOo foo fOo", "$#rX", "fOo Xoo fOo"); // Case insensitive. 0110 DoTest("fOo foo fOo", "*ggnrX", "fOo Xoo fOo"); // Flag that the search to repeat is case insensitive. 0111 DoTest("fOo foo fOo", "$#ggNrX", "fOo Xoo fOo"); // Flag that the search to repeat is case insensitive. 0112 DoTest("bar foo", "$*rX", "bar Xoo"); 0113 DoTest("bar foo", "$#rX", "bar Xoo"); 0114 // Test that calling # on the last, blank line of a document does not go into an infinite loop. 0115 DoTest("foo\n", "j#", "foo\n"); 0116 0117 // Testing "-" 0118 DoTest("0\n1\n2\n3\n4\n5", "5j-x2-x", "0\n1\n\n3\n\n5"); 0119 DoTest("foo\n\t \t bar\nbaz", "3j-r.", "foo\n\t \t .ar\nbaz"); 0120 0121 // Testing "^" 0122 DoTest(" foo bar", "$^x", " oo bar"); 0123 0124 // Testing "gg" 0125 DoTest("1\n2\n3\n4\n5", "4jggx", "\n2\n3\n4\n5"); 0126 0127 // Testing "G" 0128 DoTest("1\n2\n3\n4\n5", "Gx", "1\n2\n3\n4\n"); 0129 0130 // Testing "ge" 0131 DoTest("quux(foo, bar, baz);", "9lgexgex$gex", "quux(fo bar, ba);"); 0132 DoTest("foo", "llgerX", "Xoo"); 0133 DoTest(" foo", "$gerX", "X foo"); 0134 DoTest(" foo foo", "$2gerX", "X foo foo"); 0135 0136 // Testing "gE" 0137 DoTest("quux(foo, bar, baz);", "9lgExgEx$gEx", "quux(fo bar baz);"); 0138 DoTest(" foo", "$gErX", "X foo"); 0139 DoTest(" foo foo", "$2gErX", "X foo foo"); 0140 DoTest(" !foo$!\"", "$gErX", "X !foo$!\""); 0141 DoTest(" !foo$!\"", "$2gErX", "X !foo$!\""); 0142 0143 // Testing "|" 0144 DoTest("123456789", "3|rx4|rx8|rx1|rx", "x2xx567x9"); 0145 0146 // Testing "`" 0147 DoTest("foo\nbar\nbaz", "lmaj`arx", "fxo\nbar\nbaz"); 0148 0149 // Testing "'" 0150 DoTest("foo\nbar\nbaz", "lmaj'arx", "xoo\nbar\nbaz"); 0151 0152 // Testing "%" 0153 DoTest("foo{\n}\n", "$d%", "foo\n"); 0154 DoTest("FOO{\nBAR}BAZ", "lllgu%", "FOO{\nbar}BAZ"); 0155 DoTest("foo{\nbar}baz", "lllgU%", "foo{\nBAR}baz"); 0156 DoTest("foo{\nbar\n}", "llly%p", "foo{{\nbar\n}\nbar\n}"); 0157 // Regression bug for test where yanking with % would actually move the cursor. 0158 DoTest("a()", "y%x", "()"); 0159 // Regression test for the bug I added fixing the bug above ;) 0160 DoTest("foo(bar)", "y%P", "foo(bar)foo(bar)"); 0161 // Regression test for adjacent brackets 0162 DoTest("foo((bar)baz)", "y%P", "foo((bar)baz)foo((bar)baz)"); 0163 // Regression test for "empty" bracket ranges 0164 DoTest("()123", "%%llx", "()23"); 0165 0166 // Testing percentage "<N>%" 0167 DoTest("10%\n20%\n30%\n40%\n50%\n60%\n70%\n80%\n90%\n100%", "20%dd", "10%\n30%\n40%\n50%\n60%\n70%\n80%\n90%\n100%"); 0168 0169 DoTest("10%\n20%\n30%\n40%\n50%\n60%\n70%\n80%\n90%\n100%", "50%dd", "10%\n20%\n30%\n40%\n60%\n70%\n80%\n90%\n100%"); 0170 0171 DoTest("10%\n20%\n30%\n40%\n50%\n60%\n70\n80%\n90%\n100%", "65%dd", "10%\n20%\n30%\n40%\n50%\n60%\n80%\n90%\n100%"); 0172 0173 DoTest("10%\n20%\n30%\n40%\n50%\n60%\n70%\n80%\n90%\n100%", "5j10%dd", "20%\n30%\n40%\n50%\n60%\n70%\n80%\n90%\n100%"); 0174 0175 // ctrl-left and ctrl-right. 0176 DoTest("foo bar xyz", "\\ctrl-\\rightrX", "foo Xar xyz"); 0177 DoTest("foo bar xyz", "$\\ctrl-\\leftrX", "foo bar Xyz"); 0178 0179 // Enter / Return / "+" 0180 DoTest("foo\n\t \t bar", "\\enterr.", "foo\n\t \t .ar"); 0181 DoTest("foo\n\t \t bar", "\\returnr.", "foo\n\t \t .ar"); 0182 DoTest("foo\n\t \t bar", "+r.", "foo\n\t \t .ar"); 0183 0184 // TEXT OBJECTS 0185 DoTest("foo \"bar baz ('first', 'second' or 'third')\"", "8w2lci'", "foo \"bar baz ('first', '' or 'third')\""); 0186 0187 DoTest("foo \"bar baz ('first', 'second' or 'third')\"", "8w2lca'", "foo \"bar baz ('first', or 'third')\""); 0188 0189 DoTest("foo \"bar baz ('first', 'second' or 'third')\"", "8w2lci(", "foo \"bar baz ()\""); 0190 0191 DoTest("foo \"bar baz ('first', 'second' or 'third')\"", "8w2lci(", "foo \"bar baz ()\""); 0192 0193 DoTest("foo \"bar baz ('first', 'second' or 'third')\"", "8w2lcib", "foo \"bar baz ()\""); 0194 // Quick test that bracket object works in visual mode. 0195 DoTest("foo \"bar baz ('first', 'second' or 'third')\"", "8w2lvibd", "foo \"bar baz ()\""); 0196 DoTest("foo \"bar baz ('first', 'second' or 'third')\"", "8w2lvabd", "foo \"bar baz \""); 0197 0198 DoTest("foo \"bar baz ('first', 'second' or 'third')\"", "8w2lca)", "foo \"bar baz \""); 0199 0200 DoTest("foo \"bar baz ('first', 'second' or 'third')\"", "8w2lci\"", "foo \"\""); 0201 0202 DoTest("foo \"bar baz ('first', 'second' or 'third')\"", "8w2lda\"", "foo "); 0203 0204 DoTest("foo \"bar [baz ({'first', 'second'} or 'third')]\"", "9w2lci[", "foo \"bar []\""); 0205 0206 DoTest("foo \"bar [baz ({'first', 'second'} or 'third')]\"", "9w2lci]", "foo \"bar []\""); 0207 0208 DoTest("foo \"bar [baz ({'first', 'second'} or 'third')]\"", "9w2lca[", "foo \"bar \""); 0209 0210 DoTest("foo \"bar [baz ({'first', 'second'} or 'third')]\"", "9w2lci{", "foo \"bar [baz ({} or 'third')]\""); 0211 0212 DoTest("foo \"bar [baz ({'first', 'second'} or 'third')]\"", "7w2lca}", "foo \"bar [baz ( or 'third')]\""); 0213 0214 DoTest("{foo { bar { (baz) \"asd\" }} {1} {2} {3} {4} {5} }", "ldiB", "{}"); 0215 0216 // Inner/ A Word. 0217 DoTest("", "diw", ""); 0218 DoTest(" ", "diw", ""); 0219 DoTest(" ", "diw", ""); 0220 DoTest("foo", "daw", ""); 0221 DoTest("foo", "ldaw", ""); 0222 DoTest("foo", "cawxyz\\esc", "xyz"); 0223 DoTest("foo bar baz", "daw", "bar baz"); 0224 DoTest("foo bar baz", "cawxyz\\esc", "xyzbar baz"); 0225 DoTest("foo bar baz", "wdaw", "foo baz"); 0226 DoTest("foo bar baz", "wldaw", "foo baz"); 0227 DoTest("foo bar baz", "wlldaw", "foo baz"); 0228 DoTest("foo bar baz", "wcawxyz\\esc", "foo xyzbaz"); 0229 DoTest("foo bar baz", "wwdaw", "foo bar"); 0230 DoTest("foo bar baz ", "wwdaw", "foo bar "); 0231 DoTest("foo bar baz", "wwcawxyz\\esc", "foo barxyz"); 0232 DoTest("foo bar baz\n123", "jdaw", "foo bar baz\n"); 0233 DoTest("foo bar baz\n123", "jcawxyz\\esc", "foo bar baz\nxyz"); 0234 DoTest("foo bar baz\n123", "wwdaw", "foo bar\n123"); 0235 DoTest("foo bar baz\n123", "wwcawxyz\\esc", "foo barxyz\n123"); 0236 DoTest("foo bar baz\n123", "wwdaw", "foo bar\n123"); 0237 DoTest("foo bar baz\n123", "wwcawxyz\\esc", "foo barxyz\n123"); 0238 DoTest("foo bar baz \n123", "wwdaw", "foo bar \n123"); 0239 DoTest("foo bar baz \n123", "wwcawxyz\\esc", "foo bar xyz\n123"); 0240 DoTest("foo bar baz \n123", "wwdaw", "foo bar \n123"); 0241 DoTest("foo bar baz \n123", "wwcawxyz\\esc", "foo bar xyz\n123"); 0242 DoTest("foo bar", "llldaw", "foo"); 0243 DoTest("foo bar", "lllcawxyz\\esc", "fooxyz"); 0244 DoTest("foo bar", "lllldaw", "foo"); 0245 DoTest("foo bar", "llllcawxyz\\esc", "fooxyz"); 0246 DoTest(" bar", "daw", ""); 0247 DoTest(" bar", "ldaw", ""); 0248 DoTest(" bar", "llldaw", ""); 0249 DoTest(" bar", "lllldaw", " "); 0250 DoTest(" bar", "cawxyz\\esc", "xyz"); 0251 DoTest(" bar", "lcawxyz\\esc", "xyz"); 0252 DoTest(" bar", "lllcawxyz\\esc", "xyz"); 0253 DoTest("foo ", "llldaw", "foo "); 0254 DoTest("foo ", "lllldaw", "foo "); 0255 DoTest("foo ", "llllldaw", "foo "); 0256 DoTest("foo ", "lllcawxyz\\esc", "foo "); 0257 DoTest("foo ", "llllcawxyz\\esc", "foo "); 0258 DoTest("foo ", "lllllcawxyz\\esc", "foo "); 0259 DoTest("foo \nbar", "llldaw", "foo"); 0260 DoTest("foo \nbar", "lllldaw", "foo"); 0261 DoTest("foo \nbar", "llllldaw", "foo"); 0262 DoTest("foo \nbar", "lllcawxyz\\esc", "fooxyz"); 0263 DoTest("foo \nbar", "llllcawxyz\\esc", "fooxyz"); 0264 DoTest("foo \nbar", "lllllcawxyz\\esc", "fooxyz"); 0265 DoTest("foo \n bar", "jdaw", "foo \n"); 0266 DoTest("foo \n bar", "jldaw", "foo \n"); 0267 DoTest("foo \n bar", "jlldaw", "foo \n"); 0268 DoTest("foo \n bar", "jcawxyz\\esc", "foo \nxyz"); 0269 DoTest("foo \n bar", "jlcawxyz\\esc", "foo \nxyz"); 0270 DoTest("foo \n bar", "jllcawxyz\\esc", "foo \nxyz"); 0271 DoTest("foo bar", "2daw", ""); 0272 DoTest("foo bar", "2cawxyz\\esc", "xyz"); 0273 DoTest("foo bar baz", "2daw", "baz"); 0274 DoTest("foo bar baz", "2cawxyz\\esc", "xyzbaz"); 0275 DoTest("foo bar baz", "3daw", ""); 0276 DoTest("foo bar baz", "3cawxyz\\esc", "xyz"); 0277 DoTest("foo bar\nbaz", "2daw", "\nbaz"); 0278 DoTest("foo bar\nbaz", "2cawxyz\\esc", "xyz\nbaz"); 0279 DoTest("foo bar\nbaz 123", "3daw", "123"); 0280 DoTest("foo bar\nbaz 123", "3cawxyz\\esc", "xyz123"); 0281 DoTest("foo bar \nbaz 123", "3daw", "123"); 0282 DoTest("foo bar \nbaz 123", "3cawxyz\\esc", "xyz123"); 0283 DoTest("foo bar baz", "lll2daw", "foo"); 0284 DoTest("foo bar baz", "lll2cawxyz\\esc", "fooxyz"); 0285 DoTest(" bar baz", "2daw", ""); 0286 DoTest(" bar baz", "2cawxyz\\esc", "xyz"); 0287 DoTest(" bar baz 123", "2daw", " 123"); 0288 DoTest(" bar baz 123", "2cawxyz\\esc", "xyz 123"); 0289 DoTest(" bar baz\n123", "3daw", ""); 0290 DoTest(" bar baz\n123", "3cawxyz\\esc", "xyz"); 0291 DoTest(" bar baz\n 123", "3daw", ""); 0292 DoTest(" bar baz\n 123", "3cawxyz\\esc", "xyz"); 0293 DoTest(" bar baz\n 123", "2daw", "\n 123"); 0294 DoTest(" bar baz\n 123", "2cawxyz\\esc", "xyz\n 123"); 0295 DoTest(" bar baz\n 123 456 789", "j2daw", " bar baz\n 789"); 0296 DoTest(" bar baz\n 123 456 789", "j2cawxyz\\esc", " bar baz\nxyz 789"); 0297 DoTest("foo\nbar\n", "2daw", ""); 0298 DoTest("bar baz\n123 \n456\n789 abc \njkl", "j4daw", "bar baz\njkl"); 0299 DoTest("bar baz\n123 \n456\n789 abc \njkl", "j4cawxyz\\esc", "bar baz\nxyzjkl"); 0300 DoTest(" bar baz\n 123 \n456\n789 abc \njkl", "j4daw", " bar baz\njkl"); 0301 DoTest(" bar baz\n 123 456 789", "j2cawxyz\\esc", " bar baz\nxyz 789"); 0302 DoTest("foo b123r xyz", "wdaw", "foo xyz"); 0303 DoTest("foo b123r xyz", "wldaw", "foo xyz"); 0304 DoTest("foo b123r xyz", "wlldaw", "foo xyz"); 0305 DoTest("foo b123r xyz", "wllldaw", "foo xyz"); 0306 DoTest("foo b123r xyz", "wlllldaw", "foo xyz"); 0307 DoTest("1 2 3 4 5 6", "daw", "2 3 4 5 6"); 0308 DoTest("1 2 3 4 5 6", "ldaw", "1 3 4 5 6"); 0309 DoTest("1 2 3 4 5 6", "lldaw", "1 3 4 5 6"); 0310 DoTest("1 2 3 4 5 6", "llldaw", "1 2 4 5 6"); 0311 DoTest("!foo!", "ldaw", "!!"); 0312 DoTest("! foo !", "ldaw", "! !"); 0313 DoTest("! foo !", "lldaw", "! !"); 0314 DoTest("! foo (", "l2daw", "!"); 0315 DoTest("! foo(\n123", "l2daw", "!\n123"); 0316 DoTest(" !foo(\n123", "lll2daw", " !\n123"); 0317 DoTest(" !!foo(\n123", "llll2daw", " !!\n123"); 0318 DoTest(" !foo( \n123", "lll2daw", " !\n123"); 0319 DoTest(" !!!!(", "llldaw", " "); 0320 DoTest(" !!!!(", "lll2daw", " !!!!("); 0321 DoTest(" !!!!(\n!!!", "lll2daw", ""); 0322 DoTest(" !!!!(\n!!!", "llll2daw", ""); 0323 0324 // Inner/ A WORD 0325 // Behave the same as a Word if there are no non-word chars. 0326 DoTest("", "diW", ""); 0327 DoTest(" ", "diW", ""); 0328 DoTest(" ", "diW", ""); 0329 DoTest("foo", "daW", ""); 0330 DoTest("foo", "ldaW", ""); 0331 DoTest("foo", "caWxyz\\esc", "xyz"); 0332 DoTest("foo bar baz", "daW", "bar baz"); 0333 DoTest("foo bar baz", "caWxyz\\esc", "xyzbar baz"); 0334 DoTest("foo bar baz", "wdaW", "foo baz"); 0335 DoTest("foo bar baz", "wldaW", "foo baz"); 0336 DoTest("foo bar baz", "wlldaW", "foo baz"); 0337 DoTest("foo bar baz", "wcaWxyz\\esc", "foo xyzbaz"); 0338 DoTest("foo bar baz", "wwdaW", "foo bar"); 0339 DoTest("foo bar baz ", "wwdaW", "foo bar "); 0340 DoTest("foo bar baz", "wwcaWxyz\\esc", "foo barxyz"); 0341 DoTest("foo bar baz\n123", "jdaW", "foo bar baz\n"); 0342 DoTest("foo bar baz\n123", "jcaWxyz\\esc", "foo bar baz\nxyz"); 0343 DoTest("foo bar baz\n123", "wwdaW", "foo bar\n123"); 0344 DoTest("foo bar baz\n123", "wwcaWxyz\\esc", "foo barxyz\n123"); 0345 DoTest("foo bar baz\n123", "wwdaW", "foo bar\n123"); 0346 DoTest("foo bar baz\n123", "wwcaWxyz\\esc", "foo barxyz\n123"); 0347 DoTest("foo bar baz \n123", "wwdaW", "foo bar \n123"); 0348 DoTest("foo bar baz \n123", "wwcaWxyz\\esc", "foo bar xyz\n123"); 0349 DoTest("foo bar baz \n123", "wwdaW", "foo bar \n123"); 0350 DoTest("foo bar baz \n123", "wwcaWxyz\\esc", "foo bar xyz\n123"); 0351 DoTest("foo bar", "llldaW", "foo"); 0352 DoTest("foo bar", "lllcaWxyz\\esc", "fooxyz"); 0353 DoTest("foo bar", "lllldaW", "foo"); 0354 DoTest("foo bar", "llllcaWxyz\\esc", "fooxyz"); 0355 DoTest(" bar", "daW", ""); 0356 DoTest(" bar", "ldaW", ""); 0357 DoTest(" bar", "llldaW", ""); 0358 DoTest(" bar", "lllldaW", " "); 0359 DoTest(" bar", "caWxyz\\esc", "xyz"); 0360 DoTest(" bar", "lcaWxyz\\esc", "xyz"); 0361 DoTest(" bar", "lllcaWxyz\\esc", "xyz"); 0362 DoTest("foo ", "llldaW", "foo "); 0363 DoTest("foo ", "lllldaW", "foo "); 0364 DoTest("foo ", "llllldaW", "foo "); 0365 DoTest("foo ", "lllcaWxyz\\esc", "foo "); 0366 DoTest("foo ", "llllcaWxyz\\esc", "foo "); 0367 DoTest("foo ", "lllllcaWxyz\\esc", "foo "); 0368 DoTest("foo \nbar", "llldaW", "foo"); 0369 DoTest("foo \nbar", "lllldaW", "foo"); 0370 DoTest("foo \nbar", "llllldaW", "foo"); 0371 DoTest("foo \nbar", "lllcaWxyz\\esc", "fooxyz"); 0372 DoTest("foo \nbar", "llllcaWxyz\\esc", "fooxyz"); 0373 DoTest("foo \nbar", "lllllcaWxyz\\esc", "fooxyz"); 0374 DoTest("foo \n bar", "jdaW", "foo \n"); 0375 DoTest("foo \n bar", "jldaW", "foo \n"); 0376 DoTest("foo \n bar", "jlldaW", "foo \n"); 0377 DoTest("foo \n bar", "jcaWxyz\\esc", "foo \nxyz"); 0378 DoTest("foo \n bar", "jlcaWxyz\\esc", "foo \nxyz"); 0379 DoTest("foo \n bar", "jllcaWxyz\\esc", "foo \nxyz"); 0380 DoTest("foo bar", "2daW", ""); 0381 DoTest("foo bar", "2caWxyz\\esc", "xyz"); 0382 DoTest("foo bar baz", "2daW", "baz"); 0383 DoTest("foo bar baz", "2caWxyz\\esc", "xyzbaz"); 0384 DoTest("foo bar baz", "3daW", ""); 0385 DoTest("foo bar baz", "3caWxyz\\esc", "xyz"); 0386 DoTest("foo bar\nbaz", "2daW", "\nbaz"); 0387 DoTest("foo bar\nbaz", "2caWxyz\\esc", "xyz\nbaz"); 0388 DoTest("foo bar\nbaz 123", "3daW", "123"); 0389 DoTest("foo bar\nbaz 123", "3caWxyz\\esc", "xyz123"); 0390 DoTest("foo bar \nbaz 123", "3daW", "123"); 0391 DoTest("foo bar \nbaz 123", "3caWxyz\\esc", "xyz123"); 0392 DoTest("foo bar baz", "lll2daW", "foo"); 0393 DoTest("foo bar baz", "lll2caWxyz\\esc", "fooxyz"); 0394 DoTest(" bar baz", "2daW", ""); 0395 DoTest(" bar baz", "2caWxyz\\esc", "xyz"); 0396 DoTest(" bar baz 123", "2daW", " 123"); 0397 DoTest(" bar baz 123", "2caWxyz\\esc", "xyz 123"); 0398 DoTest(" bar baz\n123", "3daW", ""); 0399 DoTest(" bar baz\n123", "3caWxyz\\esc", "xyz"); 0400 DoTest(" bar baz\n 123", "3daW", ""); 0401 DoTest(" bar baz\n 123", "3caWxyz\\esc", "xyz"); 0402 DoTest(" bar baz\n 123", "2daW", "\n 123"); 0403 DoTest(" bar baz\n 123", "2caWxyz\\esc", "xyz\n 123"); 0404 DoTest(" bar baz\n 123 456 789", "j2daW", " bar baz\n 789"); 0405 DoTest(" bar baz\n 123 456 789", "j2caWxyz\\esc", " bar baz\nxyz 789"); 0406 DoTest("foo\nbar\n", "2daW", ""); 0407 DoTest("bar baz\n123 \n456\n789 abc \njkl", "j4daW", "bar baz\njkl"); 0408 DoTest("bar baz\n123 \n456\n789 abc \njkl", "j4caWxyz\\esc", "bar baz\nxyzjkl"); 0409 DoTest(" bar baz\n 123 \n456\n789 abc \njkl", "j4daW", " bar baz\njkl"); 0410 DoTest(" bar baz\n 123 456 789", "j2caWxyz\\esc", " bar baz\nxyz 789"); 0411 DoTest("foo b123r xyz", "wdaW", "foo xyz"); 0412 DoTest("foo b123r xyz", "wldaW", "foo xyz"); 0413 DoTest("foo b123r xyz", "wlldaW", "foo xyz"); 0414 DoTest("foo b123r xyz", "wllldaW", "foo xyz"); 0415 DoTest("foo b123r xyz", "wlllldaW", "foo xyz"); 0416 DoTest("1 2 3 4 5 6", "daW", "2 3 4 5 6"); 0417 DoTest("1 2 3 4 5 6", "ldaW", "1 3 4 5 6"); 0418 DoTest("1 2 3 4 5 6", "lldaW", "1 3 4 5 6"); 0419 DoTest("1 2 3 4 5 6", "llldaW", "1 2 4 5 6"); 0420 // Now with non-word characters. 0421 DoTest("fo(o", "daW", ""); 0422 DoTest("fo(o", "ldaW", ""); 0423 DoTest("fo(o", "lldaW", ""); 0424 DoTest("fo(o", "llldaW", ""); 0425 DoTest("fo(o )!)!)ffo", "2daW", ""); 0426 DoTest("fo(o", "diW", ""); 0427 DoTest("fo(o", "ldiW", ""); 0428 DoTest("fo(o", "lldiW", ""); 0429 DoTest("fo(o", "llldiW", ""); 0430 DoTest("foo \"\"B!!", "fBdaW", "foo"); 0431 0432 // Inner / Sentence text object ("is") 0433 DoTest("", "cis", ""); 0434 DoTest("hello", "cis", ""); 0435 DoTest("hello", "flcis", ""); 0436 DoTest("hello. bye", "cisX", "X bye"); 0437 DoTest("hello. bye", "f.cisX", "X bye"); 0438 DoTest("hello. bye", "fbcisX", "hello. X"); 0439 DoTest("hello\n\nbye.", "cisX", "X\n\nbye."); 0440 DoTest("Hello. Bye.\n", "GcisX", "Hello. Bye.\nX"); 0441 DoTest("hello. by.. another.", "cisX", "X by.. another."); 0442 DoTest("hello. by.. another.", "fbcisX", "hello. X another."); 0443 DoTest("hello. by.. another.\n", "GcisX", "hello. by.. another.\nX"); 0444 DoTest("hello. yay\nis this a string?!?.. another.\n", "fycisX", "hello. X another.\n"); 0445 DoTest("hello. yay\nis this a string?!?.. another.\n", "jcisX", "hello. X another.\n"); 0446 DoTest("This is a sentence.\nThis is another sentence.", "jdis", "This is a sentence.\n"); 0447 0448 // Around / Sentence text object ("as") 0449 DoTest("", "cas", ""); 0450 DoTest("hello", "cas", ""); 0451 DoTest("hello", "flcas", ""); 0452 DoTest("hello. bye", "casX", "Xbye"); 0453 DoTest("hello. bye", "f.casX", "Xbye"); 0454 DoTest("hello. bye.", "fbcasX", "hello.X"); 0455 DoTest("hello. bye", "fbcasX", "hello.X"); 0456 DoTest("hello\n\nbye.", "casX", "X\n\nbye."); 0457 DoTest("Hello. Bye.\n", "GcasX", "Hello. Bye.\nX"); 0458 DoTest("hello. by.. another.", "casX", "Xby.. another."); 0459 DoTest("hello. by.. another.", "fbcasX", "hello. Xanother."); 0460 DoTest("hello. by.. another.\n", "GcasX", "hello. by.. another.\nX"); 0461 DoTest("hello. yay\nis this a string?!?.. another.\n", "fycasX", "hello. Xanother.\n"); 0462 DoTest("hello. yay\nis this a string?!?.. another.\n", "jcasX", "hello. Xanother.\n"); 0463 DoTest("hello. yay\nis this a string?!?.. \t another.\n", "jcasX", "hello. Xanother.\n"); 0464 0465 // Inner / Paragraph text object ("ip") 0466 DoTest("", "cip", ""); 0467 DoTest("\nhello", "cipX", "X\nhello"); 0468 DoTest("\nhello\n\nanother. text.", "jcipX", "\nX\n\nanother. text."); 0469 DoTest("\nhello\n\n\nanother. text.", "jjcipX", "\nhello\nX\nanother. text."); 0470 DoTest("\nhello\n\n\nanother. text.", "jjjcipX", "\nhello\nX\nanother. text."); 0471 DoTest("\nhello\n\n\nanother. text.", "jjjjcipX", "\nhello\n\n\nX"); 0472 DoTest("hello\n\n", "jcipX", "hello\nX"); 0473 DoTest("hello\n\n", "jjcipX", "hello\nX"); 0474 0475 // Around / Paragraph text object ("ap") 0476 DoTest("", "cap", ""); 0477 DoTest("\nhello", "capX", "X"); 0478 DoTest("\nhello\n\nanother.text.", "jcapX", "\nX\nanother.text."); 0479 DoTest("\nhello\n\nanother.text.\n\n\nAnother.", "jjjcapX", "\nhello\n\nX\nAnother."); 0480 DoTest("\nhello\n\nanother.text.\n\n\nAnother.", "jjjjjcapX", "\nhello\n\nanother.text.\nX"); 0481 DoTest("hello\n\n\n", "jjcapX", "hello\n\n\n"); 0482 DoTest("hello\n\nasd", "jjjcapX", "hello\nX"); 0483 0484 DoTest("{\nfoo\n}", "jdiB", "{\n}"); 0485 DoTest("{\n}", "diB", "{\n}"); 0486 DoTest("{\nfoo}", "jdiB", "{\n}"); 0487 DoTest("{foo\nbar\nbaz}", "jdiB", "{}"); 0488 DoTest("{foo\nbar\n \t\t }", "jdiB", "{\n \t\t }"); 0489 DoTest("{foo\nbar\n \t\ta}", "jdiB", "{}"); 0490 DoTest("\t{\n\t}", "ldiB", "\t{\n\t}"); 0491 // Quick test to see whether inner curly bracket works in visual mode. 0492 DoTest("{\nfoo}", "jviBd", "{\n}"); 0493 DoTest("{\nfoo}", "jvaBd", ""); 0494 // Regression test for viB not working if there is a blank line before the closing }. 0495 DoTest("{\nfoo\n\n}", "viBd", "{\n}"); 0496 // The inner block text object does not include the line containing the opening brace if 0497 // the opening brace is the last character on its line and there is only whitespace before the closing brace. 0498 // (In particular: >iB should not indent the line containing the opening brace under these conditions). 0499 DoTest("{\nfoo\n}", "j>iB", "{\n foo\n}"); 0500 // Similarly, in such conditions, deleting the inner block should leave the cursor on closing brace line, not the 0501 // opening. 0502 DoTest("{\nfoo\n}", "jdiBiX", "{\nX}"); 0503 // Yanking and pasting such a text object should be treated as linewise. 0504 DoTest("{\nfoo\nbar\n}", "jyiBjp", "{\nfoo\nbar\nfoo\nbar\n}"); 0505 // Changing such a text object should delete everything but one line, which we will begin insertion at. 0506 DoTest("{\nfoo\nbar\n}", "jciBbaz\\esc", "{\nbaz\n}"); 0507 // Make sure we remove the "last motion was a *linewise* curly text object" flag when we next parse a motion! 0508 DoTest("{\nfoo\n}", "jciBbaz xyz\\escdiw", "{\nbaz \n}"); 0509 DoTest("{\nfoo\nbar\n}", "jviBbd", "{\nar\n}"); 0510 0511 DoTest("int main() {\n printf( \"HelloWorld!\\n\" );\n return 0;\n} ", "jda}xr;", "int main();"); 0512 0513 DoTest("QList<QString>", "wwldi>", "QList<>"); 0514 DoTest("QList<QString>", "wwlda<", "QList"); 0515 DoTest("<>\n<title>Title</title>\n</head>", "di<jci>\\ctrl-c", "<>\n<>Title</title>\n</head>"); 0516 0517 DoTest("foo bar baz", "wldiw", "foo baz"); 0518 0519 DoTest("foo bar baz", "wldawx", "foo az"); 0520 0521 DoTest("foo ( \n bar\n)baz", "jdi(", "foo ()baz"); 0522 DoTest("foo ( \n bar\n)baz", "jda(", "foo baz"); 0523 DoTest("(foo(bar)baz)", "ldi)", "()"); 0524 DoTest("(foo(bar)baz)", "lca(\\ctrl-c", ""); 0525 DoTest("( foo ( bar ) )baz", "di(", "()baz"); 0526 DoTest("( foo ( bar ) )baz", "da(", "baz"); 0527 DoTest("[foo [ bar] [(a)b [c]d ]]", "$hda]", "[foo [ bar] ]"); 0528 DoTest("(a)", "di(", "()"); 0529 DoTest("(ab)", "di(", "()"); 0530 DoTest("(abc)", "di(", "()"); 0531 0532 DoTest("hi!))))}}]]", "di]di}da)di)da]", "hi!))))}}]]"); 0533 0534 DoTest("foo \"bar\" baz", "4ldi\"", "foo \"\" baz"); 0535 DoTest("foo \"bar\" baz", "8lca\"\\ctrl-c", "foo baz"); 0536 0537 DoTest("foo 'bar' baz", "4lca'\\ctrl-c", "foo baz"); 0538 DoTest("foo 'bar' baz", "8ldi'", "foo '' baz"); 0539 0540 DoTest("foo `bar` baz", "4lca`\\ctrl-c", "foo baz"); 0541 DoTest("foo `bar` baz", "8ldi`", "foo `` baz"); 0542 0543 DoTest("()", "di(", "()"); 0544 DoTest("\"\"", "di\"", "\"\""); 0545 0546 // Comma text object 0547 DoTest("func(aaaa);", "llllldi,", "func();"); 0548 DoTest("func(aaaa);", "lllllda,", "func;"); 0549 DoTest("//Hello, world!\nfunc(a[0] > 2);", "jf>di,", "//Hello, world!\nfunc();"); 0550 DoTest("//Hello, world!\nfunc(a[0] > 2);", "jf>da,", "//Hello, world!\nfunc;"); 0551 DoTest("//Hello, world!\na[] = {135};", "jf3di,", "//Hello, world!\na[] = {};"); 0552 0553 // Some corner case tests for t/ T, mainly dealing with how a ; after e.g. a ta will 0554 // start searching for the next a *after* the character after the cursor. 0555 // Hard to explain; I'll let the test-cases do the talking :) 0556 DoTest("bar baz", "ta;x", "bar az"); 0557 // Ensure we reset the flag that says we must search starting from the character after the cursor! 0558 DoTest("bar baz", "ta;^tax", "ar baz"); 0559 // Corresponding tests for T 0560 DoTest("bar baz", "$Ta;x", "ba baz"); 0561 // Ensure we reset the flag that says we must search starting from the character before the cursor! 0562 DoTest("bar baz", "$Ta;$Tax", "bar ba"); 0563 // Ensure that command backwards works, too - only one test, as any additional ones would 0564 // just overlap with our previous ones. 0565 DoTest("aba bar", "lTa,x", "aba ar"); 0566 // Some tests with counting. 0567 DoTest("aba bar", "2tax", "aba ar"); 0568 // If we can't find 3 further a's, don't move at all... 0569 DoTest("aba bar", "3tax", "ba bar"); 0570 // ... except if we are repeating the last search, in which case stop at the last 0571 // one that we do find. 0572 DoTest("aba bar", "ta2;x", "aba ar"); 0573 0574 // Don't move if we can't find any matches at all, or fewer than we require. 0575 DoTest("nocapitalc", "lltCx", "noapitalc"); 0576 DoTest("nocapitalc", "llTCx", "noapitalc"); 0577 0578 DoTest("123c456", "2tcx", "23c456"); 0579 DoTest("123c456", "$2Tcx", "123c45"); 0580 // Commands with searches that do not find anything, or find less than required, should do nothing. 0581 DoTest("foo", "dtk", "foo"); 0582 DoTest("foomxyz", "d2tm", "foomxyz"); 0583 DoTest("foo", "dfk", "foo"); 0584 DoTest("foomxyz", "d2fm", "foomxyz"); 0585 DoTest("foo", "$dTk", "foo"); 0586 DoTest("foomxyz", "$d2Fm", "foomxyz"); 0587 // They should also return a range marked as invalid. 0588 DoTest("foo bar", "gUF(", "foo bar"); 0589 DoTest("foo bar", "gUf(", "foo bar"); 0590 DoTest("foo bar", "gUt(", "foo bar"); 0591 DoTest("foo bar", "gUT(", "foo bar"); 0592 0593 // Changes using backward motions don't consume cursor character 0594 DoTest("foo bar", "$dTf", "fr"); 0595 DoTest("foo bar", "$c2Fo", "fr"); 0596 0597 // Regression test for special-handling of "/" and "?" keys: these shouldn't interfere 0598 // with character searches. 0599 DoTest("foo /", "f/rX", "foo X"); 0600 // d{f,F}{/,?} 0601 DoTest("foo/bar?baz", "df/", "bar?baz"); 0602 DoTest("foo/bar?baz", "f/df?", "foobaz"); 0603 DoTest("foo/bar?baz", "df?", "baz"); 0604 DoTest("foo/bar?baz", "f?dF/", "foo?baz"); 0605 // d{t,T}{/,?} 0606 DoTest("foo/bar?baz", "dt/", "/bar?baz"); 0607 DoTest("foo/bar?baz", "t/dt?", "fo?baz"); 0608 DoTest("foo/bar?baz", "dt?", "?baz"); 0609 DoTest("foo/bar?baz", "t?dT/", "foo/r?baz"); 0610 // c{f,F}{/,?} 0611 DoTest("foo/bar?baz", "cf/qux\\esc", "quxbar?baz"); 0612 DoTest("foo/bar?baz", "f/cf?qux\\esc", "fooquxbaz"); 0613 DoTest("foo/bar?baz", "cf?qux\\esc", "quxbaz"); 0614 DoTest("foo/bar?baz", "f?cF/qux\\esc", "fooqux?baz"); 0615 // c{t,T}{/,?} 0616 DoTest("foo/bar?baz", "ct/qux\\esc", "qux/bar?baz"); 0617 DoTest("foo/bar?baz", "t/ct?qux\\esc", "foqux?baz"); 0618 DoTest("foo/bar?baz", "ct?qux\\esc", "qux?baz"); 0619 DoTest("foo/bar?baz", "t?cT/qux\\esc", "foo/quxr?baz"); 0620 // y{f,F}{/,?} 0621 DoTest("foo/bar?baz", "yf/p", "ffoo/oo/bar?baz"); 0622 DoTest("foo/bar?baz", "f/yf?p", "foo//bar?bar?baz"); 0623 DoTest("foo/bar?baz", "yf?p", "ffoo/bar?oo/bar?baz"); 0624 DoTest("foo/bar?baz", "f?yF/p", "foo/bar?/barbaz"); 0625 // y{t,T}{/,?} 0626 DoTest("foo/bar?baz", "yt/p", "ffoooo/bar?baz"); 0627 DoTest("foo/bar?baz", "t/yt?p", "fooo/bar/bar?baz"); 0628 DoTest("foo/bar?baz", "yt?p", "ffoo/baroo/bar?baz"); 0629 DoTest("foo/bar?baz", "t?yT/p", "foo/barba?baz"); 0630 0631 // gU, gu, g~. 0632 DoTest("foo/bar?baz", "gUf/", "FOO/bar?baz"); 0633 DoTest("FOO/bar?baz", "g~f?", "foo/BAR?baz"); 0634 DoTest("foo/BAR?baz", "guf?", "foo/bar?baz"); 0635 0636 // Not adding tests for =f/, >t?, <F?, gqT/ : 0637 // Not likely to be used with those motions. 0638 // gw and g@ are currently not supported by ktexteditor's vimode 0639 0640 // Using registers 0641 DoTest("foo/bar?baz", "\"2df?", "baz"); 0642 DoTest("foo/bar?baz", "\"_ct/qux", "qux/bar?baz"); 0643 0644 // counted find on change/deletion != find digit 0645 DoTest("foo2barbaz", "df2ax", "bxarbaz"); 0646 DoTest("foo2barbaz", "d2fax", ""); 0647 0648 // Motion to lines starting with { or } 0649 DoTest("{\nfoo\n}", "][x", "{\nfoo\n"); 0650 DoTest("{\nfoo\n}", "j[[x", "\nfoo\n}"); 0651 DoTest("bar\n{\nfoo\n}", "]]x", "bar\n\nfoo\n}"); 0652 DoTest("{\nfoo\n}\nbar", "jjj[]x", "{\nfoo\n\nbar"); 0653 DoTest("bar\nfoo\n}", "d][", "}"); 0654 DoTest("bar\n{\nfoo\n}", "d]]", "{\nfoo\n}"); 0655 DoTest("bar\nfoo\n}", "ld][", "b\n}"); 0656 DoTest("{\nfoo\n}", "jld[[", "oo\n}"); 0657 DoTest("bar\n{\nfoo\n}", "ld]]", "b\n{\nfoo\n}"); 0658 DoTest("{\nfoo\n}\nbar", "jjjld[]", "{\nfoo\nar"); 0659 0660 // Testing the "(" motion 0661 DoTest("", "(", ""); 0662 DoTest("\nhello.", "fh(iX", "X\nhello."); 0663 DoTest("\n hello.", "jfe(iX", "X\n hello."); 0664 DoTest("hello. world.", "fr(iX", "Xhello. world."); 0665 DoTest("hello. world.\n", "j(iX", "hello. Xworld.\n"); 0666 DoTest("hello. world\nyay. lol.\n", "jfl(iX", "hello. Xworld\nyay. lol.\n"); 0667 DoTest("Hello.\n\n", "jj(iX", "XHello.\n\n"); 0668 DoTest("\nHello.", "j(iX", "X\nHello."); 0669 DoTest("\n\n\nHello.", "jj(iX", "X\n\n\nHello."); 0670 DoTest("Hello! Bye!", "fB(iX", "XHello! Bye!"); 0671 DoTest("Hello! Bye! Hye!", "fH(iX", "Hello! XBye! Hye!"); 0672 DoTest("\nHello. Bye.. Asd.\n\n\n\nAnother.", "jjjj(iX", "\nHello. Bye.. XAsd.\n\n\n\nAnother."); 0673 0674 // Testing the ")" motion 0675 DoTest("", ")", ""); 0676 DoTest("\nhello.", ")iX", "\nXhello."); 0677 DoTest("hello. world.", ")iX", "hello. Xworld."); 0678 DoTest("hello. world\n\nasd.", "))iX", "hello. world\nX\nasd."); 0679 DoTest("hello. wor\nld.?? Asd", "))iX", "hello. wor\nld.?? XAsd"); 0680 DoTest("hello. wor\nld.?? Asd", "jfA(iX", "hello. Xwor\nld.?? Asd"); 0681 DoTest("Hello.\n\n\nWorld.", ")iX", "Hello.\nX\n\nWorld."); 0682 DoTest("Hello.\n\n\nWorld.", "))iX", "Hello.\n\n\nXWorld."); 0683 DoTest("Hello.\n\n", ")iX", "Hello.\nX\n"); 0684 DoTest("Hello.\n\n", "))iX", "Hello.\n\nX"); 0685 DoTest("Hello. ", ")aX", "Hello. X"); 0686 DoTest("Hello?? Bye!", ")iX", "Hello?? XBye!"); 0687 0688 // Testing "{" and "}" motions 0689 DoTest("", "{}", ""); 0690 DoTest("foo", "{}dd", ""); 0691 DoTest("foo\n\nbar", "}dd", "foo\nbar"); 0692 DoTest("foo\n\nbar\n\nbaz", "3}x", "foo\n\nbar\n\nba"); 0693 DoTest("foo\n\nbar\n\nbaz", "3}{dd{dd", "foo\nbar\nbaz"); 0694 DoTest("foo\nfoo\n\nbar\n\nbaz", "5}{dd{dd", "foo\nfoo\nbar\nbaz"); 0695 DoTest("foo\nfoo\n\nbar\n\nbaz", "5}3{x", "oo\nfoo\n\nbar\n\nbaz"); 0696 DoTest("foo\n\n\nbar", "10}{{x", "oo\n\n\nbar"); 0697 DoTest("foo\n\n\nbar", "}}x", "foo\n\n\nba"); 0698 DoTest("foo\n\n\nbar\n", "}}dd", "foo\n\n\nbar"); 0699 0700 // Testing the position of the cursor in some cases of the "c" command. 0701 DoTest("(a, b, c)", "cibX", "(X)"); 0702 DoTest("(a, b, c)", "f)cibX", "(X)"); 0703 DoTest("(a, b, c)", "ci(X", "(X)"); 0704 DoTest("(a, b, c)", "ci)X", "(X)"); 0705 DoTest("[a, b, c]", "ci[X", "[X]"); 0706 DoTest("[a, b, c]", "ci]X", "[X]"); 0707 DoTest("{a, b, c}", "ciBX", "{X}"); 0708 DoTest("{a, b, c}", "ci{X", "{X}"); 0709 DoTest("{a, b, c}", "ci}X", "{X}"); 0710 DoTest("<a, b, c>", "ci<X", "<X>"); 0711 DoTest("<a, b, c>", "ci>X", "<X>"); 0712 0713 // Things like "cn" and "cN" don't crash. 0714 DoTest("Hello", "cn", "Hello"); 0715 DoTest("Hello", "cN", "Hello"); 0716 } 0717 0718 void ModesTest::NormalCommandsTests() 0719 { 0720 // Testing "J" 0721 DoTest("foo\nbar", "J", "foo bar"); 0722 DoTest("foo\nbar", "JrX", "fooXbar"); 0723 DoTest("foo\nbar\nxyz\n123", "3J", "foo bar xyz\n123"); 0724 DoTest("foo\nbar\nxyz\n123", "3JrX", "foo barXxyz\n123"); 0725 DoTest("foo\nbar\nxyz\n12345\n789", "4JrX", "foo bar xyzX12345\n789"); 0726 DoTest("foo\nbar\nxyz\n12345\n789", "6JrX", "Xoo\nbar\nxyz\n12345\n789"); 0727 DoTest("foo\nbar\nxyz\n12345\n789", "j5JrX", "foo\nXar\nxyz\n12345\n789"); 0728 DoTest("foo\nbar\nxyz\n12345\n789", "7JrX", "Xoo\nbar\nxyz\n12345\n789"); 0729 DoTest("\n\n", "J", "\n"); 0730 DoTest("foo\n\t \t\t bar", "JrX", "fooXbar"); 0731 DoTest("foo\n\t \t\t", "J", "foo "); 0732 DoTest("foo\n\t \t\t", "JrX", "fooX"); 0733 0734 // Testing "dd" 0735 DoTest("foo\nbar", "dd", "bar"); 0736 DoTest("foo\nbar", "2dd", ""); 0737 DoTest("foo\nbar\n", "Gdd", "foo\nbar"); 0738 // Testing numbered registers 0739 DoTest("hello\nworld", "dddd\"2p\"1p", "\nhello\nworld"); 0740 DoTest("foo\nbar", "ddD\"1p", "\nfoo"); 0741 DoTest("abc\nlmn\nxyz", "dddd\"2dd\"1p\"2p", "\nxyz\nlmn"); 0742 DoTest("123\n456", "dd\"add\"1p\"2p", "\n456\n123"); 0743 DoTest("9\n8\n7\n6\n5\n4\n3\n2\n1\n0", "\"1dddddddddddddddd2dd\"1p\"2p\"3p\"4p\"5p\"6p\"7p\"8p\"9p", "\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0"); 0744 0745 // Testing "D" 0746 DoTest("foo bar", "lllD", "foo"); 0747 DoTest("foo\nfoo2\nfoo3", "l2D", "f\nfoo3"); 0748 DoTest("qwerty", "d frDai", "wei"); 0749 // Testing small delete (-) register 0750 DoTest("12345\n67890", "ddD\"-p", "67890"); 0751 DoTest("foo\nbar\nhello world", "ld$dj$\"-p", "hello worldoo"); 0752 DoTest("123\n456", "Dj\"aD\"-p", "\n123"); 0753 DoTest("abc\nlmn\nxyz", "yyjlYjxk\"-p", "abc\nlmyn\nxz"); 0754 0755 // Testing "d" 0756 DoTest("foobar", "ld2l", "fbar"); 0757 DoTest("1 2 3\n4 5 6", "ld100l", "1\n4 5 6"); 0758 0759 DoTest("123\n", "d10l", "\n"); 0760 DoTest("123\n", "10lx", "12\n"); 0761 0762 // Testing "Y" 0763 DoTest("qwerty", "ld Yep", "qertyerty"); 0764 // Testing ""<x>y" where x is in a-z (overwrite/insert to register) 0765 DoTest("x", "\"ayh\"Ayl\"ap", "xx"); 0766 DoTest("xy", "\"byll\"byll\"bp", "xyy"); 0767 DoTest("xyz", "\"cy3l$\"cp", "xyzxyz"); 0768 DoTest("abz", "\"xyll\"yyll\"zyll\"zp\"xp\"yp", "abzzab"); 0769 DoTest("abcdwxyz", "\"byh\"ayll\"Byll\"cyll\"dyll\"dyl\"zye$\"zp\"ap\"Cp\"bp\"dp", "abcdwxyzwxyzacbw"); 0770 // Testing "<X>y" where X is in A-Z (append-copy) 0771 DoTest("foo bar ", "\"ayew\"Aye$\"ap", "foo bar foobar"); 0772 DoTest("foo bar 2", "\"ayew\"Ayew\"aye\"ap", "foo bar 22"); 0773 DoTest("123 foo ", "\"ayew\"zye\"Aye0\"Zy4l$\"Zp\"ap", "123 foo foo123 123foo"); 0774 0775 // Testing "X" 0776 DoTest("ABCD", "$XX", "AD"); 0777 DoTest("foo", "XP", "foo"); 0778 0779 // Testing Del key 0780 DoTest("foo", "\\home\\delete", "oo"); 0781 DoTest("foo", "$\\delete", "fo"); 0782 0783 // Delete. Note that when sent properly via Qt, the key event text() will inexplicably be "127", 0784 // which can trip up the key parser. Duplicate this oddity here. 0785 BeginTest("xyz"); 0786 TestPressKey("l"); 0787 QKeyEvent *deleteKeyDown = new QKeyEvent(QEvent::KeyPress, Qt::Key_Delete, Qt::NoModifier, "127"); 0788 QApplication::postEvent(kate_view->focusProxy(), deleteKeyDown); 0789 QApplication::sendPostedEvents(); 0790 QKeyEvent *deleteKeyUp = new QKeyEvent(QEvent::KeyRelease, Qt::Key_Delete, Qt::NoModifier, "127"); 0791 QApplication::postEvent(kate_view->focusProxy(), deleteKeyUp); 0792 QApplication::sendPostedEvents(); 0793 FinishTest("xz"); 0794 0795 // Testing "gu" 0796 DoTest("FOO\nBAR BAZ", "guj", "foo\nbar baz"); 0797 DoTest("AbCDF", "gu3l", "abcDF"); 0798 0799 // Testing "guu" 0800 DoTest("FOO", "guu", "foo"); 0801 DoTest("FOO\nBAR\nBAZ", "2guu", "foo\nbar\nBAZ"); 0802 DoTest("", "guu", ""); 0803 0804 // Testing "gU" 0805 DoTest("aBcdf", "gU2l", "ABcdf"); 0806 DoTest("foo\nbar baz", "gUj", "FOO\nBAR BAZ"); 0807 0808 // Testing "gUU" 0809 DoTest("foo", "gUU", "FOO"); 0810 DoTest("foo\nbar\nbaz", "2gUU", "FOO\nBAR\nbaz"); 0811 DoTest("", "gUU", ""); 0812 0813 // Testing "g~" 0814 DoTest("fOo BAr", "lg~fA", "foO bar"); 0815 DoTest("fOo BAr", "$hg~FO", "foO bAr"); 0816 DoTest("fOo BAr", "lf~fZ", "fOo BAr"); 0817 DoTest("{\nfOo BAr\n}", "jg~iB", "{\nFoO baR\n}"); 0818 0819 // Testing "g~~" 0820 DoTest("", "g~~", ""); 0821 DoTest("\nfOo\nbAr", "g~~", "\nfOo\nbAr"); 0822 DoTest("fOo\nbAr\nBaz", "g~~", "FoO\nbAr\nBaz"); 0823 DoTest("fOo\nbAr\nBaz\nfAR", "j2g~~", "fOo\nBaR\nbAZ\nfAR"); 0824 DoTest("fOo\nbAr\nBaz", "jlg~~rX", "fOo\nXaR\nBaz"); 0825 DoTest("fOo\nbAr\nBaz\nfAR", "jl2g~~rX", "fOo\nBXR\nbAZ\nfAR"); 0826 0827 // Testing "s" 0828 DoTest("substitute char repeat", "w4scheck\\esc", "substitute check repeat"); 0829 0830 // Testing "r". 0831 DoTest("foobar", "l2r.", "f..bar"); 0832 DoTest("foobar", "l5r.", "f....."); 0833 // Do nothing if the count is too high. 0834 DoTest("foobar", "l6r.", "foobar"); 0835 0836 // Testing "Ctrl-o" and "Ctrl-i" 0837 DoTest("abc\ndef\nghi", "Gx\\ctrl-ox", "bc\ndef\nhi"); 0838 DoTest("{\n}", "%\\ctrl-ox", "\n}"); 0839 DoTest("Foo foo.\nBar bar.\nBaz baz.", "lmajlmb`a`b\\ctrl-ox", "Fo foo.\nBar bar.\nBaz baz."); 0840 DoTest("Foo foo.\nBar bar.\nBaz baz.", "lmajlmb`a`bj\\ctrl-o\\ctrl-ix", "Foo foo.\nBar bar.\nBa baz."); 0841 0842 // Testing "gq" (reformat) text 0843 DoTest("foo\nbar", "gqq", "foo\nbar"); 0844 DoTest("foo\nbar", "2gqq", "foo bar"); 0845 DoTest("foo\nbar\nbaz", "jgqj", "foo\nbar baz"); 0846 DoTest("foo\nbar\n\n\n", "gqap", "foo bar\n\n\n"); 0847 0848 // when setting the text to wrap at column 10, this should be re-formatted to 0849 // span several lines ... 0850 kate_document->setWordWrapAt(10); 0851 DoTest("foo bar foo bar foo bar", "gqq", "foo bar \nfoo bar \nfoo bar"); 0852 0853 // ... and when re-setting it to column 80 again, they should be joined again 0854 kate_document->setWordWrapAt(80); 0855 DoTest("foo bar\nfoo bar\nfoo bar", "gqG", "foo bar foo bar foo bar"); 0856 0857 // test >> and << (indent and de-indent) 0858 kate_document->config()->setReplaceTabsDyn(true); 0859 0860 DoTest("foo\nbar", ">>", " foo\nbar"); 0861 DoTest("foo\nbar", "2>>", " foo\n bar"); 0862 DoTest("foo\nbar", "100>>", " foo\n bar"); 0863 0864 DoTest("fop\nbar", "yiwjlgpx", "fop\nbafop"); 0865 DoTest("fop\nbar", "yiwjlgPx", "fop\nbfopr"); 0866 0867 DoTest("repeat\nindent", "2>>2>>", " repeat\n indent"); 0868 0869 // make sure we record correct history when indenting 0870 DoTest("repeat\nindent and undo", "2>>2>>2>>uu", " repeat\n indent and undo"); 0871 DoTest("repeat\nunindent and undo", "2>>2>>2<<u", " repeat\n unindent and undo"); 0872 0873 // Yank and paste op\ngid into bar i.e. text spanning lines, but not linewise. 0874 DoTest("fop\ngid\nbar", "lvjyjjgpx", "fop\ngid\nbaop\ngi"); 0875 DoTest("fop\ngid\nbar", "lvjyjjgPx", "fop\ngid\nbop\ngir"); 0876 DoTest("fop\ngid\nbar", "lvjyjjpx", "fop\ngid\nbap\ngir"); 0877 DoTest("fop\ngid\nbar", "lvjyjjPx", "fop\ngid\nbp\ngiar"); 0878 // Linewise 0879 DoTest("fop\ngid\nbar\nhuv", "yjjjgpx", "fop\ngid\nbar\nfop\ngid\nuv"); 0880 DoTest("fop\ngid\nbar\nhuv", "yjjjgPx", "fop\ngid\nfop\ngid\nar\nhuv"); 0881 DoTest("fop\ngid", "yjjgpx", "fop\ngid\nfop\nid"); 0882 DoTest("fop\ngid\nbar\nhuv", "yjjjPx", "fop\ngid\nop\ngid\nbar\nhuv"); 0883 0884 DoTest("fop\nbar", "yiwjlpx", "fop\nbafor"); 0885 DoTest("fop\nbar", "yiwjlPx", "fop\nbfoar"); 0886 0887 // Indented paste. 0888 // ]p behaves as ordinary paste if not linewise, and on unindented line. 0889 DoTest("foo bar", "wyiwgg]p", "fbaroo bar"); 0890 // ]p behaves as ordinary paste if not linewise, even on indented line. 0891 DoTest(" foo bar", "wwyiwggw]p", " fbaroo bar"); 0892 // [p behaves as ordinary Paste (P) if not linewise, and on unindented line. 0893 DoTest("foo bar", "wyiwgg[p", "barfoo bar"); 0894 // [p behaves as ordinary Paste (P) if not linewise, even on indented line. 0895 DoTest(" foo bar", "wwyiw0w[p", " barfoo bar"); 0896 // Prepend the spaces from the current line to the beginning of a single, pasted line. 0897 DoTest(" foo bar\nxyz", "jVygg]p", " foo bar\n xyz\nxyz"); 0898 // Prepend the spaces from the current line to the beginning of each pasted line. 0899 DoTest(" foo bar\nxyz\nnose", "jVjygg]p", " foo bar\n xyz\n nose\nxyz\nnose"); 0900 const bool oldReplaceTabsDyn = kate_document->config()->replaceTabsDyn(); 0901 kate_document->config()->setReplaceTabsDyn(false); 0902 // Tabs as well as spaces! 0903 DoTest(" \tfoo bar\nxyz\nnose", "jVjygg]p", " \tfoo bar\n \txyz\n \tnose\nxyz\nnose"); 0904 // Same for [p. 0905 DoTest(" \tfoo bar\nxyz\nnose", "jVjygg[p", " \txyz\n \tnose\n \tfoo bar\nxyz\nnose"); 0906 // Test if everything works if the current line has no non-whitespace. 0907 DoTest("\t \nbar", "jVygg]p", "\t \n\t bar\nbar"); 0908 // Test if everything works if the current line is empty. 0909 DoTest("\nbar", "jVygg]p", "\nbar\nbar"); 0910 // Unindent a pasted indented line if the current line has no indent. 0911 DoTest("foo\n \tbar", "jVygg]p", "foo\nbar\n \tbar"); 0912 // Unindent subsequent lines, too - TODO - this assumes that each subsequent line has 0913 // *identical* trailing whitespace to the first pasted line: Vim seems to be able to 0914 // deal with cases where this does not hold. 0915 DoTest("foo\n \tbar\n \txyz", "jVjygg]p", "foo\nbar\nxyz\n \tbar\n \txyz"); 0916 DoTest("foo\n \tbar\n \t xyz", "jVjygg]p", "foo\nbar\n xyz\n \tbar\n \t xyz"); 0917 kate_document->config()->setReplaceTabsDyn(oldReplaceTabsDyn); 0918 0919 // Some special cases of cw/ cW. 0920 DoTest("foo bar", "cwxyz\\esc", "xyz bar"); 0921 DoTest("foo+baz bar", "cWxyz\\esc", "xyz bar"); 0922 DoTest("foo+baz bar", "cwxyz\\esc", "xyz+baz bar"); 0923 DoTest(" foo bar", "cwxyz\\esc", "xyzfoo bar"); 0924 DoTest(" foo+baz bar", "cWxyz\\esc", "xyzfoo+baz bar"); 0925 DoTest(" foo+baz bar", "cwxyz\\esc", "xyzfoo+baz bar"); 0926 DoTest("\\foo bar", "cWxyz\\esc", "xyz bar"); 0927 DoTest("foo ", "lllcwxyz\\esc", "fooxyz"); 0928 0929 DoTest("foo", "yr", "foo"); 0930 QCOMPARE(kate_view->renderer()->caretStyle(), KateRenderer::Block); 0931 0932 // BUG #332523 0933 const bool oldDynWordWrap = KateViewConfig::global()->dynWordWrap(); 0934 BeginTest("asdasdasd\nasdasdasdasdasdasdasd"); 0935 kate_document->setWordWrap(true); 0936 kate_document->setWordWrapAt(10); 0937 TestPressKey("Jii"); 0938 FinishTest("iasdasdasd\n \nasdasdasda \nsdasdasdas \nd"); 0939 kate_document->setWordWrap(oldDynWordWrap); 0940 } 0941 0942 void ModesTest::NormalControlTests() 0943 { 0944 // Testing "Ctrl-x" 0945 DoTest("150", "101\\ctrl-x", "49"); 0946 DoTest("1", "\\ctrl-x\\ctrl-x\\ctrl-x\\ctrl-x", "-3"); 0947 DoTest("0xabcdef", "1000000\\ctrl-x", "0x9c8baf"); 0948 DoTest("0x0000f", "\\ctrl-x", "0x0000e"); 0949 // Octal numbers should retain leading 0's. 0950 DoTest("00010", "\\ctrl-x", "00007"); 0951 0952 // Testing "Ctrl-a" 0953 DoTest("150", "101\\ctrl-a", "251"); 0954 DoTest("1000", "\\ctrl-ax", "100"); 0955 DoTest("-1", "1\\ctrl-a", "0"); 0956 DoTest("-1", "l1\\ctrl-a", "0"); 0957 DoTest("0x0000f", "\\ctrl-a", "0x00010"); 0958 // Decimal with leading 0's - increment, and strip leading 0's, like Vim. 0959 DoTest("0000193", "\\ctrl-a", "194"); 0960 // If a number begins with 0, parse it as octal if we can. The resulting number should retain the 0961 // leadingi 0. 0962 DoTest("07", "\\ctrl-a", "010"); 0963 DoTest("5", "5\\ctrl-a.", "15"); 0964 DoTest("5", "5\\ctrl-a2.", "12"); 0965 DoTest("5", "5\\ctrl-a2.10\\ctrl-a", "22"); 0966 DoTest(" 5 ", "l\\ctrl-ax", " "); 0967 // If there's no parseable number under the cursor, look to the right to see if we can find one. 0968 DoTest("aaaa0xbcX", "\\ctrl-a", "aaaa0xbdX"); 0969 DoTest("1 1", "l\\ctrl-a", "1 2"); 0970 // We can skip across word boundaries in our search if need be. 0971 DoTest("aaaa 0xbcX", "\\ctrl-a", "aaaa 0xbdX"); 0972 // If we can't find a parseable number anywhere, don't change anything. 0973 DoTest("foo", "\\ctrl-a", "foo"); 0974 // Don't hang if the cursor is at the end of the line and the only number is to the immediate left of the cursor. 0975 DoTest("1 ", "l\\ctrl-a", "1 "); 0976 // ctrl-a/x algorithm involves stepping back to the previous word: don't crash if this is on the previous line 0977 // and at a column greater than the length of the current line. 0978 DoTest(" a a\n1", "j\\ctrl-a", " a a\n2"); 0979 DoTest(" a a a\n 1", "jll\\ctrl-a", " a a a\n 2"); 0980 // Regression test. 0981 DoTest("1w3", "l\\ctrl-a", "1w4"); 0982 0983 // Test "Ctrl-a/x" on a blank document/ blank line. 0984 DoTest("", "\\ctrl-a", ""); 0985 DoTest("", "\\ctrl-x", ""); 0986 DoTest("foo\n", "j\\ctrl-x", "foo\n"); 0987 DoTest("foo\n", "j\\ctrl-a", "foo\n"); 0988 0989 // Testing "Ctrl-r" 0990 DoTest("foobar", "d3lu\\ctrl-r", "bar"); 0991 DoTest("line 1\nline 2\n", "ddu\\ctrl-r", "line 2\n"); 0992 } 0993 0994 void ModesTest::NormalNotYetImplementedFeaturesTests() 0995 { 0996 QSKIP("This tests never worked :(", SkipAll); 0997 0998 // Testing "))" 0999 DoTest("Foo foo. Bar bar.", "))\\ctrl-ox", "Foo foo. ar bar."); 1000 DoTest("Foo foo.\nBar bar.\nBaz baz.", ")))\\ctrl-ox\\ctrl-ox", "Foo foo.\nar bar.\nBaz baz."); 1001 DoTest("Foo foo.\nBar bar.\nBaz baz.", "))\\ctrl-ox\\ctrl-ix", "Foo foo.\nBar bar.\naz baz."); 1002 DoTest("Foo foo.\nBar bar.\nBaz baz.", "))\\ctrl-ox\\ctrl-ix", "Foo foo.\nBar bar.\naz baz."); 1003 } 1004 1005 // END: Normal mode. 1006 1007 // BEGIN: Insert mode. 1008 1009 void ModesTest::InsertTests() 1010 { 1011 // Basic stuff. 1012 DoTest("bar", "s\\ctrl-c", "ar"); 1013 DoTest("bar", "ls\\ctrl-cx", "r"); 1014 DoTest("foo\nbar", "S\\ctrl-c", "\nbar"); 1015 DoTest("baz bar", "lA\\ctrl-cx", "baz ba"); 1016 DoTest("baz bar", "la\\ctrl-cx", "bz bar"); 1017 DoTest("foo\nbar\nbaz", "C\\ctrl-c", "\nbar\nbaz"); 1018 DoTest("foo bar baz", "c2w\\ctrl-c", " baz"); 1019 DoTest("foo\nbar\nbaz", "jo\\ctrl-c", "foo\nbar\n\nbaz"); 1020 DoTest("foo\nbar\nbaz", "jO\\ctrl-c", "foo\n\nbar\nbaz"); 1021 DoTest("foo\nbar", "O\\ctrl-c", "\nfoo\nbar"); 1022 DoTest("foo\nbar", "o\\ctrl-c", "foo\n\nbar"); 1023 DoTest("foo bar", "wlI\\ctrl-cx", "oo bar"); 1024 DoTest("foo bar", "wli\\ctrl-cx", "foo ar"); 1025 DoTest("foo bar", "wlihello\\ctrl-c", "foo bhelloar"); 1026 1027 // With count. 1028 DoTest("", "5ihello\\esc", "hellohellohellohellohello"); 1029 DoTest("bar", "5ahello\\esc", "bhellohellohellohellohelloar"); 1030 DoTest(" bar", "5Ihello\\esc", " hellohellohellohellohellobar"); 1031 DoTest("bar", "5Ahello\\esc", "barhellohellohellohellohello"); 1032 DoTest("", "5ihello\\ctrl-c", "hello"); 1033 DoTest("bar", "5ohello\\esc", "bar\nhello\nhello\nhello\nhello\nhello"); 1034 DoTest("bar", "5Ohello\\esc", "hello\nhello\nhello\nhello\nhello\nbar"); 1035 DoTest("bar", "Ohello\\escu", "bar"); 1036 DoTest("bar", "5Ohello\\escu", "bar"); 1037 DoTest("bar", "ohello\\escu", "bar"); 1038 DoTest("bar", "5ohello\\escu", "bar"); 1039 DoTest("foo\nbar", "j5Ohello\\esc", "foo\nhello\nhello\nhello\nhello\nhello\nbar"); 1040 DoTest("bar", "5ohello\\esc2ixyz\\esc", "bar\nhello\nhello\nhello\nhello\nhellxyzxyzo"); 1041 DoTest("", "ihello\\esc5.", "hellhellohellohellohellohelloo"); 1042 1043 // Ensure that the flag that says that counted repeats should begin on a new line is reset. 1044 DoTest("foo", "obar\\ctrl-c5ixyz\\esc", "foo\nbaxyzxyzxyzxyzxyzr"); 1045 DoTest("foo", "obar\\ctrl-cgg\\ctrl-vlljAxyz\\esc5i123\\esc", "fooxy123123123123123z\nbarxyz"); 1046 DoTest("foo foo foo", "c3wbar\\esc", "bar"); 1047 DoTest("abc", "lOxyz", "xyz\nabc"); 1048 1049 // Test that our test driver can handle newlines during insert mode :) 1050 DoTest("", "ia\\returnb", "a\nb"); 1051 } 1052 1053 void ModesTest::InsertKeysTests() 1054 { 1055 // Ctrl-w 1056 DoTest("foobar", "$i\\ctrl-w", "r"); 1057 DoTest("foobar\n", "A\\ctrl-w", "\n"); 1058 DoTest(" foo", "i\\ctrl-wX\\esc", "X foo"); 1059 DoTest(" foo", "lli\\ctrl-wX\\esc", "X foo"); 1060 1061 // Ctrl-u 1062 DoTest("", "i\\ctrl-u", ""); 1063 DoTest("foobar", "i\\ctrl-u", "foobar"); 1064 DoTest("foobar", "fbi\\ctrl-u", "bar"); 1065 DoTest("foobar\nsecond", "ji\\ctrl-u", "foobarsecond"); 1066 DoTest("foobar\n second", "jwi\\ctrl-u", "foobar\nsecond"); 1067 DoTest("foobar\n second", "jfci\\ctrl-u", "foobar\n cond"); 1068 DoTest("foobar\n second", "j$a\\ctrl-u", "foobar\n "); 1069 1070 // Ctrl-e 1071 DoTest("foo\nbar", "i\\ctrl-e", "bfoo\nbar"); 1072 DoTest("foo\nbar", "i\\ctrl-e\\ctrl-e\\ctrl-e", "barfoo\nbar"); 1073 DoTest("foo\nb", "i\\ctrl-e\\ctrl-e", "bfoo\nb"); 1074 1075 // Ctrl-y 1076 DoTest("foo\nbar", "ji\\ctrl-y", "foo\nfbar"); 1077 DoTest("foo\nbar", "ji\\ctrl-y\\ctrl-y\\ctrl-y", "foo\nfoobar"); 1078 DoTest("f\nbar", "ji\\ctrl-y\\ctrl-y", "f\nfbar"); 1079 1080 // Ctrl-R 1081 DoTest("barbaz", "\"ay3li\\ctrl-ra", "barbarbaz"); 1082 DoTest("barbaz", "\"ay3li\\ctrl-raX", "barXbarbaz"); 1083 DoTest("bar\nbaz", "\"byylli\\ctrl-rb", "bar\nbar\nbaz"); 1084 DoTest("Hello", "0yei\\ctrl-r\"", "HelloHello"); 1085 1086 // Ctrl-O 1087 DoTest("foo bar baz", "3li\\ctrl-od2w", "foobaz"); 1088 DoTest("foo bar baz", "3li\\ctrl-od2w\\ctrl-w", "baz"); 1089 DoTest("foo bar baz", "i\\ctrl-o3l\\ctrl-w", " bar baz"); 1090 DoTest("foo\nbar\nbaz", "li\\ctrl-oj\\ctrl-w\\ctrl-oj\\ctrl-w", "foo\nar\naz"); 1091 1092 // Test that the text written after the Ctrl-O command completes is treated as 1093 // an insertion of text (rather than a sequence of commands) when repeated via "." 1094 DoTest("", "isausage\\ctrl-obugo\\esc.", "ugugoosausage"); 1095 1096 // 'Step back' on Ctrl-O if at the end of the line 1097 DoTest("foo bar baz", "A\\ctrl-ox", "foo bar ba"); 1098 1099 // Paste acts as gp when executing in a Ctrl-O 1100 DoTest("foo bar baz", "yiwea\\ctrl-opd", "foo foodbar baz"); 1101 DoTest("bar", "A\\ctrl-o\\ctrl-chx", "br"); 1102 DoTest("bar", "A\\ctrl-o\\eschx", "br"); 1103 1104 // Ctrl-D & Ctrl-T 1105 DoTest("foo", "i\\ctrl-t", " foo"); 1106 DoTest(" foo", "i\\ctrl-d", "foo"); 1107 DoTest("foo\nbar", "i\\ctrl-t\\ctrl-d", "foo\nbar"); 1108 1109 // Ctrl-H 1110 DoTest("foo", "i\\ctrl-h", "foo"); 1111 DoTest(" foo", "li\\ctrl-h", "foo"); 1112 DoTest("foo\nbar", "ji\\ctrl-h", "foobar"); 1113 DoTest("1234567890", "A\\ctrl-h\\ctrl-h\\ctrl-h\\ctrl-h\\ctrl-h", "12345"); 1114 DoTest("1\n2\n3", "GA\\ctrl-h\\ctrl-h\\ctrl-h\\ctrl-h", "1"); 1115 1116 // Ctrl-J 1117 DoTest("foo", "i\\ctrl-j", "\nfoo"); 1118 DoTest("foo", "lli\\ctrl-j", "fo\no"); 1119 DoTest("foo\nbar", "ji\\ctrl-j", "foo\n\nbar"); 1120 DoTest("foobar", "A\\ctrl-j", "foobar\n"); 1121 DoTest("foobar", "li\\ctrl-j\\ctrl-cli\\ctrl-j\\ctrl-cli\\ctrl-j\\ctrl-cli\\ctrl-j\\ctrl-cli\\ctrl-j\\ctrl-c", "f\no\no\nb\na\nr"); 1122 1123 // Ctrl-left & Ctrl-right. 1124 DoTest("foo bar", "i\\ctrl-\\rightX\\esc", "foo Xbar"); 1125 DoTest("foo bar", "i\\ctrl-\\right\\ctrl-\\rightX\\esc", "foo barX"); 1126 DoTest("foo", "\\endi\\ctrl-\\left\\ctrl-\\leftX", "Xfoo"); // we crashed here before 1127 1128 // Special keys: enter, return, insert, etc. 1129 DoTest("", "ifoo\\enterbar", "foo\nbar"); 1130 DoTest("", "ifoo\\returnbar", "foo\nbar"); 1131 DoTest("", "\\insertfoo", "foo"); 1132 DoTest("foo bar", "i\\home\\delete", "oo bar"); 1133 1134 // BUG #451076, don't want an extra newline when using the "Find" action from the menu or Ctrl-F 1135 BaseTest::ensureKateViewVisible(); // required for the bug to trigger 1136 BeginTest("foobar"); 1137 TestPressKey("i"); 1138 kate_view->find(); 1139 TestPressKey("bar\\return"); 1140 // ensure the cursor is at 'foo_b_ar' 1141 QCOMPARE(kate_view->cursorPosition().line(), 0); 1142 QCOMPARE(kate_view->cursorPosition().column(), 3); 1143 FinishTest("foobar"); 1144 // hide the view again 1145 kate_view->hide(); 1146 mainWindow->hide(); 1147 } 1148 1149 // END: Insert mode. 1150 1151 // BEGIN: Visual mode. 1152 1153 void ModesTest::VisualMotionsTests() 1154 { 1155 // Basic motions. 1156 DoTest("\n", "vjcX", "X"); 1157 DoTest("foobar", "vlllx", "ar"); 1158 DoTest("foo\nbar", "Vd", "bar"); 1159 DoTest("Hello.\nWorld", "2lvjcX", "HeXld"); 1160 DoTest("Three. Different. Sentences.\n\n", "vapcX", "X"); 1161 DoTest("1234\n1234\n1234", "l\\ctrl-vljjd", "14\n14\n14"); 1162 QCOMPARE(kate_view->blockSelection(), false); 1163 DoTest("Three. Different. Sentences.", "v)cX", "Xifferent. Sentences."); 1164 DoTest("Three. Different. Sentences.", "v)cX", "Xifferent. Sentences."); 1165 DoTest("Three. Different. Sentences.", "v)cX", "Xifferent. Sentences."); 1166 DoTest("Three. Different. Sentences.", "viWcX", "X Different. Sentences."); 1167 DoTest("Three. Different. Sentences.", "viwcX", "X. Different. Sentences."); 1168 DoTest("Three. Different. Sentences.", "vaWcX", "XDifferent. Sentences."); 1169 DoTest("Three. Different. Sentences.", "vawcX", "X. Different. Sentences."); 1170 DoTest("Three. Different. Sentences.", "vascX", "XDifferent. Sentences."); 1171 DoTest("Three. Different. Sentences.", "viscX", "X Different. Sentences."); 1172 DoTest("Three. Different. Sentences.", "vapcX", "X"); 1173 DoTest("Three. Different. Sentences.", "vipcX", "X"); 1174 DoTest("Hello.\n", "vap\\esciX", "Hello.\nX"); 1175 // Make sure cursor is properly moved to the start of paragraph and sentence text objects 1176 DoTest("Hello.\nWorld.", "jvapX", ""); 1177 DoTest("Hello.\nWorld.", "jvasX", "Hello.\n"); 1178 1179 // With count. 1180 DoTest("12345678", "lv3lyx", "1345678"); 1181 DoTest("12345678", "$hv3hyx", "1235678"); 1182 DoTest("aaa\nbbb", "lvj~x", "aA\nBBb"); 1183 DoTest("123\n456", "jlvkyx", "13\n456"); 1184 DoTest("12\n34", "lVjyx", "2\n34"); 1185 DoTest("ab\ncd", "jVlkgux", "a\ncd"); 1186 DoTest("ABCD\nABCD\nABCD\nABCD", "lj\\ctrl-vjlgux", "ABCD\nAcD\nAbcD\nABCD"); 1187 DoTest("abcd\nabcd\nabcd\nabcd", "jjjlll\\ctrl-vkkhgUx", "abcd\nabD\nabCD\nabCD"); 1188 1189 // Cancelling visual mode should not reset the cursor. 1190 DoTest("12345678", "lv3l\\escx", "1234678"); 1191 DoTest("12345678", "lv3l\\ctrl-cx", "1234678"); 1192 1193 // Don't forget to clear the flag that says we shouldn't reset the cursor, though! 1194 DoTest("12345678", "lv3l\\ctrl-cxv3lyx", "123478"); 1195 DoTest("12345678", "y\\escv3lyx", "2345678"); 1196 1197 // Regression test for ][ in Visual Mode. 1198 DoTest("foo {\n\n}", "lV][d", ""); 1199 1200 // Misc tests for motions starting in front of the Visual Mode start point. 1201 DoTest("{foo}", "lvb%x", "{"); 1202 DoTest("foo bar", "wvbfax", "foo r"); 1203 DoTest("(foo bar)", "wwv^%x", "(foo "); 1204 1205 // * and # 1206 DoTest("foo foo", "v*x", "oo"); 1207 DoTest("foo foo", "wv#x", "oo"); 1208 1209 // Quick test that "{" and "}" motions work in visual mode 1210 DoTest("foo\n\n\nbar\n", "v}}d", ""); 1211 DoTest("\n\nfoo\nbar\n", "jjjv{d", "\nar\n"); 1212 1213 // ctrl-left and ctrl-right 1214 DoTest("foo bar xyz", "v\\ctrl-\\rightd", "ar xyz"); 1215 DoTest("foo bar xyz", "$v\\ctrl-\\leftd", "foo bar "); 1216 } 1217 1218 void ModesTest::VisualCommandsTests() 1219 { 1220 // Testing "d" 1221 DoTest("foobarbaz", "lvlkkjl2ld", "fbaz"); 1222 DoTest("foobar", "v$d", ""); 1223 DoTest("foo\nbar\nbaz", "jVlld", "foo\nbaz"); 1224 DoTest("01\n02\n03\n04\n05", "Vjdj.", "03"); 1225 1226 // Testing Del key 1227 DoTest("foobarbaz", "lvlkkjl2l\\delete", "fbaz"); 1228 1229 // Testing "D" 1230 DoTest("foo\nbar\nbaz", "lvjlD", "baz"); 1231 DoTest("foo\nbar", "l\\ctrl-vjD", "f\nb"); 1232 DoTest("foo\nbar", "VjkD", "bar"); 1233 DoTest("Test:\n - One\n - Two", "jfnVDia", "Test:\n a- Two"); 1234 DoTest("Test:\n - One\n - Two", "jjfwVDia", "Test:\n a- One"); 1235 1236 // Testing "gU", "U" 1237 DoTest("foo bar", "vwgU", "FOO Bar"); 1238 DoTest("foo\nbar\nbaz", "VjjU", "FOO\nBAR\nBAZ"); 1239 DoTest("foo\nbar\nbaz", "\\ctrl-vljjU", "FOo\nBAr\nBAz"); 1240 DoTest("aaaa\nbbbb\ncccc", "\\ctrl-vljgUjll.", "AAaa\nBBBB\nccCC"); 1241 1242 // Testing "gu", "u" 1243 DoTest("TEST", "Vgu", "test"); 1244 DoTest("TeSt", "vlgu", "teSt"); 1245 DoTest("FOO\nBAR\nBAZ", "\\ctrl-vljju", "foO\nbaR\nbaZ"); 1246 DoTest("AAAA\nBBBB\nCCCC\nDDDD", "vjlujjl.", "aaaa\nbbBB\nCccc\ndddD"); 1247 1248 // Testing "gv" 1249 DoTest("foo\nbar\nxyz", "l\\ctrl-vjj\\ctrl-cgvr.", "f.o\nb.r\nx.z"); 1250 1251 // Testing "g~" 1252 DoTest("fOo bAr", "Vg~", "FoO BaR"); 1253 DoTest("foo\nbAr\nxyz", "l\\ctrl-vjjg~", "fOo\nbar\nxYz"); 1254 1255 // Testing "y" 1256 DoTest("foobar", "Vypp", "foobar\nfoobar\nfoobar"); 1257 DoTest("foo\nbar", "lvjlyp", "fooo\nbaro\nbar"); 1258 DoTest("foo\nbar", "Vjlllypddxxxdd", "foo\nbar"); 1259 DoTest("12\n12", "\\ctrl-vjyp", "112\n112"); 1260 DoTest("1234\n1234\n1234\n1234", "lj\\ctrl-vljyp", "1234\n122334\n122334\n1234"); 1261 1262 // Testing "Y" 1263 DoTest("foo\nbar", "llvjypx", "foo\nbar\nbar"); 1264 DoTest("foo\nbar", "VYp", "foo\nfoo\nbar"); 1265 1266 // Testing "m." 1267 DoTest("foo\nbar", "vljmavgg`ax", "foo\nbr"); 1268 DoTest("1\n2\n3\n4", "Vjmajjmb\\:'a,'bd\\", "1"); 1269 1270 // Testing ">" 1271 DoTest("foo\nbar", "vj>", " foo\n bar"); 1272 DoTest("foo\nbar\nbaz", "jVj>", "foo\n bar\n baz"); 1273 DoTest("foo", "vl3>", " foo"); 1274 DoTest("indent\nrepeat", "V>.", " indent\nrepeat"); 1275 DoTest("indent\nrepeat", "Vj>.", " indent\n repeat"); 1276 DoTest("indent\nrepeat\non\nothers", "Vj>jj.", " indent\n repeat\n on\n others"); 1277 DoTest("foo\nbar\nbaz", "jjVk>.", "foo\n bar\n baz"); 1278 1279 // Testing "<" 1280 DoTest(" foo", "vl<", "foo"); 1281 DoTest("foo\n bar\n baz", "jjVk<.", "foo\nbar\nbaz"); 1282 1283 // Testing "o" 1284 DoTest("foobar", "lv2lo2ld", "fooar"); 1285 DoTest("foo\nbar", "jvllokld", "f"); 1286 DoTest("12\n12", "\\ctrl-vjlold", "1\n1"); 1287 1288 // Testing "~" 1289 DoTest("foobar", "lv2l~", "fOOBar"); 1290 DoTest("FooBar", "V~", "fOObAR"); 1291 DoTest("foo\nbar", "\\ctrl-vjl~", "FOo\nBAr"); 1292 1293 // Testing "r" 1294 DoTest("foobar", "Vra", "aaaaaa"); 1295 DoTest("foo\nbar", "jlvklrx", "fox\nxxr"); 1296 DoTest("123\n123", "l\\ctrl-vljrx", "1xx\n1xx"); 1297 DoTest("a", "r\\ctrl-c", "a"); 1298 DoTest("a", "r\\ctrl-[", "a"); 1299 DoTest("a", "r\\keypad-0", "0"); 1300 DoTest("a", "r\\keypad-9", "9"); 1301 DoTest("foo\nbar", "l\\ctrl-vjr\\keypad-9", "f9o\nb9r"); 1302 1303 // Testing "gq" 1304 DoTest("foo\nbar\nbaz", "Vgq", "foo\nbar\nbaz"); 1305 DoTest("foo\nbar\nbaz", "Vjgq", "foo bar\nbaz"); 1306 1307 // Testing "<<"/">>" 1308 kate_document->config()->setReplaceTabsDyn(true); 1309 DoTest("foo\nbar\nbaz", "V>>", " foo\nbar\nbaz"); 1310 DoTest("foo\nbar\nbaz", "Vj>>", " foo\n bar\nbaz"); 1311 DoTest("foo\nbar\nbaz", "V2j>>", " foo\n bar\n baz"); 1312 DoTest("foo\nbar\nbaz", "V10>>", " foo\nbar\nbaz"); 1313 DoTest("foo\nbar\nbaz", "V2j3>>", " foo\n bar\n baz"); 1314 1315 DoTest(" foo\nbar\nbaz", "V<<", "foo\nbar\nbaz"); 1316 DoTest("foo\nbar\nbaz", "V>>V<<", "foo\nbar\nbaz"); 1317 DoTest(" foo\n bar\n baz", "V2j<<", " foo\n bar\n baz"); 1318 1319 // Testing block append 1320 DoTest("averyverylongline\nshortline\nshorter\n", "jjV$kkAb\\esc", "averyverylonglineb\nshortlineb\nshorterb\n"); 1321 DoTest("averyverylongline\nshortline\n", "V$jAb\\esc", "averyverylonglineb\nshortlineb\n"); 1322 1323 // Testing "J" 1324 DoTest("foo\nbar\nxyz\nbaz\n123\n456", "jVjjjJ", "foo\nbar xyz baz 123\n456"); 1325 DoTest("foo\nbar\nxyz\nbaz\n123\n456", "jjjjVkkkJ", "foo\nbar xyz baz 123\n456"); 1326 DoTest("foo\nbar\nxyz\nbaz\n123456\n789", "jjjjVkkkJrX", "foo\nbar xyz bazX123456\n789"); 1327 DoTest("foo\nbar\nxyz\n", "VGJ", "foo bar xyz "); 1328 1329 // Testing undo behaviour with c and cc 1330 DoTest("foo", "ciwbar\\escu", "foo"); 1331 DoTest("foo", "ccbar\\escu", "foo"); 1332 1333 // Pasting should replace the current selection. 1334 DoTest("foo bar xyz", "yiwwviwp", "foo foo xyz"); 1335 1336 // Undo should undo both paste and removal of selection. 1337 DoTest("foo bar xyz", "yiwwviwpu", "foo bar xyz"); 1338 DoTest("foo\nbar\n123\nxyz", "yiwjVjp", "foo\nfoo\nxyz"); 1339 1340 // Set the *whole* selection to the given text object, even if the cursor is no 1341 // longer at the position where Visual Mode was started. 1342 // This seems to work (in Vim) only when the start of the given text object occurs before them 1343 // start position of Visual Mode. 1344 DoTest("{\nfoo\nbar\nxyz\n}", "jjvliBd", "{\n}"); 1345 DoTest("foo[hello]", "fhlvli[d", "foo[]"); 1346 DoTest("foo(hello)", "fhlvli(d", "foo()"); 1347 DoTest("foo<hello>", "fhlvli<d", "foo<>"); 1348 DoTest("foo\"hello\"", "fhlvli\"d", "foo\"\""); 1349 DoTest("foo'hello'", "fhlvli'd", "foo''"); 1350 1351 // A couple of spot tests, where the beginning of the text object occurs after the start position of Visual Mode; 1352 // the selection should remain unchanged if we the text object motion is triggered, here. 1353 DoTest("foobarxyz\n(12345)", "llvjibd", "fo345)"); 1354 DoTest("foobarxyz\n{12345}", "llvjiBd", "fo345}"); 1355 // Cursor should end up at the end of the text object. 1356 DoTest("foo[hello]", "fhlvli[\\escrX", "foo[hellX]"); 1357 // Ensure we reset the flag that says that the current motion is a text object! 1358 DoTest("foo[hello]", "jfhlvli[^d", "ello]"); 1359 1360 // proper yanking in block mode 1361 { 1362 BeginTest("aaaa\nbbbb\ncccc\ndddd"); 1363 TestPressKey("lj\\ctrl-vljy"); 1364 KateBuffer &buffer = kate_document->buffer(); 1365 QVector<Kate::TextRange *> ranges = buffer.rangesForLine(1, kate_view, true); 1366 QCOMPARE(ranges.size(), 1); 1367 KTextEditor::Range range = ranges[0]->toRange(); 1368 QCOMPARE(range.start().column(), 1); 1369 QCOMPARE(range.end().column(), 3); 1370 } 1371 1372 // proper selection in block mode after switching to cmdline 1373 { 1374 BeginTest("aaaa\nbbbb\ncccc\ndddd"); 1375 TestPressKey("lj\\ctrl-vlj:"); 1376 QCOMPARE(kate_view->selectionText(), QString("bb\ncc")); 1377 } 1378 1379 // BUG #328277 - make sure kate doesn't crash 1380 BeginTest("aaa\nbbb"); 1381 TestPressKey("Vj>u>."); 1382 QCOMPARE(kate_view->renderer()->caretStyle(), KateRenderer::Block); 1383 FinishTest("aaa\nbbb"); 1384 } 1385 1386 void ModesTest::VisualExternalTests() 1387 { 1388 // Test that selecting a range "externally" to Vim (i.e. via the mouse, or 1389 // one of the ktexteditor api's) switches us into Visual Mode. 1390 BeginTest("foo bar"); 1391 1392 // Actually selects "oo " (i.e. without the "b"). 1393 kate_view->setSelection(Range(0, 1, 0, 4)); 1394 TestPressKey("d"); 1395 FinishTest("fbar"); 1396 1397 // Always return to normal mode when undoing/redoing. 1398 BeginTest(""); 1399 TestPressKey("iHello World!\\esc"); 1400 TestPressKey("0wvlldu"); 1401 QCOMPARE(vi_input_mode_manager->getCurrentViMode(), KateVi::NormalMode); 1402 QCOMPARE(kate_view->selectionText(), QString("")); 1403 QCOMPARE(kate_document->text(), QString("Hello World!")); 1404 TestPressKey("u"); 1405 QCOMPARE(vi_input_mode_manager->getCurrentViMode(), KateVi::NormalMode); 1406 QCOMPARE(kate_document->text(), QString("")); 1407 TestPressKey("\\ctrl-r"); 1408 QCOMPARE(vi_input_mode_manager->getCurrentViMode(), KateVi::NormalMode); 1409 FinishTest("Hello World!"); 1410 1411 // Make sure that we don't screw up selection after an undo. 1412 BeginTest("Hola\nHola\nHello\nHallo\n"); 1413 TestPressKey("jVjduVk"); 1414 QCOMPARE(vi_input_mode_manager->getCurrentViMode(), KateVi::VisualLineMode); 1415 QCOMPARE(kate_view->selectionText(), QString("Hola\nHello")); 1416 FinishTest("Hola\nHola\nHello\nHallo\n"); 1417 1418 // Test that, if kate_view has a selection before the Vi mode stuff is loaded, then we 1419 // end up in Visual Mode: this mimics what happens if we click on a Find result in 1420 // KDevelop's "grepview" plugin. 1421 delete kate_view; 1422 kate_view = new KTextEditor::ViewPrivate(kate_document, mainWindow); 1423 kate_view->setInputMode(View::NormalInputMode); 1424 mainWindowLayout->addWidget(kate_view); 1425 kate_document->setText("foo bar"); 1426 kate_view->setSelection(Range(Cursor(0, 1), Cursor(0, 4))); 1427 QCOMPARE(kate_document->text(kate_view->selectionRange()), QString("oo ")); 1428 kate_view->setInputMode(View::ViInputMode); 1429 qDebug() << "selected: " << kate_document->text(kate_view->selectionRange()); 1430 QVERIFY(kate_view->currentInputMode()->viewInputMode() == View::ViInputMode); 1431 vi_input_mode = dynamic_cast<KateViInputMode *>(kate_view->currentInputMode()); 1432 vi_input_mode_manager = vi_input_mode->viInputModeManager(); 1433 QVERIFY(vi_input_mode_manager->getCurrentViMode() == KateVi::VisualMode); 1434 TestPressKey("l"); 1435 QCOMPARE(kate_document->text(kate_view->selectionRange()), QString("oo b")); 1436 TestPressKey("d"); 1437 QCOMPARE(kate_document->text(), QString("far")); 1438 1439 // Test returning to correct mode when selecting ranges with mouse 1440 BeginTest("foo bar\nbar baz"); 1441 TestPressKey("i"); // get me into insert mode 1442 kate_view->setSelection(Range(0, 1, 1, 4)); 1443 QCOMPARE((int)vi_input_mode_manager->getCurrentViMode(), (int)KateVi::VisualMode); 1444 kate_view->setSelection(Range::invalid()); 1445 QCOMPARE((int)vi_input_mode_manager->getCurrentViMode(), (int)KateVi::InsertMode); 1446 TestPressKey("\\esc"); // get me into normal mode 1447 kate_view->setSelection(Range(0, 1, 1, 4)); 1448 QCOMPARE((int)vi_input_mode_manager->getCurrentViMode(), (int)KateVi::VisualMode); 1449 kate_view->setSelection(Range::invalid()); 1450 QCOMPARE((int)vi_input_mode_manager->getCurrentViMode(), (int)KateVi::NormalMode); 1451 } 1452 1453 // END: Visual mode. 1454 1455 // BEGIN: Command mode. 1456 1457 void ModesTest::CommandTests() 1458 { 1459 // Testing ":<num>" 1460 DoTest("foo\nbar\nbaz", "\\:2\\x", "foo\nar\nbaz"); 1461 DoTest("foo\nbar\nbaz", "jmak\\:'a\\x", "foo\nar\nbaz"); 1462 DoTest("foo\nbar\nbaz", "\\:$\\x", "foo\nbar\naz"); 1463 1464 // Testing ":y", ":yank" 1465 DoTest("foo\nbar\nbaz", "\\:3y\\p", "foo\nbaz\nbar\nbaz"); 1466 DoTest("foo\nbar\nbaz", "\\:2y a 2\\\"ap", "foo\nbar\nbaz\nbar\nbaz"); 1467 DoTest("foo\nbar\nbaz", "\\:y\\p", "foo\nfoo\nbar\nbaz"); 1468 DoTest("foo\nbar\nbaz", "\\:3,1y\\p", "foo\nfoo\nbar\nbaz\nbar\nbaz"); 1469 1470 // Testing ">" 1471 DoTest("foo", "\\:>\\", " foo"); 1472 DoTest(" foo", "\\:<\\", " foo"); 1473 1474 DoTest("foo\nbar", "\\:2>\\", "foo\n bar"); 1475 DoTest(" foo\nbaz", "\\:1<\\", " foo\nbaz"); 1476 1477 DoTest("foo\nundo", "\\:2>\\u", "foo\nundo"); 1478 DoTest(" foo\nundo", "\\:1<\\u", " foo\nundo"); 1479 1480 DoTest("indent\nmultiline\ntext", "\\:1,2>\\", " indent\n multiline\ntext"); 1481 DoTest("indent\nmultiline\n+undo", "\\:1,2>\\:1,2>\\:1,2>\\u", " indent\n multiline\n+undo"); 1482 // doesn't test correctly, why? 1483 // DoTest("indent\nmultiline\n+undo", "\\:1,2>\\:1,2<\\u", " indent\n multiline\n+undo"); 1484 1485 // Testing ":c", ":change" 1486 DoTest("foo\nbar\nbaz", "\\:2change\\", "foo\n\nbaz"); 1487 DoTest("foo\nbar\nbaz", "\\:%c\\", ""); 1488 BeginTest("foo\nbar\nbaz"); 1489 TestPressKey("\\:$c\\"); // Work around ambiguity in the code that parses commands to execute. 1490 TestPressKey("\\:$change\\"); 1491 FinishTest("foo\nbar\n"); 1492 DoTest("foo\nbar\nbaz", "ma\\:2,'achange\\", "\nbaz"); 1493 DoTest("foo\nbar\nbaz", "\\:2,3c\\", "foo\n"); 1494 1495 // Testing ":j" 1496 DoTest("1\n2\n3\n4\n5", "\\:2,4j\\", "1\n2 3 4\n5"); 1497 1498 DoTest("1\n2\n3\n4", "jvj\\ctrl-c\\:'<,'>d\\enter", "1\n4"); 1499 DoTest("1\n2\n3\n4", "\\:1+1+1+1d\\", "1\n2\n3"); 1500 DoTest("1\n2\n3\n4", "2j\\:.,.-1d\\", "1\n4"); 1501 DoTest("1\n2\n3\n4", "\\:.+200-100-100+20-5-5-5-5+.-.,$-1+1-2+2-3+3-4+4-5+5-6+6-7+7-1000+1000+0-0-$+$-.+.-1d\\", "4"); 1502 DoTest("1\n2\n3\n4", "majmbjmcjmdgg\\:'a+'b+'d-'c,.d\\", ""); 1503 } 1504 1505 void ModesTest::CommandSedTests() 1506 { 1507 DoTest("foo", "\\:s/foo/bar\\", "bar"); 1508 DoTest("foobarbaz", "\\:s/bar/xxx\\", "fooxxxbaz"); 1509 DoTest("foo", "\\:s/bar/baz\\", "foo"); 1510 DoTest("foo\nfoo\nfoo", "j\\:s/foo/bar\\", "foo\nbar\nfoo"); 1511 DoTest("foo\nfoo\nfoo", "2jma2k\\:'a,'as/foo/bar\\", "foo\nfoo\nbar"); 1512 DoTest("foo\nfoo\nfoo", "\\:%s/foo/bar\\", "bar\nbar\nbar"); 1513 DoTest("foo\nfoo\nfoo", "\\:2,3s/foo/bar\\", "foo\nbar\nbar"); 1514 DoTest("foo\nfoo\nfoo\nfoo", "j2lmajhmbgg\\:'a,'bs/foo/bar\\", "foo\nbar\nbar\nfoo"); 1515 DoTest("foo\nfoo\nfoo\nfoo", "jlma2jmbgg\\:'b,'as/foo/bar\\", "foo\nbar\nbar\nbar"); 1516 DoTest("foo", "\\:s/$/x/g\\", "foox"); 1517 DoTest("foo", "\\:s/.*/x/g\\", "x"); 1518 DoTest("abc", "\\:s/\\\\s*/x/g\\", "xaxbxc"); 1519 // DoTest("abc\n123", "\\:s/\\\\s*/x/g\\", "xaxbxc\nx1x2x3"); // currently not working properly 1520 1521 DoTest("foo/bar", "\\:s-/--\\", "foobar"); 1522 DoTest("foo/bar", "\\:s_/__\\", "foobar"); 1523 1524 DoTest("foo\nfoo\nfoo", "\\:2s/foo/bar\\", "foo\nbar\nfoo"); 1525 DoTest("foo\nfoo\nfoo", "2jmagg\\:'as/foo/bar\\", "foo\nfoo\nbar"); 1526 DoTest("foo\nfoo\nfoo", "\\:$s/foo/bar\\", "foo\nfoo\nbar"); 1527 1528 // https://bugs.kde.org/show_bug.cgi?id=235862 1529 DoTest("try\n\nalso\nfoo", "\\:/r/,/o/s/^/ha/\\", "hatry\nha\nhaalso\nfoo"); 1530 DoTest("much\nmuch\nmuch\nmuch", "\\:.,.+2s/much/try/\\", "try\ntry\ntry\nmuch"); 1531 } 1532 1533 void ModesTest::CommandDeleteTests() 1534 { 1535 DoTest("foo\nbar\nbaz", "\\:2d\\", "foo\nbaz"); 1536 DoTest("foo\nbar\nbaz", "\\:%d\\", ""); 1537 BeginTest("foo\nbar\nbaz"); 1538 TestPressKey("\\:$d\\"); // Work around ambiguity in the code that parses commands to execute. 1539 TestPressKey("\\:$d\\"); 1540 FinishTest("foo"); 1541 DoTest("foo\nbar\nbaz", "ma\\:2,'ad\\", "baz"); 1542 DoTest("foo\nbar\nbaz", "\\:/foo/,/bar/d\\", "baz"); 1543 DoTest("foo\nbar\nbaz", "\\:2,3delete\\", "foo"); 1544 1545 DoTest("foo\nbar\nbaz", "\\:d\\", "bar\nbaz"); 1546 DoTest("foo\nbar\nbaz", "\\:d 33\\", ""); 1547 DoTest("foo\nbar\nbaz", "\\:3d a\\k\"ap", "foo\nbaz\nbar"); 1548 } 1549 1550 // END: Command mode. 1551 1552 // BEGIN: Replace mode. 1553 1554 void ModesTest::ReplaceCharacter() 1555 { 1556 DoTest("", "rr", ""); 1557 DoTest("a", "rb", "b"); 1558 DoTest("abc", "lr\\enter", "a\nc"); 1559 DoTest("abc", "l\\backspace", "abc"); 1560 DoTest("abc", "l\\left", "abc"); 1561 } 1562 1563 void ModesTest::ReplaceBasicTests() 1564 { 1565 // Basic stuff. 1566 DoTest("", "Rqwerty", "qwerty"); 1567 DoTest("qwerty", "R\\rightXX", "qXXrty"); 1568 1569 // Enter replace and go to the next/previous word. 1570 DoTest("foo bar", "R\\ctrl-\\rightX", "foo Xar"); 1571 DoTest("foo bar", "R\\ctrl-\\right\\ctrl-\\rightX", "foo barX"); 1572 DoTest("foo bar", "R\\ctrl-\\leftX", "Xoo bar"); 1573 DoTest("foo bar", "R\\ctrl-\\left\\delete", "oo bar"); 1574 1575 // Enter replace mode and go up/down. 1576 DoTest("foo\nbar\nbaz", "R\\downX", "foo\nXar\nbaz"); 1577 DoTest("foo\nbar\nbaz", "jjR\\upX", "foo\nXar\nbaz"); 1578 1579 // Repeat replacements 1580 DoTest("foobaz", "Rbar\\esc.", "babarz"); 1581 DoTest("foobarbaz", "Rbar\\esc2.", "babarbarz"); 1582 DoTest("foobarbaz", "Rbar\\esc4.", "babarbarbarbar"); 1583 DoTest("foobarbaz", "Rbar\\esc2.R\\esc2.", "babarbarz"); 1584 1585 // BUG #451076, don't want an extra newline when using the "Find" action from the menu or Ctrl-F 1586 BaseTest::ensureKateViewVisible(); // required for the bug to trigger 1587 BeginTest("foobar"); 1588 TestPressKey("R"); 1589 kate_view->find(); 1590 TestPressKey("bar\\return"); 1591 // ensure the cursor is at 'foo_b_ar' 1592 QCOMPARE(kate_view->cursorPosition().line(), 0); 1593 QCOMPARE(kate_view->cursorPosition().column(), 3); 1594 FinishTest("foobar"); 1595 // hide the view again 1596 kate_view->hide(); 1597 mainWindow->hide(); 1598 } 1599 1600 void ModesTest::ReplaceUndoTests() 1601 { 1602 // Backspace. 1603 DoTest("", "R\\backspace", ""); 1604 DoTest("qwerty", "lR\\backspaceX", "Xwerty"); 1605 DoTest("qwerty", "lRX\\backspace\\backspaceX", "Xwerty"); 1606 1607 // Ctrl-W 1608 DoTest("", "R\\ctrl-w", ""); 1609 DoTest("Hello", "lRXX\\ctrl-w", "Hello"); 1610 DoTest("Hello", "lR\t\\ctrl-w", "Hello"); 1611 DoTest("Hello", "lRXX\\left\\ctrl-w", "HXXlo"); 1612 1613 // Ctrl-U 1614 DoTest("", "R\\ctrl-u", ""); 1615 DoTest("Hello", "lRXX\\ctrl-u", "Hello"); 1616 DoTest("Hello", "lR\t\\ctrl-u", "Hello"); 1617 DoTest("Hello", "lRXX\\left\\ctrl-u", "HXXlo"); 1618 DoTest("Hello World", "3lRXX XX\\ctrl-u", "Hello World"); 1619 } 1620 1621 void ModesTest::ReplaceInsertFromLineTests() 1622 { 1623 // Ctrl-E: replace the current column with the column of the next line. 1624 DoTest("", "R\\ctrl-e", ""); 1625 DoTest("\n", "jR\\ctrl-e", "\n"); 1626 DoTest("\nqwerty", "R\\ctrl-e\\ctrl-e", "qw\nqwerty"); 1627 DoTest("a\nbb", "R\\ctrl-e\\ctrl-e", "bb\nbb"); 1628 DoTest("aa\n b", "R\\ctrl-e\\ctrl-e", " b\n b"); 1629 DoTest("\n\tb", "R\\ctrl-e\\ctrl-e", "\tb\n\tb"); 1630 1631 // Ctrl-Y: replace the current column with the column of the previous line. 1632 DoTest("", "R\\ctrl-y", ""); 1633 DoTest("qwerty\n", "jR\\ctrl-y\\ctrl-y", "qwerty\nqw"); 1634 DoTest("aa\nb", "jR\\ctrl-y\\ctrl-y", "aa\naa"); 1635 DoTest(" a\nbb", "jR\\ctrl-y\\ctrl-y", " a\n a"); 1636 DoTest("\tb\n", "jR\\ctrl-y\\ctrl-y", "\tb\n\tb"); 1637 } 1638 1639 // END: Replace mode. 1640 1641 #include "moc_modes.cpp"