TextViewTests.cs 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  1. using System;
  2. using Xunit;
  3. namespace Terminal.Gui {
  4. public class TextViewTests {
  5. private TextView _textView;
  6. public TextViewTests ()
  7. {
  8. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  9. // 1 2 3
  10. // 01234567890123456789012345678901=32 (Length)
  11. var txt = "TAB to jump between text fields.";
  12. var buff = new byte [txt.Length];
  13. for (int i = 0; i < txt.Length; i++) {
  14. buff [i] = (byte)txt [i];
  15. }
  16. var ms = new System.IO.MemoryStream (buff).ToArray ();
  17. _textView = new TextView () { Width = 30, Height = 10 };
  18. _textView.Text = ms;
  19. }
  20. [Fact]
  21. public void Changing_Selection_Or_CursorPosition_Update_SelectedLength_And_SelectedText ()
  22. {
  23. _textView.SelectionStartColumn = 2;
  24. _textView.SelectionStartRow = 0;
  25. Assert.Equal (0, _textView.CursorPosition.X);
  26. Assert.Equal (0, _textView.CursorPosition.Y);
  27. Assert.Equal (2, _textView.SelectedLength);
  28. Assert.Equal ("TA", _textView.SelectedText);
  29. _textView.CursorPosition = new Point (20, 0);
  30. Assert.Equal (2, _textView.SelectionStartColumn);
  31. Assert.Equal (0, _textView.SelectionStartRow);
  32. Assert.Equal (18, _textView.SelectedLength);
  33. Assert.Equal ("B to jump between ", _textView.SelectedText);
  34. }
  35. [Fact]
  36. public void Selection_With_Value_Less_Than_Zero_Changes_To_Zero ()
  37. {
  38. _textView.SelectionStartColumn = -2;
  39. _textView.SelectionStartRow = -2;
  40. Assert.Equal (0, _textView.SelectionStartColumn);
  41. Assert.Equal (0, _textView.SelectionStartRow);
  42. Assert.Equal (0, _textView.SelectedLength);
  43. Assert.Equal ("", _textView.SelectedText);
  44. }
  45. [Fact]
  46. public void Selection_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  47. {
  48. _textView.CursorPosition = new Point (2, 0);
  49. _textView.SelectionStartColumn = 33;
  50. _textView.SelectionStartRow = 1;
  51. Assert.Equal (32, _textView.SelectionStartColumn);
  52. Assert.Equal (0, _textView.SelectionStartRow);
  53. Assert.Equal (30, _textView.SelectedLength);
  54. Assert.Equal ("B to jump between text fields.", _textView.SelectedText);
  55. }
  56. [Fact]
  57. public void Selection_With_Empty_Text ()
  58. {
  59. _textView = new TextView ();
  60. _textView.CursorPosition = new Point (2, 0);
  61. _textView.SelectionStartColumn = 33;
  62. _textView.SelectionStartRow = 1;
  63. Assert.Equal (0, _textView.SelectionStartColumn);
  64. Assert.Equal (0, _textView.SelectionStartRow);
  65. Assert.Equal (0, _textView.SelectedLength);
  66. Assert.Equal ("", _textView.SelectedText);
  67. }
  68. [Fact]
  69. public void Selection_And_CursorPosition_With_Value_Greater_Than_Text_Length_Changes_Both_To_Text_Length ()
  70. {
  71. _textView.CursorPosition = new Point (33, 2);
  72. _textView.SelectionStartColumn = 33;
  73. _textView.SelectionStartRow = 33;
  74. Assert.Equal (32, _textView.CursorPosition.X);
  75. Assert.Equal (0, _textView.CursorPosition.Y);
  76. Assert.Equal (32, _textView.SelectionStartColumn);
  77. Assert.Equal (0, _textView.SelectionStartRow);
  78. Assert.Equal (0, _textView.SelectedLength);
  79. Assert.Equal ("", _textView.SelectedText);
  80. }
  81. [Fact]
  82. public void CursorPosition_With_Value_Less_Than_Zero_Changes_To_Zero ()
  83. {
  84. _textView.CursorPosition = new Point (-1, -1);
  85. Assert.Equal (0, _textView.CursorPosition.X);
  86. Assert.Equal (0, _textView.CursorPosition.Y);
  87. Assert.Equal (0, _textView.SelectedLength);
  88. Assert.Equal ("", _textView.SelectedText);
  89. }
  90. [Fact]
  91. public void CursorPosition_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  92. {
  93. _textView.CursorPosition = new Point (33, 1);
  94. Assert.Equal (32, _textView.CursorPosition.X);
  95. Assert.Equal (0, _textView.CursorPosition.Y);
  96. Assert.Equal (0, _textView.SelectedLength);
  97. Assert.Equal ("", _textView.SelectedText);
  98. }
  99. [Fact]
  100. public void WordForward_With_No_Selection ()
  101. {
  102. _textView.CursorPosition = new Point (0, 0);
  103. var iteration = 0;
  104. while (_textView.CursorPosition.X < _textView.Text.Length) {
  105. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()));
  106. switch (iteration) {
  107. case 0:
  108. Assert.Equal (4, _textView.CursorPosition.X);
  109. Assert.Equal (0, _textView.CursorPosition.Y);
  110. Assert.Equal (0, _textView.SelectionStartColumn);
  111. Assert.Equal (0, _textView.SelectionStartRow);
  112. Assert.Equal (0, _textView.SelectedLength);
  113. Assert.Equal ("", _textView.SelectedText);
  114. break;
  115. case 1:
  116. Assert.Equal (7, _textView.CursorPosition.X);
  117. Assert.Equal (0, _textView.CursorPosition.Y);
  118. Assert.Equal (0, _textView.SelectionStartColumn);
  119. Assert.Equal (0, _textView.SelectionStartRow);
  120. Assert.Equal (0, _textView.SelectedLength);
  121. Assert.Equal ("", _textView.SelectedText);
  122. break;
  123. case 2:
  124. Assert.Equal (12, _textView.CursorPosition.X);
  125. Assert.Equal (0, _textView.CursorPosition.Y);
  126. Assert.Equal (0, _textView.SelectionStartColumn);
  127. Assert.Equal (0, _textView.SelectionStartRow);
  128. Assert.Equal (0, _textView.SelectedLength);
  129. Assert.Equal ("", _textView.SelectedText);
  130. break;
  131. case 3:
  132. Assert.Equal (20, _textView.CursorPosition.X);
  133. Assert.Equal (0, _textView.CursorPosition.Y);
  134. Assert.Equal (0, _textView.SelectionStartColumn);
  135. Assert.Equal (0, _textView.SelectionStartRow);
  136. Assert.Equal (0, _textView.SelectedLength);
  137. Assert.Equal ("", _textView.SelectedText);
  138. break;
  139. case 4:
  140. Assert.Equal (25, _textView.CursorPosition.X);
  141. Assert.Equal (0, _textView.CursorPosition.Y);
  142. Assert.Equal (0, _textView.SelectionStartColumn);
  143. Assert.Equal (0, _textView.SelectionStartRow);
  144. Assert.Equal (0, _textView.SelectedLength);
  145. Assert.Equal ("", _textView.SelectedText);
  146. break;
  147. case 5:
  148. Assert.Equal (32, _textView.CursorPosition.X);
  149. Assert.Equal (0, _textView.CursorPosition.Y);
  150. Assert.Equal (0, _textView.SelectionStartColumn);
  151. Assert.Equal (0, _textView.SelectionStartRow);
  152. Assert.Equal (0, _textView.SelectedLength);
  153. Assert.Equal ("", _textView.SelectedText);
  154. break;
  155. }
  156. iteration++;
  157. }
  158. }
  159. [Fact]
  160. public void WordBackward_With_No_Selection ()
  161. {
  162. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  163. var iteration = 0;
  164. while (_textView.CursorPosition.X > 0) {
  165. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()));
  166. switch (iteration) {
  167. case 0:
  168. Assert.Equal (25, _textView.CursorPosition.X);
  169. Assert.Equal (0, _textView.CursorPosition.Y);
  170. Assert.Equal (0, _textView.SelectionStartColumn);
  171. Assert.Equal (0, _textView.SelectionStartRow);
  172. Assert.Equal (0, _textView.SelectedLength);
  173. Assert.Equal ("", _textView.SelectedText);
  174. break;
  175. case 1:
  176. Assert.Equal (20, _textView.CursorPosition.X);
  177. Assert.Equal (0, _textView.CursorPosition.Y);
  178. Assert.Equal (0, _textView.SelectionStartColumn);
  179. Assert.Equal (0, _textView.SelectionStartRow);
  180. Assert.Equal (0, _textView.SelectedLength);
  181. Assert.Equal ("", _textView.SelectedText);
  182. break;
  183. case 2:
  184. Assert.Equal (12, _textView.CursorPosition.X);
  185. Assert.Equal (0, _textView.CursorPosition.Y);
  186. Assert.Equal (0, _textView.SelectionStartColumn);
  187. Assert.Equal (0, _textView.SelectionStartRow);
  188. Assert.Equal (0, _textView.SelectedLength);
  189. Assert.Equal ("", _textView.SelectedText);
  190. break;
  191. case 3:
  192. Assert.Equal (7, _textView.CursorPosition.X);
  193. Assert.Equal (0, _textView.CursorPosition.Y);
  194. Assert.Equal (0, _textView.SelectionStartColumn);
  195. Assert.Equal (0, _textView.SelectionStartRow);
  196. Assert.Equal (0, _textView.SelectedLength);
  197. Assert.Equal ("", _textView.SelectedText);
  198. break;
  199. case 4:
  200. Assert.Equal (4, _textView.CursorPosition.X);
  201. Assert.Equal (0, _textView.CursorPosition.Y);
  202. Assert.Equal (0, _textView.SelectionStartColumn);
  203. Assert.Equal (0, _textView.SelectionStartRow);
  204. Assert.Equal (0, _textView.SelectedLength);
  205. Assert.Equal ("", _textView.SelectedText);
  206. break;
  207. case 5:
  208. Assert.Equal (0, _textView.CursorPosition.X);
  209. Assert.Equal (0, _textView.CursorPosition.Y);
  210. Assert.Equal (0, _textView.SelectionStartColumn);
  211. Assert.Equal (0, _textView.SelectionStartRow);
  212. Assert.Equal (0, _textView.SelectedLength);
  213. Assert.Equal ("", _textView.SelectedText);
  214. break;
  215. }
  216. iteration++;
  217. }
  218. }
  219. [Fact]
  220. public void WordForward_With_Selection ()
  221. {
  222. _textView.CursorPosition = new Point (0, 0);
  223. _textView.SelectionStartColumn = 0;
  224. _textView.SelectionStartRow = 0;
  225. var iteration = 0;
  226. while (_textView.CursorPosition.X < _textView.Text.Length) {
  227. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  228. switch (iteration) {
  229. case 0:
  230. Assert.Equal (4, _textView.CursorPosition.X);
  231. Assert.Equal (0, _textView.CursorPosition.Y);
  232. Assert.Equal (0, _textView.SelectionStartColumn);
  233. Assert.Equal (0, _textView.SelectionStartRow);
  234. Assert.Equal (4, _textView.SelectedLength);
  235. Assert.Equal ("TAB ", _textView.SelectedText);
  236. break;
  237. case 1:
  238. Assert.Equal (7, _textView.CursorPosition.X);
  239. Assert.Equal (0, _textView.CursorPosition.Y);
  240. Assert.Equal (0, _textView.SelectionStartColumn);
  241. Assert.Equal (0, _textView.SelectionStartRow);
  242. Assert.Equal (7, _textView.SelectedLength);
  243. Assert.Equal ("TAB to ", _textView.SelectedText);
  244. break;
  245. case 2:
  246. Assert.Equal (12, _textView.CursorPosition.X);
  247. Assert.Equal (0, _textView.CursorPosition.Y);
  248. Assert.Equal (0, _textView.SelectionStartColumn);
  249. Assert.Equal (0, _textView.SelectionStartRow);
  250. Assert.Equal (12, _textView.SelectedLength);
  251. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  252. break;
  253. case 3:
  254. Assert.Equal (20, _textView.CursorPosition.X);
  255. Assert.Equal (0, _textView.CursorPosition.Y);
  256. Assert.Equal (0, _textView.SelectionStartColumn);
  257. Assert.Equal (0, _textView.SelectionStartRow);
  258. Assert.Equal (20, _textView.SelectedLength);
  259. Assert.Equal ("TAB to jump between ", _textView.SelectedText);
  260. break;
  261. case 4:
  262. Assert.Equal (25, _textView.CursorPosition.X);
  263. Assert.Equal (0, _textView.CursorPosition.Y);
  264. Assert.Equal (0, _textView.SelectionStartColumn);
  265. Assert.Equal (0, _textView.SelectionStartRow);
  266. Assert.Equal (25, _textView.SelectedLength);
  267. Assert.Equal ("TAB to jump between text ", _textView.SelectedText);
  268. break;
  269. case 5:
  270. Assert.Equal (32, _textView.CursorPosition.X);
  271. Assert.Equal (0, _textView.CursorPosition.Y);
  272. Assert.Equal (0, _textView.SelectionStartColumn);
  273. Assert.Equal (0, _textView.SelectionStartRow);
  274. Assert.Equal (32, _textView.SelectedLength);
  275. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  276. break;
  277. }
  278. iteration++;
  279. }
  280. }
  281. [Fact]
  282. public void WordBackward_With_Selection ()
  283. {
  284. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  285. _textView.SelectionStartColumn = _textView.Text.Length;
  286. _textView.SelectionStartRow = 0;
  287. var iteration = 0;
  288. while (_textView.CursorPosition.X > 0) {
  289. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  290. switch (iteration) {
  291. case 0:
  292. Assert.Equal (25, _textView.CursorPosition.X);
  293. Assert.Equal (0, _textView.CursorPosition.Y);
  294. Assert.Equal (32, _textView.SelectionStartColumn);
  295. Assert.Equal (0, _textView.SelectionStartRow);
  296. Assert.Equal (7, _textView.SelectedLength);
  297. Assert.Equal ("fields.", _textView.SelectedText);
  298. break;
  299. case 1:
  300. Assert.Equal (20, _textView.CursorPosition.X);
  301. Assert.Equal (0, _textView.CursorPosition.Y);
  302. Assert.Equal (32, _textView.SelectionStartColumn);
  303. Assert.Equal (0, _textView.SelectionStartRow);
  304. Assert.Equal (12, _textView.SelectedLength);
  305. Assert.Equal ("text fields.", _textView.SelectedText);
  306. break;
  307. case 2:
  308. Assert.Equal (12, _textView.CursorPosition.X);
  309. Assert.Equal (0, _textView.CursorPosition.Y);
  310. Assert.Equal (32, _textView.SelectionStartColumn);
  311. Assert.Equal (0, _textView.SelectionStartRow);
  312. Assert.Equal (20, _textView.SelectedLength);
  313. Assert.Equal ("between text fields.", _textView.SelectedText);
  314. break;
  315. case 3:
  316. Assert.Equal (7, _textView.CursorPosition.X);
  317. Assert.Equal (0, _textView.CursorPosition.Y);
  318. Assert.Equal (32, _textView.SelectionStartColumn);
  319. Assert.Equal (0, _textView.SelectionStartRow);
  320. Assert.Equal (25, _textView.SelectedLength);
  321. Assert.Equal ("jump between text fields.", _textView.SelectedText);
  322. break;
  323. case 4:
  324. Assert.Equal (4, _textView.CursorPosition.X);
  325. Assert.Equal (0, _textView.CursorPosition.Y);
  326. Assert.Equal (32, _textView.SelectionStartColumn);
  327. Assert.Equal (0, _textView.SelectionStartRow);
  328. Assert.Equal (28, _textView.SelectedLength);
  329. Assert.Equal ("to jump between text fields.", _textView.SelectedText);
  330. break;
  331. case 5:
  332. Assert.Equal (0, _textView.CursorPosition.X);
  333. Assert.Equal (0, _textView.CursorPosition.Y);
  334. Assert.Equal (32, _textView.SelectionStartColumn);
  335. Assert.Equal (0, _textView.SelectionStartRow);
  336. Assert.Equal (32, _textView.SelectedLength);
  337. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  338. break;
  339. }
  340. iteration++;
  341. }
  342. }
  343. [Fact]
  344. public void WordForward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  345. {
  346. _textView.CursorPosition = new Point (10, 0);
  347. _textView.SelectionStartColumn = 10;
  348. _textView.SelectionStartRow = 0;
  349. var iteration = 0;
  350. while (_textView.CursorPosition.X < _textView.Text.Length) {
  351. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  352. switch (iteration) {
  353. case 0:
  354. Assert.Equal (12, _textView.CursorPosition.X);
  355. Assert.Equal (0, _textView.CursorPosition.Y);
  356. Assert.Equal (10, _textView.SelectionStartColumn);
  357. Assert.Equal (0, _textView.SelectionStartRow);
  358. Assert.Equal (2, _textView.SelectedLength);
  359. Assert.Equal ("p ", _textView.SelectedText);
  360. break;
  361. case 1:
  362. Assert.Equal (20, _textView.CursorPosition.X);
  363. Assert.Equal (0, _textView.CursorPosition.Y);
  364. Assert.Equal (10, _textView.SelectionStartColumn);
  365. Assert.Equal (0, _textView.SelectionStartRow);
  366. Assert.Equal (10, _textView.SelectedLength);
  367. Assert.Equal ("p between ", _textView.SelectedText);
  368. break;
  369. case 2:
  370. Assert.Equal (25, _textView.CursorPosition.X);
  371. Assert.Equal (0, _textView.CursorPosition.Y);
  372. Assert.Equal (10, _textView.SelectionStartColumn);
  373. Assert.Equal (0, _textView.SelectionStartRow);
  374. Assert.Equal (15, _textView.SelectedLength);
  375. Assert.Equal ("p between text ", _textView.SelectedText);
  376. break;
  377. case 3:
  378. Assert.Equal (32, _textView.CursorPosition.X);
  379. Assert.Equal (0, _textView.CursorPosition.Y);
  380. Assert.Equal (10, _textView.SelectionStartColumn);
  381. Assert.Equal (0, _textView.SelectionStartRow);
  382. Assert.Equal (22, _textView.SelectedLength);
  383. Assert.Equal ("p between text fields.", _textView.SelectedText);
  384. break;
  385. }
  386. iteration++;
  387. }
  388. }
  389. [Fact]
  390. public void WordBackward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  391. {
  392. _textView.CursorPosition = new Point (10, 0);
  393. _textView.SelectionStartColumn = 10;
  394. _textView.SelectionStartRow = 0;
  395. var iteration = 0;
  396. while (_textView.CursorPosition.X > 0) {
  397. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  398. switch (iteration) {
  399. case 0:
  400. Assert.Equal (7, _textView.CursorPosition.X);
  401. Assert.Equal (0, _textView.CursorPosition.Y);
  402. Assert.Equal (10, _textView.SelectionStartColumn);
  403. Assert.Equal (0, _textView.SelectionStartRow);
  404. Assert.Equal (3, _textView.SelectedLength);
  405. Assert.Equal ("jum", _textView.SelectedText);
  406. break;
  407. case 1:
  408. Assert.Equal (4, _textView.CursorPosition.X);
  409. Assert.Equal (0, _textView.CursorPosition.Y);
  410. Assert.Equal (10, _textView.SelectionStartColumn);
  411. Assert.Equal (0, _textView.SelectionStartRow);
  412. Assert.Equal (6, _textView.SelectedLength);
  413. Assert.Equal ("to jum", _textView.SelectedText);
  414. break;
  415. case 2:
  416. Assert.Equal (0, _textView.CursorPosition.X);
  417. Assert.Equal (0, _textView.CursorPosition.Y);
  418. Assert.Equal (10, _textView.SelectionStartColumn);
  419. Assert.Equal (0, _textView.SelectionStartRow);
  420. Assert.Equal (10, _textView.SelectedLength);
  421. Assert.Equal ("TAB to jum", _textView.SelectedText);
  422. break;
  423. }
  424. iteration++;
  425. }
  426. }
  427. [Fact]
  428. public void WordForward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  429. {
  430. // 1 2 3 4 5
  431. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  432. _textView.Text = "TAB t o jump b etween t ext f ields .";
  433. _textView.CursorPosition = new Point (0, 0);
  434. var iteration = 0;
  435. while (_textView.CursorPosition.X < _textView.Text.Length) {
  436. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()));
  437. switch (iteration) {
  438. case 0:
  439. Assert.Equal (6, _textView.CursorPosition.X);
  440. Assert.Equal (0, _textView.CursorPosition.Y);
  441. Assert.Equal (0, _textView.SelectionStartColumn);
  442. Assert.Equal (0, _textView.SelectionStartRow);
  443. Assert.Equal (0, _textView.SelectedLength);
  444. Assert.Equal ("", _textView.SelectedText);
  445. break;
  446. case 1:
  447. Assert.Equal (9, _textView.CursorPosition.X);
  448. Assert.Equal (0, _textView.CursorPosition.Y);
  449. Assert.Equal (0, _textView.SelectionStartColumn);
  450. Assert.Equal (0, _textView.SelectionStartRow);
  451. Assert.Equal (0, _textView.SelectedLength);
  452. Assert.Equal ("", _textView.SelectedText);
  453. break;
  454. case 2:
  455. Assert.Equal (12, _textView.CursorPosition.X);
  456. Assert.Equal (0, _textView.CursorPosition.Y);
  457. Assert.Equal (0, _textView.SelectionStartColumn);
  458. Assert.Equal (0, _textView.SelectionStartRow);
  459. Assert.Equal (0, _textView.SelectedLength);
  460. Assert.Equal ("", _textView.SelectedText);
  461. break;
  462. case 3:
  463. Assert.Equal (25, _textView.CursorPosition.X);
  464. Assert.Equal (0, _textView.CursorPosition.Y);
  465. Assert.Equal (0, _textView.SelectionStartColumn);
  466. Assert.Equal (0, _textView.SelectionStartRow);
  467. Assert.Equal (0, _textView.SelectedLength);
  468. Assert.Equal ("", _textView.SelectedText);
  469. break;
  470. case 4:
  471. Assert.Equal (28, _textView.CursorPosition.X);
  472. Assert.Equal (0, _textView.CursorPosition.Y);
  473. Assert.Equal (0, _textView.SelectionStartColumn);
  474. Assert.Equal (0, _textView.SelectionStartRow);
  475. Assert.Equal (0, _textView.SelectedLength);
  476. Assert.Equal ("", _textView.SelectedText);
  477. break;
  478. case 5:
  479. Assert.Equal (38, _textView.CursorPosition.X);
  480. Assert.Equal (0, _textView.CursorPosition.Y);
  481. Assert.Equal (0, _textView.SelectionStartColumn);
  482. Assert.Equal (0, _textView.SelectionStartRow);
  483. Assert.Equal (0, _textView.SelectedLength);
  484. Assert.Equal ("", _textView.SelectedText);
  485. break;
  486. case 6:
  487. Assert.Equal (40, _textView.CursorPosition.X);
  488. Assert.Equal (0, _textView.CursorPosition.Y);
  489. Assert.Equal (0, _textView.SelectionStartColumn);
  490. Assert.Equal (0, _textView.SelectionStartRow);
  491. Assert.Equal (0, _textView.SelectedLength);
  492. Assert.Equal ("", _textView.SelectedText);
  493. break;
  494. case 7:
  495. Assert.Equal (46, _textView.CursorPosition.X);
  496. Assert.Equal (0, _textView.CursorPosition.Y);
  497. Assert.Equal (0, _textView.SelectionStartColumn);
  498. Assert.Equal (0, _textView.SelectionStartRow);
  499. Assert.Equal (0, _textView.SelectedLength);
  500. Assert.Equal ("", _textView.SelectedText);
  501. break;
  502. case 8:
  503. Assert.Equal (48, _textView.CursorPosition.X);
  504. Assert.Equal (0, _textView.CursorPosition.Y);
  505. Assert.Equal (0, _textView.SelectionStartColumn);
  506. Assert.Equal (0, _textView.SelectionStartRow);
  507. Assert.Equal (0, _textView.SelectedLength);
  508. Assert.Equal ("", _textView.SelectedText);
  509. break;
  510. case 9:
  511. Assert.Equal (55, _textView.CursorPosition.X);
  512. Assert.Equal (0, _textView.CursorPosition.Y);
  513. Assert.Equal (0, _textView.SelectionStartColumn);
  514. Assert.Equal (0, _textView.SelectionStartRow);
  515. Assert.Equal (0, _textView.SelectedLength);
  516. Assert.Equal ("", _textView.SelectedText);
  517. break;
  518. }
  519. iteration++;
  520. }
  521. }
  522. [Fact]
  523. public void WordBackward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  524. {
  525. // 1 2 3 4 5
  526. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  527. _textView.Text = "TAB t o jump b etween t ext f ields .";
  528. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  529. var iteration = 0;
  530. while (_textView.CursorPosition.X > 0) {
  531. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()));
  532. switch (iteration) {
  533. case 0:
  534. Assert.Equal (54, _textView.CursorPosition.X);
  535. Assert.Equal (0, _textView.CursorPosition.Y);
  536. Assert.Equal (0, _textView.SelectionStartColumn);
  537. Assert.Equal (0, _textView.SelectionStartRow);
  538. Assert.Equal (0, _textView.SelectedLength);
  539. Assert.Equal ("", _textView.SelectedText);
  540. break;
  541. case 1:
  542. Assert.Equal (48, _textView.CursorPosition.X);
  543. Assert.Equal (0, _textView.CursorPosition.Y);
  544. Assert.Equal (0, _textView.SelectionStartColumn);
  545. Assert.Equal (0, _textView.SelectionStartRow);
  546. Assert.Equal (0, _textView.SelectedLength);
  547. Assert.Equal ("", _textView.SelectedText);
  548. break;
  549. case 2:
  550. Assert.Equal (46, _textView.CursorPosition.X);
  551. Assert.Equal (0, _textView.CursorPosition.Y);
  552. Assert.Equal (0, _textView.SelectionStartColumn);
  553. Assert.Equal (0, _textView.SelectionStartRow);
  554. Assert.Equal (0, _textView.SelectedLength);
  555. Assert.Equal ("", _textView.SelectedText);
  556. break;
  557. case 3:
  558. Assert.Equal (40, _textView.CursorPosition.X);
  559. Assert.Equal (0, _textView.CursorPosition.Y);
  560. Assert.Equal (0, _textView.SelectionStartColumn);
  561. Assert.Equal (0, _textView.SelectionStartRow);
  562. Assert.Equal (0, _textView.SelectedLength);
  563. Assert.Equal ("", _textView.SelectedText);
  564. break;
  565. case 4:
  566. Assert.Equal (38, _textView.CursorPosition.X);
  567. Assert.Equal (0, _textView.CursorPosition.Y);
  568. Assert.Equal (0, _textView.SelectionStartColumn);
  569. Assert.Equal (0, _textView.SelectionStartRow);
  570. Assert.Equal (0, _textView.SelectedLength);
  571. Assert.Equal ("", _textView.SelectedText);
  572. break;
  573. case 5:
  574. Assert.Equal (28, _textView.CursorPosition.X);
  575. Assert.Equal (0, _textView.CursorPosition.Y);
  576. Assert.Equal (0, _textView.SelectionStartColumn);
  577. Assert.Equal (0, _textView.SelectionStartRow);
  578. Assert.Equal (0, _textView.SelectedLength);
  579. Assert.Equal ("", _textView.SelectedText);
  580. break;
  581. case 6:
  582. Assert.Equal (25, _textView.CursorPosition.X);
  583. Assert.Equal (0, _textView.CursorPosition.Y);
  584. Assert.Equal (0, _textView.SelectionStartColumn);
  585. Assert.Equal (0, _textView.SelectionStartRow);
  586. Assert.Equal (0, _textView.SelectedLength);
  587. Assert.Equal ("", _textView.SelectedText);
  588. break;
  589. case 7:
  590. Assert.Equal (12, _textView.CursorPosition.X);
  591. Assert.Equal (0, _textView.CursorPosition.Y);
  592. Assert.Equal (0, _textView.SelectionStartColumn);
  593. Assert.Equal (0, _textView.SelectionStartRow);
  594. Assert.Equal (0, _textView.SelectedLength);
  595. Assert.Equal ("", _textView.SelectedText);
  596. break;
  597. case 8:
  598. Assert.Equal (9, _textView.CursorPosition.X);
  599. Assert.Equal (0, _textView.CursorPosition.Y);
  600. Assert.Equal (0, _textView.SelectionStartColumn);
  601. Assert.Equal (0, _textView.SelectionStartRow);
  602. Assert.Equal (0, _textView.SelectedLength);
  603. Assert.Equal ("", _textView.SelectedText);
  604. break;
  605. case 9:
  606. Assert.Equal (6, _textView.CursorPosition.X);
  607. Assert.Equal (0, _textView.CursorPosition.Y);
  608. Assert.Equal (0, _textView.SelectionStartColumn);
  609. Assert.Equal (0, _textView.SelectionStartRow);
  610. Assert.Equal (0, _textView.SelectedLength);
  611. Assert.Equal ("", _textView.SelectedText);
  612. break;
  613. case 10:
  614. Assert.Equal (0, _textView.CursorPosition.X);
  615. Assert.Equal (0, _textView.CursorPosition.Y);
  616. Assert.Equal (0, _textView.SelectionStartColumn);
  617. Assert.Equal (0, _textView.SelectionStartRow);
  618. Assert.Equal (0, _textView.SelectedLength);
  619. Assert.Equal ("", _textView.SelectedText);
  620. break;
  621. }
  622. iteration++;
  623. }
  624. }
  625. [Fact]
  626. public void WordBackward_Multiline_With_Selection ()
  627. {
  628. // 4 3 2 1
  629. // 87654321098765432109876 54321098765432109876543210-Length
  630. // 1 2 1 2
  631. // 01234567890123456789012 0123456789012345678901234
  632. _textView.Text = "This is the first line.\nThis is the second line.";
  633. _textView.MoveEnd ();
  634. _textView.SelectionStartColumn = _textView.CurrentColumn;
  635. _textView.SelectionStartRow = _textView.CurrentRow;
  636. var iteration = 0;
  637. bool iterationsFinished = false;
  638. while (!iterationsFinished) {
  639. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  640. switch (iteration) {
  641. case 0:
  642. Assert.Equal (19, _textView.CursorPosition.X);
  643. Assert.Equal (1, _textView.CursorPosition.Y);
  644. Assert.Equal (24, _textView.SelectionStartColumn);
  645. Assert.Equal (1, _textView.SelectionStartRow);
  646. Assert.Equal (5, _textView.SelectedLength);
  647. Assert.Equal ("line.", _textView.SelectedText);
  648. break;
  649. case 1:
  650. Assert.Equal (12, _textView.CursorPosition.X);
  651. Assert.Equal (1, _textView.CursorPosition.Y);
  652. Assert.Equal (24, _textView.SelectionStartColumn);
  653. Assert.Equal (1, _textView.SelectionStartRow);
  654. Assert.Equal (12, _textView.SelectedLength);
  655. Assert.Equal ("second line.", _textView.SelectedText);
  656. break;
  657. case 2:
  658. Assert.Equal (8, _textView.CursorPosition.X);
  659. Assert.Equal (1, _textView.CursorPosition.Y);
  660. Assert.Equal (24, _textView.SelectionStartColumn);
  661. Assert.Equal (1, _textView.SelectionStartRow);
  662. Assert.Equal (16, _textView.SelectedLength);
  663. Assert.Equal ("the second line.", _textView.SelectedText);
  664. break;
  665. case 3:
  666. Assert.Equal (5, _textView.CursorPosition.X);
  667. Assert.Equal (1, _textView.CursorPosition.Y);
  668. Assert.Equal (24, _textView.SelectionStartColumn);
  669. Assert.Equal (1, _textView.SelectionStartRow);
  670. Assert.Equal (19, _textView.SelectedLength);
  671. Assert.Equal ("is the second line.", _textView.SelectedText);
  672. break;
  673. case 4:
  674. Assert.Equal (0, _textView.CursorPosition.X);
  675. Assert.Equal (1, _textView.CursorPosition.Y);
  676. Assert.Equal (24, _textView.SelectionStartColumn);
  677. Assert.Equal (1, _textView.SelectionStartRow);
  678. Assert.Equal (24, _textView.SelectedLength);
  679. Assert.Equal ("This is the second line.", _textView.SelectedText);
  680. break;
  681. case 5:
  682. Assert.Equal (23, _textView.CursorPosition.X);
  683. Assert.Equal (0, _textView.CursorPosition.Y);
  684. Assert.Equal (24, _textView.SelectionStartColumn);
  685. Assert.Equal (1, _textView.SelectionStartRow);
  686. Assert.Equal (25, _textView.SelectedLength);
  687. Assert.Equal ("\nThis is the second line.", _textView.SelectedText);
  688. break;
  689. case 6:
  690. Assert.Equal (18, _textView.CursorPosition.X);
  691. Assert.Equal (0, _textView.CursorPosition.Y);
  692. Assert.Equal (24, _textView.SelectionStartColumn);
  693. Assert.Equal (1, _textView.SelectionStartRow);
  694. Assert.Equal (30, _textView.SelectedLength);
  695. Assert.Equal ("line.\nThis is the second line.", _textView.SelectedText);
  696. break;
  697. case 7:
  698. Assert.Equal (12, _textView.CursorPosition.X);
  699. Assert.Equal (0, _textView.CursorPosition.Y);
  700. Assert.Equal (24, _textView.SelectionStartColumn);
  701. Assert.Equal (1, _textView.SelectionStartRow);
  702. Assert.Equal (36, _textView.SelectedLength);
  703. Assert.Equal ("first line.\nThis is the second line.", _textView.SelectedText);
  704. break;
  705. case 8:
  706. Assert.Equal (8, _textView.CursorPosition.X);
  707. Assert.Equal (0, _textView.CursorPosition.Y);
  708. Assert.Equal (24, _textView.SelectionStartColumn);
  709. Assert.Equal (1, _textView.SelectionStartRow);
  710. Assert.Equal (40, _textView.SelectedLength);
  711. Assert.Equal ("the first line.\nThis is the second line.", _textView.SelectedText);
  712. break;
  713. case 9:
  714. Assert.Equal (5, _textView.CursorPosition.X);
  715. Assert.Equal (0, _textView.CursorPosition.Y);
  716. Assert.Equal (24, _textView.SelectionStartColumn);
  717. Assert.Equal (1, _textView.SelectionStartRow);
  718. Assert.Equal (43, _textView.SelectedLength);
  719. Assert.Equal ("is the first line.\nThis is the second line.", _textView.SelectedText);
  720. break;
  721. case 10:
  722. Assert.Equal (0, _textView.CursorPosition.X);
  723. Assert.Equal (0, _textView.CursorPosition.Y);
  724. Assert.Equal (24, _textView.SelectionStartColumn);
  725. Assert.Equal (1, _textView.SelectionStartRow);
  726. Assert.Equal (48, _textView.SelectedLength);
  727. Assert.Equal ("This is the first line.\nThis is the second line.", _textView.SelectedText);
  728. break;
  729. default:
  730. iterationsFinished = true;
  731. break;
  732. }
  733. iteration++;
  734. }
  735. }
  736. [Fact]
  737. public void WordForward_Multiline_With_Selection ()
  738. {
  739. // 1 2 3 4
  740. // 01234567890123456789012 34567890123456789012345678-Length
  741. // 1 2 1 2
  742. // 01234567890123456789012 0123456789012345678901234
  743. _textView.Text = "This is the first line.\nThis is the second line.";
  744. _textView.SelectionStartColumn = _textView.CurrentColumn;
  745. _textView.SelectionStartRow = _textView.CurrentRow;
  746. var iteration = 0;
  747. bool iterationsFinished = false;
  748. while (!iterationsFinished) {
  749. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  750. switch (iteration) {
  751. case 0:
  752. Assert.Equal (5, _textView.CursorPosition.X);
  753. Assert.Equal (0, _textView.CursorPosition.Y);
  754. Assert.Equal (0, _textView.SelectionStartColumn);
  755. Assert.Equal (0, _textView.SelectionStartRow);
  756. Assert.Equal (5, _textView.SelectedLength);
  757. Assert.Equal ("This ", _textView.SelectedText);
  758. break;
  759. case 1:
  760. Assert.Equal (8, _textView.CursorPosition.X);
  761. Assert.Equal (0, _textView.CursorPosition.Y);
  762. Assert.Equal (0, _textView.SelectionStartColumn);
  763. Assert.Equal (0, _textView.SelectionStartRow);
  764. Assert.Equal (8, _textView.SelectedLength);
  765. Assert.Equal ("This is ", _textView.SelectedText);
  766. break;
  767. case 2:
  768. Assert.Equal (12, _textView.CursorPosition.X);
  769. Assert.Equal (0, _textView.CursorPosition.Y);
  770. Assert.Equal (0, _textView.SelectionStartColumn);
  771. Assert.Equal (0, _textView.SelectionStartRow);
  772. Assert.Equal (12, _textView.SelectedLength);
  773. Assert.Equal ("This is the ", _textView.SelectedText);
  774. break;
  775. case 3:
  776. Assert.Equal (18, _textView.CursorPosition.X);
  777. Assert.Equal (0, _textView.CursorPosition.Y);
  778. Assert.Equal (0, _textView.SelectionStartColumn);
  779. Assert.Equal (0, _textView.SelectionStartRow);
  780. Assert.Equal (18, _textView.SelectedLength);
  781. Assert.Equal ("This is the first ", _textView.SelectedText);
  782. break;
  783. case 4:
  784. Assert.Equal (23, _textView.CursorPosition.X);
  785. Assert.Equal (0, _textView.CursorPosition.Y);
  786. Assert.Equal (0, _textView.SelectionStartColumn);
  787. Assert.Equal (0, _textView.SelectionStartRow);
  788. Assert.Equal (23, _textView.SelectedLength);
  789. Assert.Equal ("This is the first line.", _textView.SelectedText);
  790. break;
  791. case 5:
  792. Assert.Equal (0, _textView.CursorPosition.X);
  793. Assert.Equal (1, _textView.CursorPosition.Y);
  794. Assert.Equal (0, _textView.SelectionStartColumn);
  795. Assert.Equal (0, _textView.SelectionStartRow);
  796. Assert.Equal (24, _textView.SelectedLength);
  797. Assert.Equal ("This is the first line.\n", _textView.SelectedText);
  798. break;
  799. case 6:
  800. Assert.Equal (5, _textView.CursorPosition.X);
  801. Assert.Equal (1, _textView.CursorPosition.Y);
  802. Assert.Equal (0, _textView.SelectionStartColumn);
  803. Assert.Equal (0, _textView.SelectionStartRow);
  804. Assert.Equal (29, _textView.SelectedLength);
  805. Assert.Equal ("This is the first line.\nThis ", _textView.SelectedText);
  806. break;
  807. case 7:
  808. Assert.Equal (8, _textView.CursorPosition.X);
  809. Assert.Equal (1, _textView.CursorPosition.Y);
  810. Assert.Equal (0, _textView.SelectionStartColumn);
  811. Assert.Equal (0, _textView.SelectionStartRow);
  812. Assert.Equal (32, _textView.SelectedLength);
  813. Assert.Equal ("This is the first line.\nThis is ", _textView.SelectedText);
  814. break;
  815. case 8:
  816. Assert.Equal (12, _textView.CursorPosition.X);
  817. Assert.Equal (1, _textView.CursorPosition.Y);
  818. Assert.Equal (0, _textView.SelectionStartColumn);
  819. Assert.Equal (0, _textView.SelectionStartRow);
  820. Assert.Equal (36, _textView.SelectedLength);
  821. Assert.Equal ("This is the first line.\nThis is the ", _textView.SelectedText);
  822. break;
  823. case 9:
  824. Assert.Equal (19, _textView.CursorPosition.X);
  825. Assert.Equal (1, _textView.CursorPosition.Y);
  826. Assert.Equal (0, _textView.SelectionStartColumn);
  827. Assert.Equal (0, _textView.SelectionStartRow);
  828. Assert.Equal (43, _textView.SelectedLength);
  829. Assert.Equal ("This is the first line.\nThis is the second ", _textView.SelectedText);
  830. break;
  831. case 10:
  832. Assert.Equal (24, _textView.CursorPosition.X);
  833. Assert.Equal (1, _textView.CursorPosition.Y);
  834. Assert.Equal (0, _textView.SelectionStartColumn);
  835. Assert.Equal (0, _textView.SelectionStartRow);
  836. Assert.Equal (48, _textView.SelectedLength);
  837. Assert.Equal ("This is the first line.\nThis is the second line.", _textView.SelectedText);
  838. break;
  839. default:
  840. iterationsFinished = true;
  841. break;
  842. }
  843. iteration++;
  844. }
  845. }
  846. [Fact]
  847. public void Kill_To_End_Delete_Forwards_And_Copy_To_The_Clipboard ()
  848. {
  849. _textView.Text = "This is the first line.\nThis is the second line.";
  850. var iteration = 0;
  851. bool iterationsFinished = false;
  852. while (!iterationsFinished) {
  853. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  854. switch (iteration) {
  855. case 0:
  856. Assert.Equal (0, _textView.CursorPosition.X);
  857. Assert.Equal (0, _textView.CursorPosition.Y);
  858. Assert.Equal ($"{System.Environment.NewLine}This is the second line.", _textView.Text);
  859. break;
  860. case 1:
  861. Assert.Equal (0, _textView.CursorPosition.X);
  862. Assert.Equal (0, _textView.CursorPosition.Y);
  863. Assert.Equal ("This is the second line.", _textView.Text);
  864. break;
  865. case 2:
  866. Assert.Equal (0, _textView.CursorPosition.X);
  867. Assert.Equal (0, _textView.CursorPosition.Y);
  868. Assert.Equal ("", _textView.Text);
  869. _textView.Paste ();
  870. Assert.Equal ("This is the second line.", _textView.Text);
  871. break;
  872. default:
  873. iterationsFinished = true;
  874. break;
  875. }
  876. iteration++;
  877. }
  878. }
  879. [Fact]
  880. public void Kill_To_Start_Delete_Backwards_And_Copy_To_The_Clipboard ()
  881. {
  882. _textView.Text = "This is the first line.\nThis is the second line.";
  883. _textView.MoveEnd ();
  884. var iteration = 0;
  885. bool iterationsFinished = false;
  886. while (!iterationsFinished) {
  887. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  888. switch (iteration) {
  889. case 0:
  890. Assert.Equal (0, _textView.CursorPosition.X);
  891. Assert.Equal (1, _textView.CursorPosition.Y);
  892. Assert.Equal ($"This is the first line.{System.Environment.NewLine}", _textView.Text);
  893. break;
  894. case 1:
  895. Assert.Equal (23, _textView.CursorPosition.X);
  896. Assert.Equal (0, _textView.CursorPosition.Y);
  897. Assert.Equal ("This is the first line.", _textView.Text);
  898. break;
  899. case 2:
  900. Assert.Equal (0, _textView.CursorPosition.X);
  901. Assert.Equal (0, _textView.CursorPosition.Y);
  902. Assert.Equal ("", _textView.Text);
  903. _textView.Paste ();
  904. Assert.Equal ("This is the first line.", _textView.Text);
  905. break;
  906. default:
  907. iterationsFinished = true;
  908. break;
  909. }
  910. iteration++;
  911. }
  912. }
  913. [Fact]
  914. public void Kill_Delete_WordForward ()
  915. {
  916. _textView.Text = "This is the first line.";
  917. var iteration = 0;
  918. bool iterationsFinished = false;
  919. while (!iterationsFinished) {
  920. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()));
  921. switch (iteration) {
  922. case 0:
  923. Assert.Equal (0, _textView.CursorPosition.X);
  924. Assert.Equal (0, _textView.CursorPosition.Y);
  925. Assert.Equal ("is the first line.", _textView.Text);
  926. break;
  927. case 1:
  928. Assert.Equal (0, _textView.CursorPosition.X);
  929. Assert.Equal (0, _textView.CursorPosition.Y);
  930. Assert.Equal ("the first line.", _textView.Text);
  931. break;
  932. case 2:
  933. Assert.Equal (0, _textView.CursorPosition.X);
  934. Assert.Equal (0, _textView.CursorPosition.Y);
  935. Assert.Equal ("first line.", _textView.Text);
  936. break;
  937. case 3:
  938. Assert.Equal (0, _textView.CursorPosition.X);
  939. Assert.Equal (0, _textView.CursorPosition.Y);
  940. Assert.Equal ("line.", _textView.Text);
  941. break;
  942. case 4:
  943. Assert.Equal (0, _textView.CursorPosition.X);
  944. Assert.Equal (0, _textView.CursorPosition.Y);
  945. Assert.Equal ("", _textView.Text);
  946. break;
  947. default:
  948. iterationsFinished = true;
  949. break;
  950. }
  951. iteration++;
  952. }
  953. }
  954. [Fact]
  955. public void Kill_Delete_WordBackward ()
  956. {
  957. _textView.Text = "This is the first line.";
  958. _textView.MoveEnd ();
  959. var iteration = 0;
  960. bool iterationsFinished = false;
  961. while (!iterationsFinished) {
  962. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()));
  963. switch (iteration) {
  964. case 0:
  965. Assert.Equal (18, _textView.CursorPosition.X);
  966. Assert.Equal (0, _textView.CursorPosition.Y);
  967. Assert.Equal ("This is the first ", _textView.Text);
  968. break;
  969. case 1:
  970. Assert.Equal (12, _textView.CursorPosition.X);
  971. Assert.Equal (0, _textView.CursorPosition.Y);
  972. Assert.Equal ("This is the ", _textView.Text);
  973. break;
  974. case 2:
  975. Assert.Equal (8, _textView.CursorPosition.X);
  976. Assert.Equal (0, _textView.CursorPosition.Y);
  977. Assert.Equal ("This is ", _textView.Text);
  978. break;
  979. case 3:
  980. Assert.Equal (5, _textView.CursorPosition.X);
  981. Assert.Equal (0, _textView.CursorPosition.Y);
  982. Assert.Equal ("This ", _textView.Text);
  983. break;
  984. case 4:
  985. Assert.Equal (0, _textView.CursorPosition.X);
  986. Assert.Equal (0, _textView.CursorPosition.Y);
  987. Assert.Equal ("", _textView.Text);
  988. break;
  989. default:
  990. iterationsFinished = true;
  991. break;
  992. }
  993. iteration++;
  994. }
  995. }
  996. [Fact]
  997. public void Kill_Delete_WordForward_Multiline ()
  998. {
  999. _textView.Text = "This is the first line.\nThis is the second line.";
  1000. _textView.Width = 4;
  1001. var iteration = 0;
  1002. bool iterationsFinished = false;
  1003. while (!iterationsFinished) {
  1004. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()));
  1005. switch (iteration) {
  1006. case 0:
  1007. Assert.Equal (0, _textView.CursorPosition.X);
  1008. Assert.Equal (0, _textView.CursorPosition.Y);
  1009. Assert.Equal ("is the first line." + Environment.NewLine
  1010. + "This is the second line.", _textView.Text);
  1011. break;
  1012. case 1:
  1013. Assert.Equal (0, _textView.CursorPosition.X);
  1014. Assert.Equal (0, _textView.CursorPosition.Y);
  1015. Assert.Equal ("the first line." + Environment.NewLine
  1016. + "This is the second line.", _textView.Text);
  1017. break;
  1018. case 2:
  1019. Assert.Equal (0, _textView.CursorPosition.X);
  1020. Assert.Equal (0, _textView.CursorPosition.Y);
  1021. Assert.Equal ("first line." + Environment.NewLine
  1022. + "This is the second line.", _textView.Text);
  1023. break;
  1024. case 3:
  1025. Assert.Equal (0, _textView.CursorPosition.X);
  1026. Assert.Equal (0, _textView.CursorPosition.Y);
  1027. Assert.Equal ("line." + Environment.NewLine
  1028. + "This is the second line.", _textView.Text);
  1029. break;
  1030. case 4:
  1031. Assert.Equal (0, _textView.CursorPosition.X);
  1032. Assert.Equal (0, _textView.CursorPosition.Y);
  1033. Assert.Equal ("" + Environment.NewLine
  1034. + "This is the second line.", _textView.Text);
  1035. break;
  1036. case 5:
  1037. Assert.Equal (0, _textView.CursorPosition.X);
  1038. Assert.Equal (0, _textView.CursorPosition.Y);
  1039. Assert.Equal ("This is the second line.", _textView.Text);
  1040. break;
  1041. case 6:
  1042. Assert.Equal (0, _textView.CursorPosition.X);
  1043. Assert.Equal (0, _textView.CursorPosition.Y);
  1044. Assert.Equal ("is the second line.", _textView.Text);
  1045. break;
  1046. case 7:
  1047. Assert.Equal (0, _textView.CursorPosition.X);
  1048. Assert.Equal (0, _textView.CursorPosition.Y);
  1049. Assert.Equal ("the second line.", _textView.Text);
  1050. break;
  1051. case 8:
  1052. Assert.Equal (0, _textView.CursorPosition.X);
  1053. Assert.Equal (0, _textView.CursorPosition.Y);
  1054. Assert.Equal ("second line.", _textView.Text);
  1055. break;
  1056. case 9:
  1057. Assert.Equal (0, _textView.CursorPosition.X);
  1058. Assert.Equal (0, _textView.CursorPosition.Y);
  1059. Assert.Equal ("line.", _textView.Text);
  1060. break;
  1061. case 10:
  1062. Assert.Equal (0, _textView.CursorPosition.X);
  1063. Assert.Equal (0, _textView.CursorPosition.Y);
  1064. Assert.Equal ("", _textView.Text);
  1065. break;
  1066. default:
  1067. iterationsFinished = true;
  1068. break;
  1069. }
  1070. iteration++;
  1071. }
  1072. }
  1073. [Fact]
  1074. public void Kill_Delete_WordBackward_Multiline ()
  1075. {
  1076. _textView.Text = "This is the first line.\nThis is the second line.";
  1077. _textView.Width = 4;
  1078. _textView.MoveEnd ();
  1079. var iteration = 0;
  1080. bool iterationsFinished = false;
  1081. while (!iterationsFinished) {
  1082. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()));
  1083. switch (iteration) {
  1084. case 0:
  1085. Assert.Equal (19, _textView.CursorPosition.X);
  1086. Assert.Equal (1, _textView.CursorPosition.Y);
  1087. Assert.Equal ("This is the first line." + Environment.NewLine
  1088. + "This is the second ", _textView.Text);
  1089. break;
  1090. case 1:
  1091. Assert.Equal (12, _textView.CursorPosition.X);
  1092. Assert.Equal (1, _textView.CursorPosition.Y);
  1093. Assert.Equal ("This is the first line." + Environment.NewLine
  1094. + "This is the ", _textView.Text);
  1095. break;
  1096. case 2:
  1097. Assert.Equal (8, _textView.CursorPosition.X);
  1098. Assert.Equal (1, _textView.CursorPosition.Y);
  1099. Assert.Equal ("This is the first line." + Environment.NewLine
  1100. + "This is ", _textView.Text);
  1101. break;
  1102. case 3:
  1103. Assert.Equal (5, _textView.CursorPosition.X);
  1104. Assert.Equal (1, _textView.CursorPosition.Y);
  1105. Assert.Equal ("This is the first line." + Environment.NewLine
  1106. + "This ", _textView.Text);
  1107. break;
  1108. case 4:
  1109. Assert.Equal (0, _textView.CursorPosition.X);
  1110. Assert.Equal (1, _textView.CursorPosition.Y);
  1111. Assert.Equal ("This is the first line." + Environment.NewLine, _textView.Text);
  1112. break;
  1113. case 5:
  1114. Assert.Equal (23, _textView.CursorPosition.X);
  1115. Assert.Equal (0, _textView.CursorPosition.Y);
  1116. Assert.Equal ("This is the first line.", _textView.Text);
  1117. break;
  1118. case 6:
  1119. Assert.Equal (18, _textView.CursorPosition.X);
  1120. Assert.Equal (0, _textView.CursorPosition.Y);
  1121. Assert.Equal ("This is the first ", _textView.Text);
  1122. break;
  1123. case 7:
  1124. Assert.Equal (12, _textView.CursorPosition.X);
  1125. Assert.Equal (0, _textView.CursorPosition.Y);
  1126. Assert.Equal ("This is the ", _textView.Text);
  1127. break;
  1128. case 8:
  1129. Assert.Equal (8, _textView.CursorPosition.X);
  1130. Assert.Equal (0, _textView.CursorPosition.Y);
  1131. Assert.Equal ("This is ", _textView.Text);
  1132. break;
  1133. case 9:
  1134. Assert.Equal (5, _textView.CursorPosition.X);
  1135. Assert.Equal (0, _textView.CursorPosition.Y);
  1136. Assert.Equal ("This ", _textView.Text);
  1137. break;
  1138. case 10:
  1139. Assert.Equal (0, _textView.CursorPosition.X);
  1140. Assert.Equal (0, _textView.CursorPosition.Y);
  1141. Assert.Equal ("", _textView.Text);
  1142. break;
  1143. default:
  1144. iterationsFinished = true;
  1145. break;
  1146. }
  1147. iteration++;
  1148. }
  1149. }
  1150. [Fact]
  1151. public void Copy_Or_Cut_Null_If_No_Selection ()
  1152. {
  1153. _textView.SelectionStartColumn = 0;
  1154. _textView.SelectionStartRow = 0;
  1155. _textView.Copy ();
  1156. Assert.Equal ("", _textView.SelectedText);
  1157. _textView.Cut ();
  1158. Assert.Equal ("", _textView.SelectedText);
  1159. }
  1160. [Fact]
  1161. public void Copy_Or_Cut_Not_Null_If_Has_Selection ()
  1162. {
  1163. _textView.SelectionStartColumn = 20;
  1164. _textView.SelectionStartRow = 0;
  1165. _textView.CursorPosition = new Point (24, 0);
  1166. _textView.Copy ();
  1167. Assert.Equal ("text", _textView.SelectedText);
  1168. _textView.Cut ();
  1169. Assert.Equal ("", _textView.SelectedText);
  1170. }
  1171. [Fact]
  1172. public void Copy_Or_Cut_And_Paste_With_Selection ()
  1173. {
  1174. _textView.SelectionStartColumn = 20;
  1175. _textView.SelectionStartRow = 0;
  1176. _textView.CursorPosition = new Point (24, 0);
  1177. _textView.Copy ();
  1178. Assert.Equal ("text", _textView.SelectedText);
  1179. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1180. _textView.Paste ();
  1181. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1182. _textView.SelectionStartColumn = 20;
  1183. _textView.SelectionStartRow = 0;
  1184. _textView.Cut ();
  1185. _textView.Paste ();
  1186. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1187. }
  1188. [Fact]
  1189. public void Copy_Or_Cut_And_Paste_With_No_Selection ()
  1190. {
  1191. _textView.SelectionStartColumn = 20;
  1192. _textView.SelectionStartRow = 0;
  1193. _textView.CursorPosition = new Point (24, 0);
  1194. _textView.Copy ();
  1195. Assert.Equal ("text", _textView.SelectedText);
  1196. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1197. _textView.SelectionStartColumn = 0;
  1198. _textView.SelectionStartRow = 0;
  1199. Assert.True (_textView.Selecting);
  1200. _textView.Selecting = false;
  1201. _textView.Paste ();
  1202. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1203. _textView.SelectionStartColumn = 24;
  1204. _textView.SelectionStartRow = 0;
  1205. _textView.Cut ();
  1206. Assert.Equal ("", _textView.SelectedText);
  1207. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1208. _textView.SelectionStartColumn = 0;
  1209. _textView.SelectionStartRow = 0;
  1210. Assert.True (_textView.Selecting);
  1211. _textView.Selecting = false;
  1212. _textView.Paste ();
  1213. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1214. }
  1215. [Fact]
  1216. public void Cut_Not_Allowed_If_ReadOnly_Is_True ()
  1217. {
  1218. _textView.ReadOnly = true;
  1219. _textView.SelectionStartColumn = 20;
  1220. _textView.SelectionStartRow = 0;
  1221. _textView.CursorPosition = new Point (24, 0);
  1222. _textView.Copy ();
  1223. Assert.Equal ("text", _textView.SelectedText);
  1224. _textView.Cut (); // Selecting is set to false after Cut.
  1225. Assert.Equal ("", _textView.SelectedText);
  1226. _textView.ReadOnly = false;
  1227. Assert.False (_textView.Selecting);
  1228. _textView.Selecting = true; // Needed to set Selecting to true.
  1229. _textView.Copy ();
  1230. Assert.Equal ("text", _textView.SelectedText);
  1231. _textView.Cut ();
  1232. Assert.Equal ("", _textView.SelectedText);
  1233. }
  1234. [Fact]
  1235. public void Paste_Always_Clear_The_SelectedText ()
  1236. {
  1237. _textView.SelectionStartColumn = 20;
  1238. _textView.SelectionStartRow = 0;
  1239. _textView.CursorPosition = new Point (24, 0);
  1240. _textView.Copy ();
  1241. Assert.Equal ("text", _textView.SelectedText);
  1242. _textView.Paste ();
  1243. Assert.Equal ("", _textView.SelectedText);
  1244. }
  1245. [Fact]
  1246. public void TextChanged_Event ()
  1247. {
  1248. _textView.TextChanged += () => {
  1249. if (_textView.Text == "changing") {
  1250. Assert.Equal ("changing", _textView.Text);
  1251. _textView.Text = "changed";
  1252. }
  1253. };
  1254. _textView.Text = "changing";
  1255. Assert.Equal ("changed", _textView.Text);
  1256. }
  1257. [Fact]
  1258. public void Used_Is_True_By_Default ()
  1259. {
  1260. _textView.CursorPosition = new Point (10, 0);
  1261. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1262. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1263. Assert.Equal ("TAB to jumup between text fields.", _textView.Text);
  1264. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1265. Assert.Equal ("TAB to jumusp between text fields.", _textView.Text);
  1266. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1267. Assert.Equal ("TAB to jumusep between text fields.", _textView.Text);
  1268. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1269. Assert.Equal ("TAB to jumusedp between text fields.", _textView.Text);
  1270. }
  1271. [Fact]
  1272. public void Used_Is_False ()
  1273. {
  1274. _textView.Used = false;
  1275. _textView.CursorPosition = new Point (10, 0);
  1276. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1277. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1278. Assert.Equal ("TAB to jumu between text fields.", _textView.Text);
  1279. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1280. Assert.Equal ("TAB to jumusbetween text fields.", _textView.Text);
  1281. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1282. Assert.Equal ("TAB to jumuseetween text fields.", _textView.Text);
  1283. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1284. Assert.Equal ("TAB to jumusedtween text fields.", _textView.Text);
  1285. }
  1286. [Fact]
  1287. public void Copy_Without_Selection ()
  1288. {
  1289. _textView.Text = "This is the first line.\nThis is the second line.\n";
  1290. _textView.CursorPosition = new Point (0, _textView.Lines - 1);
  1291. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()));
  1292. _textView.Paste ();
  1293. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1294. _textView.CursorPosition = new Point (3, 1);
  1295. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()));
  1296. _textView.Paste ();
  1297. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1298. Assert.Equal (new Point (3, 2), _textView.CursorPosition);
  1299. _textView.Paste ();
  1300. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1301. Assert.Equal (new Point (3, 3), _textView.CursorPosition);
  1302. }
  1303. }
  1304. }