TextViewTests.cs 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755
  1. using System;
  2. using System.Linq;
  3. using System.Reflection;
  4. using Xunit;
  5. namespace Terminal.Gui.Views {
  6. public class TextViewTests {
  7. private static TextView _textView;
  8. // This class enables test functions annoated with the [InitShutdown] attribute
  9. // to have a function called before the test function is called and after.
  10. //
  11. // This is necessary because a) Application is a singleton and Init/Shutdown must be called
  12. // as a pair, and b) all unit test functions should be atomic.
  13. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
  14. public class InitShutdown : Xunit.Sdk.BeforeAfterTestAttribute {
  15. public override void Before (MethodInfo methodUnderTest)
  16. {
  17. if (_textView != null) {
  18. throw new InvalidOperationException ("After did not run.");
  19. }
  20. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  21. // 1 2 3
  22. // 01234567890123456789012345678901=32 (Length)
  23. var txt = "TAB to jump between text fields.";
  24. var buff = new byte [txt.Length];
  25. for (int i = 0; i < txt.Length; i++) {
  26. buff [i] = (byte)txt [i];
  27. }
  28. var ms = new System.IO.MemoryStream (buff).ToArray ();
  29. _textView = new TextView () { Width = 30, Height = 10 };
  30. _textView.Text = ms;
  31. }
  32. public override void After (MethodInfo methodUnderTest)
  33. {
  34. _textView = null;
  35. Application.Shutdown ();
  36. }
  37. }
  38. [Fact][InitShutdown]
  39. public void Changing_Selection_Or_CursorPosition_Update_SelectedLength_And_SelectedText ()
  40. {
  41. _textView.SelectionStartColumn = 2;
  42. _textView.SelectionStartRow = 0;
  43. Assert.Equal (0, _textView.CursorPosition.X);
  44. Assert.Equal (0, _textView.CursorPosition.Y);
  45. Assert.Equal (2, _textView.SelectedLength);
  46. Assert.Equal ("TA", _textView.SelectedText);
  47. _textView.CursorPosition = new Point (20, 0);
  48. Assert.Equal (2, _textView.SelectionStartColumn);
  49. Assert.Equal (0, _textView.SelectionStartRow);
  50. Assert.Equal (18, _textView.SelectedLength);
  51. Assert.Equal ("B to jump between ", _textView.SelectedText);
  52. }
  53. [Fact][InitShutdown]
  54. public void Selection_With_Value_Less_Than_Zero_Changes_To_Zero ()
  55. {
  56. _textView.SelectionStartColumn = -2;
  57. _textView.SelectionStartRow = -2;
  58. Assert.Equal (0, _textView.SelectionStartColumn);
  59. Assert.Equal (0, _textView.SelectionStartRow);
  60. Assert.Equal (0, _textView.SelectedLength);
  61. Assert.Equal ("", _textView.SelectedText);
  62. }
  63. [Fact][InitShutdown]
  64. public void Selection_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  65. {
  66. _textView.CursorPosition = new Point (2, 0);
  67. _textView.SelectionStartColumn = 33;
  68. _textView.SelectionStartRow = 1;
  69. Assert.Equal (32, _textView.SelectionStartColumn);
  70. Assert.Equal (0, _textView.SelectionStartRow);
  71. Assert.Equal (30, _textView.SelectedLength);
  72. Assert.Equal ("B to jump between text fields.", _textView.SelectedText);
  73. }
  74. [Fact][InitShutdown]
  75. public void Selection_With_Empty_Text ()
  76. {
  77. _textView = new TextView ();
  78. _textView.CursorPosition = new Point (2, 0);
  79. _textView.SelectionStartColumn = 33;
  80. _textView.SelectionStartRow = 1;
  81. Assert.Equal (0, _textView.SelectionStartColumn);
  82. Assert.Equal (0, _textView.SelectionStartRow);
  83. Assert.Equal (0, _textView.SelectedLength);
  84. Assert.Equal ("", _textView.SelectedText);
  85. }
  86. [Fact][InitShutdown]
  87. public void Selection_And_CursorPosition_With_Value_Greater_Than_Text_Length_Changes_Both_To_Text_Length ()
  88. {
  89. _textView.CursorPosition = new Point (33, 2);
  90. _textView.SelectionStartColumn = 33;
  91. _textView.SelectionStartRow = 33;
  92. Assert.Equal (32, _textView.CursorPosition.X);
  93. Assert.Equal (0, _textView.CursorPosition.Y);
  94. Assert.Equal (32, _textView.SelectionStartColumn);
  95. Assert.Equal (0, _textView.SelectionStartRow);
  96. Assert.Equal (0, _textView.SelectedLength);
  97. Assert.Equal ("", _textView.SelectedText);
  98. }
  99. [Fact][InitShutdown]
  100. public void CursorPosition_With_Value_Less_Than_Zero_Changes_To_Zero ()
  101. {
  102. _textView.CursorPosition = new Point (-1, -1);
  103. Assert.Equal (0, _textView.CursorPosition.X);
  104. Assert.Equal (0, _textView.CursorPosition.Y);
  105. Assert.Equal (0, _textView.SelectedLength);
  106. Assert.Equal ("", _textView.SelectedText);
  107. }
  108. [Fact][InitShutdown]
  109. public void CursorPosition_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  110. {
  111. _textView.CursorPosition = new Point (33, 1);
  112. Assert.Equal (32, _textView.CursorPosition.X);
  113. Assert.Equal (0, _textView.CursorPosition.Y);
  114. Assert.Equal (0, _textView.SelectedLength);
  115. Assert.Equal ("", _textView.SelectedText);
  116. }
  117. [Fact][InitShutdown]
  118. public void WordForward_With_No_Selection ()
  119. {
  120. _textView.CursorPosition = new Point (0, 0);
  121. var iteration = 0;
  122. while (_textView.CursorPosition.X < _textView.Text.Length) {
  123. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()));
  124. switch (iteration) {
  125. case 0:
  126. Assert.Equal (4, _textView.CursorPosition.X);
  127. Assert.Equal (0, _textView.CursorPosition.Y);
  128. Assert.Equal (0, _textView.SelectionStartColumn);
  129. Assert.Equal (0, _textView.SelectionStartRow);
  130. Assert.Equal (0, _textView.SelectedLength);
  131. Assert.Equal ("", _textView.SelectedText);
  132. break;
  133. case 1:
  134. Assert.Equal (7, _textView.CursorPosition.X);
  135. Assert.Equal (0, _textView.CursorPosition.Y);
  136. Assert.Equal (0, _textView.SelectionStartColumn);
  137. Assert.Equal (0, _textView.SelectionStartRow);
  138. Assert.Equal (0, _textView.SelectedLength);
  139. Assert.Equal ("", _textView.SelectedText);
  140. break;
  141. case 2:
  142. Assert.Equal (12, _textView.CursorPosition.X);
  143. Assert.Equal (0, _textView.CursorPosition.Y);
  144. Assert.Equal (0, _textView.SelectionStartColumn);
  145. Assert.Equal (0, _textView.SelectionStartRow);
  146. Assert.Equal (0, _textView.SelectedLength);
  147. Assert.Equal ("", _textView.SelectedText);
  148. break;
  149. case 3:
  150. Assert.Equal (20, _textView.CursorPosition.X);
  151. Assert.Equal (0, _textView.CursorPosition.Y);
  152. Assert.Equal (0, _textView.SelectionStartColumn);
  153. Assert.Equal (0, _textView.SelectionStartRow);
  154. Assert.Equal (0, _textView.SelectedLength);
  155. Assert.Equal ("", _textView.SelectedText);
  156. break;
  157. case 4:
  158. Assert.Equal (25, _textView.CursorPosition.X);
  159. Assert.Equal (0, _textView.CursorPosition.Y);
  160. Assert.Equal (0, _textView.SelectionStartColumn);
  161. Assert.Equal (0, _textView.SelectionStartRow);
  162. Assert.Equal (0, _textView.SelectedLength);
  163. Assert.Equal ("", _textView.SelectedText);
  164. break;
  165. case 5:
  166. Assert.Equal (32, _textView.CursorPosition.X);
  167. Assert.Equal (0, _textView.CursorPosition.Y);
  168. Assert.Equal (0, _textView.SelectionStartColumn);
  169. Assert.Equal (0, _textView.SelectionStartRow);
  170. Assert.Equal (0, _textView.SelectedLength);
  171. Assert.Equal ("", _textView.SelectedText);
  172. break;
  173. }
  174. iteration++;
  175. }
  176. }
  177. [Fact][InitShutdown]
  178. public void WordBackward_With_No_Selection ()
  179. {
  180. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  181. var iteration = 0;
  182. while (_textView.CursorPosition.X > 0) {
  183. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()));
  184. switch (iteration) {
  185. case 0:
  186. Assert.Equal (25, _textView.CursorPosition.X);
  187. Assert.Equal (0, _textView.CursorPosition.Y);
  188. Assert.Equal (0, _textView.SelectionStartColumn);
  189. Assert.Equal (0, _textView.SelectionStartRow);
  190. Assert.Equal (0, _textView.SelectedLength);
  191. Assert.Equal ("", _textView.SelectedText);
  192. break;
  193. case 1:
  194. Assert.Equal (20, _textView.CursorPosition.X);
  195. Assert.Equal (0, _textView.CursorPosition.Y);
  196. Assert.Equal (0, _textView.SelectionStartColumn);
  197. Assert.Equal (0, _textView.SelectionStartRow);
  198. Assert.Equal (0, _textView.SelectedLength);
  199. Assert.Equal ("", _textView.SelectedText);
  200. break;
  201. case 2:
  202. Assert.Equal (12, _textView.CursorPosition.X);
  203. Assert.Equal (0, _textView.CursorPosition.Y);
  204. Assert.Equal (0, _textView.SelectionStartColumn);
  205. Assert.Equal (0, _textView.SelectionStartRow);
  206. Assert.Equal (0, _textView.SelectedLength);
  207. Assert.Equal ("", _textView.SelectedText);
  208. break;
  209. case 3:
  210. Assert.Equal (7, _textView.CursorPosition.X);
  211. Assert.Equal (0, _textView.CursorPosition.Y);
  212. Assert.Equal (0, _textView.SelectionStartColumn);
  213. Assert.Equal (0, _textView.SelectionStartRow);
  214. Assert.Equal (0, _textView.SelectedLength);
  215. Assert.Equal ("", _textView.SelectedText);
  216. break;
  217. case 4:
  218. Assert.Equal (4, _textView.CursorPosition.X);
  219. Assert.Equal (0, _textView.CursorPosition.Y);
  220. Assert.Equal (0, _textView.SelectionStartColumn);
  221. Assert.Equal (0, _textView.SelectionStartRow);
  222. Assert.Equal (0, _textView.SelectedLength);
  223. Assert.Equal ("", _textView.SelectedText);
  224. break;
  225. case 5:
  226. Assert.Equal (0, _textView.CursorPosition.X);
  227. Assert.Equal (0, _textView.CursorPosition.Y);
  228. Assert.Equal (0, _textView.SelectionStartColumn);
  229. Assert.Equal (0, _textView.SelectionStartRow);
  230. Assert.Equal (0, _textView.SelectedLength);
  231. Assert.Equal ("", _textView.SelectedText);
  232. break;
  233. }
  234. iteration++;
  235. }
  236. }
  237. [Fact][InitShutdown]
  238. public void WordForward_With_Selection ()
  239. {
  240. _textView.CursorPosition = new Point (0, 0);
  241. _textView.SelectionStartColumn = 0;
  242. _textView.SelectionStartRow = 0;
  243. var iteration = 0;
  244. while (_textView.CursorPosition.X < _textView.Text.Length) {
  245. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  246. switch (iteration) {
  247. case 0:
  248. Assert.Equal (4, _textView.CursorPosition.X);
  249. Assert.Equal (0, _textView.CursorPosition.Y);
  250. Assert.Equal (0, _textView.SelectionStartColumn);
  251. Assert.Equal (0, _textView.SelectionStartRow);
  252. Assert.Equal (4, _textView.SelectedLength);
  253. Assert.Equal ("TAB ", _textView.SelectedText);
  254. break;
  255. case 1:
  256. Assert.Equal (7, _textView.CursorPosition.X);
  257. Assert.Equal (0, _textView.CursorPosition.Y);
  258. Assert.Equal (0, _textView.SelectionStartColumn);
  259. Assert.Equal (0, _textView.SelectionStartRow);
  260. Assert.Equal (7, _textView.SelectedLength);
  261. Assert.Equal ("TAB to ", _textView.SelectedText);
  262. break;
  263. case 2:
  264. Assert.Equal (12, _textView.CursorPosition.X);
  265. Assert.Equal (0, _textView.CursorPosition.Y);
  266. Assert.Equal (0, _textView.SelectionStartColumn);
  267. Assert.Equal (0, _textView.SelectionStartRow);
  268. Assert.Equal (12, _textView.SelectedLength);
  269. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  270. break;
  271. case 3:
  272. Assert.Equal (20, _textView.CursorPosition.X);
  273. Assert.Equal (0, _textView.CursorPosition.Y);
  274. Assert.Equal (0, _textView.SelectionStartColumn);
  275. Assert.Equal (0, _textView.SelectionStartRow);
  276. Assert.Equal (20, _textView.SelectedLength);
  277. Assert.Equal ("TAB to jump between ", _textView.SelectedText);
  278. break;
  279. case 4:
  280. Assert.Equal (25, _textView.CursorPosition.X);
  281. Assert.Equal (0, _textView.CursorPosition.Y);
  282. Assert.Equal (0, _textView.SelectionStartColumn);
  283. Assert.Equal (0, _textView.SelectionStartRow);
  284. Assert.Equal (25, _textView.SelectedLength);
  285. Assert.Equal ("TAB to jump between text ", _textView.SelectedText);
  286. break;
  287. case 5:
  288. Assert.Equal (32, _textView.CursorPosition.X);
  289. Assert.Equal (0, _textView.CursorPosition.Y);
  290. Assert.Equal (0, _textView.SelectionStartColumn);
  291. Assert.Equal (0, _textView.SelectionStartRow);
  292. Assert.Equal (32, _textView.SelectedLength);
  293. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  294. break;
  295. }
  296. iteration++;
  297. }
  298. }
  299. [Fact][InitShutdown]
  300. public void WordBackward_With_Selection ()
  301. {
  302. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  303. _textView.SelectionStartColumn = _textView.Text.Length;
  304. _textView.SelectionStartRow = 0;
  305. var iteration = 0;
  306. while (_textView.CursorPosition.X > 0) {
  307. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  308. switch (iteration) {
  309. case 0:
  310. Assert.Equal (25, _textView.CursorPosition.X);
  311. Assert.Equal (0, _textView.CursorPosition.Y);
  312. Assert.Equal (32, _textView.SelectionStartColumn);
  313. Assert.Equal (0, _textView.SelectionStartRow);
  314. Assert.Equal (7, _textView.SelectedLength);
  315. Assert.Equal ("fields.", _textView.SelectedText);
  316. break;
  317. case 1:
  318. Assert.Equal (20, _textView.CursorPosition.X);
  319. Assert.Equal (0, _textView.CursorPosition.Y);
  320. Assert.Equal (32, _textView.SelectionStartColumn);
  321. Assert.Equal (0, _textView.SelectionStartRow);
  322. Assert.Equal (12, _textView.SelectedLength);
  323. Assert.Equal ("text fields.", _textView.SelectedText);
  324. break;
  325. case 2:
  326. Assert.Equal (12, _textView.CursorPosition.X);
  327. Assert.Equal (0, _textView.CursorPosition.Y);
  328. Assert.Equal (32, _textView.SelectionStartColumn);
  329. Assert.Equal (0, _textView.SelectionStartRow);
  330. Assert.Equal (20, _textView.SelectedLength);
  331. Assert.Equal ("between text fields.", _textView.SelectedText);
  332. break;
  333. case 3:
  334. Assert.Equal (7, _textView.CursorPosition.X);
  335. Assert.Equal (0, _textView.CursorPosition.Y);
  336. Assert.Equal (32, _textView.SelectionStartColumn);
  337. Assert.Equal (0, _textView.SelectionStartRow);
  338. Assert.Equal (25, _textView.SelectedLength);
  339. Assert.Equal ("jump between text fields.", _textView.SelectedText);
  340. break;
  341. case 4:
  342. Assert.Equal (4, _textView.CursorPosition.X);
  343. Assert.Equal (0, _textView.CursorPosition.Y);
  344. Assert.Equal (32, _textView.SelectionStartColumn);
  345. Assert.Equal (0, _textView.SelectionStartRow);
  346. Assert.Equal (28, _textView.SelectedLength);
  347. Assert.Equal ("to jump between text fields.", _textView.SelectedText);
  348. break;
  349. case 5:
  350. Assert.Equal (0, _textView.CursorPosition.X);
  351. Assert.Equal (0, _textView.CursorPosition.Y);
  352. Assert.Equal (32, _textView.SelectionStartColumn);
  353. Assert.Equal (0, _textView.SelectionStartRow);
  354. Assert.Equal (32, _textView.SelectedLength);
  355. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  356. break;
  357. }
  358. iteration++;
  359. }
  360. }
  361. [Fact][InitShutdown]
  362. public void WordForward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  363. {
  364. _textView.CursorPosition = new Point (10, 0);
  365. _textView.SelectionStartColumn = 10;
  366. _textView.SelectionStartRow = 0;
  367. var iteration = 0;
  368. while (_textView.CursorPosition.X < _textView.Text.Length) {
  369. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  370. switch (iteration) {
  371. case 0:
  372. Assert.Equal (12, _textView.CursorPosition.X);
  373. Assert.Equal (0, _textView.CursorPosition.Y);
  374. Assert.Equal (10, _textView.SelectionStartColumn);
  375. Assert.Equal (0, _textView.SelectionStartRow);
  376. Assert.Equal (2, _textView.SelectedLength);
  377. Assert.Equal ("p ", _textView.SelectedText);
  378. break;
  379. case 1:
  380. Assert.Equal (20, _textView.CursorPosition.X);
  381. Assert.Equal (0, _textView.CursorPosition.Y);
  382. Assert.Equal (10, _textView.SelectionStartColumn);
  383. Assert.Equal (0, _textView.SelectionStartRow);
  384. Assert.Equal (10, _textView.SelectedLength);
  385. Assert.Equal ("p between ", _textView.SelectedText);
  386. break;
  387. case 2:
  388. Assert.Equal (25, _textView.CursorPosition.X);
  389. Assert.Equal (0, _textView.CursorPosition.Y);
  390. Assert.Equal (10, _textView.SelectionStartColumn);
  391. Assert.Equal (0, _textView.SelectionStartRow);
  392. Assert.Equal (15, _textView.SelectedLength);
  393. Assert.Equal ("p between text ", _textView.SelectedText);
  394. break;
  395. case 3:
  396. Assert.Equal (32, _textView.CursorPosition.X);
  397. Assert.Equal (0, _textView.CursorPosition.Y);
  398. Assert.Equal (10, _textView.SelectionStartColumn);
  399. Assert.Equal (0, _textView.SelectionStartRow);
  400. Assert.Equal (22, _textView.SelectedLength);
  401. Assert.Equal ("p between text fields.", _textView.SelectedText);
  402. break;
  403. }
  404. iteration++;
  405. }
  406. }
  407. [Fact][InitShutdown]
  408. public void WordBackward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  409. {
  410. _textView.CursorPosition = new Point (10, 0);
  411. _textView.SelectionStartColumn = 10;
  412. _textView.SelectionStartRow = 0;
  413. var iteration = 0;
  414. while (_textView.CursorPosition.X > 0) {
  415. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  416. switch (iteration) {
  417. case 0:
  418. Assert.Equal (7, _textView.CursorPosition.X);
  419. Assert.Equal (0, _textView.CursorPosition.Y);
  420. Assert.Equal (10, _textView.SelectionStartColumn);
  421. Assert.Equal (0, _textView.SelectionStartRow);
  422. Assert.Equal (3, _textView.SelectedLength);
  423. Assert.Equal ("jum", _textView.SelectedText);
  424. break;
  425. case 1:
  426. Assert.Equal (4, _textView.CursorPosition.X);
  427. Assert.Equal (0, _textView.CursorPosition.Y);
  428. Assert.Equal (10, _textView.SelectionStartColumn);
  429. Assert.Equal (0, _textView.SelectionStartRow);
  430. Assert.Equal (6, _textView.SelectedLength);
  431. Assert.Equal ("to jum", _textView.SelectedText);
  432. break;
  433. case 2:
  434. Assert.Equal (0, _textView.CursorPosition.X);
  435. Assert.Equal (0, _textView.CursorPosition.Y);
  436. Assert.Equal (10, _textView.SelectionStartColumn);
  437. Assert.Equal (0, _textView.SelectionStartRow);
  438. Assert.Equal (10, _textView.SelectedLength);
  439. Assert.Equal ("TAB to jum", _textView.SelectedText);
  440. break;
  441. }
  442. iteration++;
  443. }
  444. }
  445. [Fact][InitShutdown]
  446. public void WordForward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  447. {
  448. // 1 2 3 4 5
  449. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  450. _textView.Text = "TAB t o jump b etween t ext f ields .";
  451. _textView.CursorPosition = new Point (0, 0);
  452. var iteration = 0;
  453. while (_textView.CursorPosition.X < _textView.Text.Length) {
  454. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()));
  455. switch (iteration) {
  456. case 0:
  457. Assert.Equal (6, _textView.CursorPosition.X);
  458. Assert.Equal (0, _textView.CursorPosition.Y);
  459. Assert.Equal (0, _textView.SelectionStartColumn);
  460. Assert.Equal (0, _textView.SelectionStartRow);
  461. Assert.Equal (0, _textView.SelectedLength);
  462. Assert.Equal ("", _textView.SelectedText);
  463. break;
  464. case 1:
  465. Assert.Equal (9, _textView.CursorPosition.X);
  466. Assert.Equal (0, _textView.CursorPosition.Y);
  467. Assert.Equal (0, _textView.SelectionStartColumn);
  468. Assert.Equal (0, _textView.SelectionStartRow);
  469. Assert.Equal (0, _textView.SelectedLength);
  470. Assert.Equal ("", _textView.SelectedText);
  471. break;
  472. case 2:
  473. Assert.Equal (12, _textView.CursorPosition.X);
  474. Assert.Equal (0, _textView.CursorPosition.Y);
  475. Assert.Equal (0, _textView.SelectionStartColumn);
  476. Assert.Equal (0, _textView.SelectionStartRow);
  477. Assert.Equal (0, _textView.SelectedLength);
  478. Assert.Equal ("", _textView.SelectedText);
  479. break;
  480. case 3:
  481. Assert.Equal (25, _textView.CursorPosition.X);
  482. Assert.Equal (0, _textView.CursorPosition.Y);
  483. Assert.Equal (0, _textView.SelectionStartColumn);
  484. Assert.Equal (0, _textView.SelectionStartRow);
  485. Assert.Equal (0, _textView.SelectedLength);
  486. Assert.Equal ("", _textView.SelectedText);
  487. break;
  488. case 4:
  489. Assert.Equal (28, _textView.CursorPosition.X);
  490. Assert.Equal (0, _textView.CursorPosition.Y);
  491. Assert.Equal (0, _textView.SelectionStartColumn);
  492. Assert.Equal (0, _textView.SelectionStartRow);
  493. Assert.Equal (0, _textView.SelectedLength);
  494. Assert.Equal ("", _textView.SelectedText);
  495. break;
  496. case 5:
  497. Assert.Equal (38, _textView.CursorPosition.X);
  498. Assert.Equal (0, _textView.CursorPosition.Y);
  499. Assert.Equal (0, _textView.SelectionStartColumn);
  500. Assert.Equal (0, _textView.SelectionStartRow);
  501. Assert.Equal (0, _textView.SelectedLength);
  502. Assert.Equal ("", _textView.SelectedText);
  503. break;
  504. case 6:
  505. Assert.Equal (40, _textView.CursorPosition.X);
  506. Assert.Equal (0, _textView.CursorPosition.Y);
  507. Assert.Equal (0, _textView.SelectionStartColumn);
  508. Assert.Equal (0, _textView.SelectionStartRow);
  509. Assert.Equal (0, _textView.SelectedLength);
  510. Assert.Equal ("", _textView.SelectedText);
  511. break;
  512. case 7:
  513. Assert.Equal (46, _textView.CursorPosition.X);
  514. Assert.Equal (0, _textView.CursorPosition.Y);
  515. Assert.Equal (0, _textView.SelectionStartColumn);
  516. Assert.Equal (0, _textView.SelectionStartRow);
  517. Assert.Equal (0, _textView.SelectedLength);
  518. Assert.Equal ("", _textView.SelectedText);
  519. break;
  520. case 8:
  521. Assert.Equal (48, _textView.CursorPosition.X);
  522. Assert.Equal (0, _textView.CursorPosition.Y);
  523. Assert.Equal (0, _textView.SelectionStartColumn);
  524. Assert.Equal (0, _textView.SelectionStartRow);
  525. Assert.Equal (0, _textView.SelectedLength);
  526. Assert.Equal ("", _textView.SelectedText);
  527. break;
  528. case 9:
  529. Assert.Equal (55, _textView.CursorPosition.X);
  530. Assert.Equal (0, _textView.CursorPosition.Y);
  531. Assert.Equal (0, _textView.SelectionStartColumn);
  532. Assert.Equal (0, _textView.SelectionStartRow);
  533. Assert.Equal (0, _textView.SelectedLength);
  534. Assert.Equal ("", _textView.SelectedText);
  535. break;
  536. }
  537. iteration++;
  538. }
  539. }
  540. [Fact][InitShutdown]
  541. public void WordBackward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  542. {
  543. // 1 2 3 4 5
  544. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  545. _textView.Text = "TAB t o jump b etween t ext f ields .";
  546. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  547. var iteration = 0;
  548. while (_textView.CursorPosition.X > 0) {
  549. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()));
  550. switch (iteration) {
  551. case 0:
  552. Assert.Equal (54, _textView.CursorPosition.X);
  553. Assert.Equal (0, _textView.CursorPosition.Y);
  554. Assert.Equal (0, _textView.SelectionStartColumn);
  555. Assert.Equal (0, _textView.SelectionStartRow);
  556. Assert.Equal (0, _textView.SelectedLength);
  557. Assert.Equal ("", _textView.SelectedText);
  558. break;
  559. case 1:
  560. Assert.Equal (48, _textView.CursorPosition.X);
  561. Assert.Equal (0, _textView.CursorPosition.Y);
  562. Assert.Equal (0, _textView.SelectionStartColumn);
  563. Assert.Equal (0, _textView.SelectionStartRow);
  564. Assert.Equal (0, _textView.SelectedLength);
  565. Assert.Equal ("", _textView.SelectedText);
  566. break;
  567. case 2:
  568. Assert.Equal (46, _textView.CursorPosition.X);
  569. Assert.Equal (0, _textView.CursorPosition.Y);
  570. Assert.Equal (0, _textView.SelectionStartColumn);
  571. Assert.Equal (0, _textView.SelectionStartRow);
  572. Assert.Equal (0, _textView.SelectedLength);
  573. Assert.Equal ("", _textView.SelectedText);
  574. break;
  575. case 3:
  576. Assert.Equal (40, _textView.CursorPosition.X);
  577. Assert.Equal (0, _textView.CursorPosition.Y);
  578. Assert.Equal (0, _textView.SelectionStartColumn);
  579. Assert.Equal (0, _textView.SelectionStartRow);
  580. Assert.Equal (0, _textView.SelectedLength);
  581. Assert.Equal ("", _textView.SelectedText);
  582. break;
  583. case 4:
  584. Assert.Equal (38, _textView.CursorPosition.X);
  585. Assert.Equal (0, _textView.CursorPosition.Y);
  586. Assert.Equal (0, _textView.SelectionStartColumn);
  587. Assert.Equal (0, _textView.SelectionStartRow);
  588. Assert.Equal (0, _textView.SelectedLength);
  589. Assert.Equal ("", _textView.SelectedText);
  590. break;
  591. case 5:
  592. Assert.Equal (28, _textView.CursorPosition.X);
  593. Assert.Equal (0, _textView.CursorPosition.Y);
  594. Assert.Equal (0, _textView.SelectionStartColumn);
  595. Assert.Equal (0, _textView.SelectionStartRow);
  596. Assert.Equal (0, _textView.SelectedLength);
  597. Assert.Equal ("", _textView.SelectedText);
  598. break;
  599. case 6:
  600. Assert.Equal (25, _textView.CursorPosition.X);
  601. Assert.Equal (0, _textView.CursorPosition.Y);
  602. Assert.Equal (0, _textView.SelectionStartColumn);
  603. Assert.Equal (0, _textView.SelectionStartRow);
  604. Assert.Equal (0, _textView.SelectedLength);
  605. Assert.Equal ("", _textView.SelectedText);
  606. break;
  607. case 7:
  608. Assert.Equal (12, _textView.CursorPosition.X);
  609. Assert.Equal (0, _textView.CursorPosition.Y);
  610. Assert.Equal (0, _textView.SelectionStartColumn);
  611. Assert.Equal (0, _textView.SelectionStartRow);
  612. Assert.Equal (0, _textView.SelectedLength);
  613. Assert.Equal ("", _textView.SelectedText);
  614. break;
  615. case 8:
  616. Assert.Equal (9, _textView.CursorPosition.X);
  617. Assert.Equal (0, _textView.CursorPosition.Y);
  618. Assert.Equal (0, _textView.SelectionStartColumn);
  619. Assert.Equal (0, _textView.SelectionStartRow);
  620. Assert.Equal (0, _textView.SelectedLength);
  621. Assert.Equal ("", _textView.SelectedText);
  622. break;
  623. case 9:
  624. Assert.Equal (6, _textView.CursorPosition.X);
  625. Assert.Equal (0, _textView.CursorPosition.Y);
  626. Assert.Equal (0, _textView.SelectionStartColumn);
  627. Assert.Equal (0, _textView.SelectionStartRow);
  628. Assert.Equal (0, _textView.SelectedLength);
  629. Assert.Equal ("", _textView.SelectedText);
  630. break;
  631. case 10:
  632. Assert.Equal (0, _textView.CursorPosition.X);
  633. Assert.Equal (0, _textView.CursorPosition.Y);
  634. Assert.Equal (0, _textView.SelectionStartColumn);
  635. Assert.Equal (0, _textView.SelectionStartRow);
  636. Assert.Equal (0, _textView.SelectedLength);
  637. Assert.Equal ("", _textView.SelectedText);
  638. break;
  639. }
  640. iteration++;
  641. }
  642. }
  643. [Fact][InitShutdown]
  644. public void WordBackward_Multiline_With_Selection ()
  645. {
  646. // 4 3 2 1
  647. // 87654321098765432109876 54321098765432109876543210-Length
  648. // 1 2 1 2
  649. // 01234567890123456789012 0123456789012345678901234
  650. _textView.Text = "This is the first line.\nThis is the second line.";
  651. _textView.MoveEnd ();
  652. _textView.SelectionStartColumn = _textView.CurrentColumn;
  653. _textView.SelectionStartRow = _textView.CurrentRow;
  654. var iteration = 0;
  655. bool iterationsFinished = false;
  656. while (!iterationsFinished) {
  657. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  658. switch (iteration) {
  659. case 0:
  660. Assert.Equal (19, _textView.CursorPosition.X);
  661. Assert.Equal (1, _textView.CursorPosition.Y);
  662. Assert.Equal (24, _textView.SelectionStartColumn);
  663. Assert.Equal (1, _textView.SelectionStartRow);
  664. Assert.Equal (5, _textView.SelectedLength);
  665. Assert.Equal ("line.", _textView.SelectedText);
  666. break;
  667. case 1:
  668. Assert.Equal (12, _textView.CursorPosition.X);
  669. Assert.Equal (1, _textView.CursorPosition.Y);
  670. Assert.Equal (24, _textView.SelectionStartColumn);
  671. Assert.Equal (1, _textView.SelectionStartRow);
  672. Assert.Equal (12, _textView.SelectedLength);
  673. Assert.Equal ("second line.", _textView.SelectedText);
  674. break;
  675. case 2:
  676. Assert.Equal (8, _textView.CursorPosition.X);
  677. Assert.Equal (1, _textView.CursorPosition.Y);
  678. Assert.Equal (24, _textView.SelectionStartColumn);
  679. Assert.Equal (1, _textView.SelectionStartRow);
  680. Assert.Equal (16, _textView.SelectedLength);
  681. Assert.Equal ("the second line.", _textView.SelectedText);
  682. break;
  683. case 3:
  684. Assert.Equal (5, _textView.CursorPosition.X);
  685. Assert.Equal (1, _textView.CursorPosition.Y);
  686. Assert.Equal (24, _textView.SelectionStartColumn);
  687. Assert.Equal (1, _textView.SelectionStartRow);
  688. Assert.Equal (19, _textView.SelectedLength);
  689. Assert.Equal ("is the second line.", _textView.SelectedText);
  690. break;
  691. case 4:
  692. Assert.Equal (0, _textView.CursorPosition.X);
  693. Assert.Equal (1, _textView.CursorPosition.Y);
  694. Assert.Equal (24, _textView.SelectionStartColumn);
  695. Assert.Equal (1, _textView.SelectionStartRow);
  696. Assert.Equal (24, _textView.SelectedLength);
  697. Assert.Equal ("This is the second line.", _textView.SelectedText);
  698. break;
  699. case 5:
  700. Assert.Equal (23, _textView.CursorPosition.X);
  701. Assert.Equal (0, _textView.CursorPosition.Y);
  702. Assert.Equal (24, _textView.SelectionStartColumn);
  703. Assert.Equal (1, _textView.SelectionStartRow);
  704. Assert.Equal (25, _textView.SelectedLength);
  705. Assert.Equal ("\nThis is the second line.", _textView.SelectedText);
  706. break;
  707. case 6:
  708. Assert.Equal (18, _textView.CursorPosition.X);
  709. Assert.Equal (0, _textView.CursorPosition.Y);
  710. Assert.Equal (24, _textView.SelectionStartColumn);
  711. Assert.Equal (1, _textView.SelectionStartRow);
  712. Assert.Equal (30, _textView.SelectedLength);
  713. Assert.Equal ("line.\nThis is the second line.", _textView.SelectedText);
  714. break;
  715. case 7:
  716. Assert.Equal (12, _textView.CursorPosition.X);
  717. Assert.Equal (0, _textView.CursorPosition.Y);
  718. Assert.Equal (24, _textView.SelectionStartColumn);
  719. Assert.Equal (1, _textView.SelectionStartRow);
  720. Assert.Equal (36, _textView.SelectedLength);
  721. Assert.Equal ("first line.\nThis is the second line.", _textView.SelectedText);
  722. break;
  723. case 8:
  724. Assert.Equal (8, _textView.CursorPosition.X);
  725. Assert.Equal (0, _textView.CursorPosition.Y);
  726. Assert.Equal (24, _textView.SelectionStartColumn);
  727. Assert.Equal (1, _textView.SelectionStartRow);
  728. Assert.Equal (40, _textView.SelectedLength);
  729. Assert.Equal ("the first line.\nThis is the second line.", _textView.SelectedText);
  730. break;
  731. case 9:
  732. Assert.Equal (5, _textView.CursorPosition.X);
  733. Assert.Equal (0, _textView.CursorPosition.Y);
  734. Assert.Equal (24, _textView.SelectionStartColumn);
  735. Assert.Equal (1, _textView.SelectionStartRow);
  736. Assert.Equal (43, _textView.SelectedLength);
  737. Assert.Equal ("is the first line.\nThis is the second line.", _textView.SelectedText);
  738. break;
  739. case 10:
  740. Assert.Equal (0, _textView.CursorPosition.X);
  741. Assert.Equal (0, _textView.CursorPosition.Y);
  742. Assert.Equal (24, _textView.SelectionStartColumn);
  743. Assert.Equal (1, _textView.SelectionStartRow);
  744. Assert.Equal (48, _textView.SelectedLength);
  745. Assert.Equal ("This is the first line.\nThis is the second line.", _textView.SelectedText);
  746. break;
  747. default:
  748. iterationsFinished = true;
  749. break;
  750. }
  751. iteration++;
  752. }
  753. }
  754. [Fact][InitShutdown]
  755. public void WordForward_Multiline_With_Selection ()
  756. {
  757. // 1 2 3 4
  758. // 01234567890123456789012 34567890123456789012345678-Length
  759. // 1 2 1 2
  760. // 01234567890123456789012 0123456789012345678901234
  761. _textView.Text = "This is the first line.\nThis is the second line.";
  762. _textView.SelectionStartColumn = _textView.CurrentColumn;
  763. _textView.SelectionStartRow = _textView.CurrentRow;
  764. var iteration = 0;
  765. bool iterationsFinished = false;
  766. while (!iterationsFinished) {
  767. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  768. switch (iteration) {
  769. case 0:
  770. Assert.Equal (5, _textView.CursorPosition.X);
  771. Assert.Equal (0, _textView.CursorPosition.Y);
  772. Assert.Equal (0, _textView.SelectionStartColumn);
  773. Assert.Equal (0, _textView.SelectionStartRow);
  774. Assert.Equal (5, _textView.SelectedLength);
  775. Assert.Equal ("This ", _textView.SelectedText);
  776. break;
  777. case 1:
  778. Assert.Equal (8, _textView.CursorPosition.X);
  779. Assert.Equal (0, _textView.CursorPosition.Y);
  780. Assert.Equal (0, _textView.SelectionStartColumn);
  781. Assert.Equal (0, _textView.SelectionStartRow);
  782. Assert.Equal (8, _textView.SelectedLength);
  783. Assert.Equal ("This is ", _textView.SelectedText);
  784. break;
  785. case 2:
  786. Assert.Equal (12, _textView.CursorPosition.X);
  787. Assert.Equal (0, _textView.CursorPosition.Y);
  788. Assert.Equal (0, _textView.SelectionStartColumn);
  789. Assert.Equal (0, _textView.SelectionStartRow);
  790. Assert.Equal (12, _textView.SelectedLength);
  791. Assert.Equal ("This is the ", _textView.SelectedText);
  792. break;
  793. case 3:
  794. Assert.Equal (18, _textView.CursorPosition.X);
  795. Assert.Equal (0, _textView.CursorPosition.Y);
  796. Assert.Equal (0, _textView.SelectionStartColumn);
  797. Assert.Equal (0, _textView.SelectionStartRow);
  798. Assert.Equal (18, _textView.SelectedLength);
  799. Assert.Equal ("This is the first ", _textView.SelectedText);
  800. break;
  801. case 4:
  802. Assert.Equal (23, _textView.CursorPosition.X);
  803. Assert.Equal (0, _textView.CursorPosition.Y);
  804. Assert.Equal (0, _textView.SelectionStartColumn);
  805. Assert.Equal (0, _textView.SelectionStartRow);
  806. Assert.Equal (23, _textView.SelectedLength);
  807. Assert.Equal ("This is the first line.", _textView.SelectedText);
  808. break;
  809. case 5:
  810. Assert.Equal (0, _textView.CursorPosition.X);
  811. Assert.Equal (1, _textView.CursorPosition.Y);
  812. Assert.Equal (0, _textView.SelectionStartColumn);
  813. Assert.Equal (0, _textView.SelectionStartRow);
  814. Assert.Equal (24, _textView.SelectedLength);
  815. Assert.Equal ("This is the first line.\n", _textView.SelectedText);
  816. break;
  817. case 6:
  818. Assert.Equal (5, _textView.CursorPosition.X);
  819. Assert.Equal (1, _textView.CursorPosition.Y);
  820. Assert.Equal (0, _textView.SelectionStartColumn);
  821. Assert.Equal (0, _textView.SelectionStartRow);
  822. Assert.Equal (29, _textView.SelectedLength);
  823. Assert.Equal ("This is the first line.\nThis ", _textView.SelectedText);
  824. break;
  825. case 7:
  826. Assert.Equal (8, _textView.CursorPosition.X);
  827. Assert.Equal (1, _textView.CursorPosition.Y);
  828. Assert.Equal (0, _textView.SelectionStartColumn);
  829. Assert.Equal (0, _textView.SelectionStartRow);
  830. Assert.Equal (32, _textView.SelectedLength);
  831. Assert.Equal ("This is the first line.\nThis is ", _textView.SelectedText);
  832. break;
  833. case 8:
  834. Assert.Equal (12, _textView.CursorPosition.X);
  835. Assert.Equal (1, _textView.CursorPosition.Y);
  836. Assert.Equal (0, _textView.SelectionStartColumn);
  837. Assert.Equal (0, _textView.SelectionStartRow);
  838. Assert.Equal (36, _textView.SelectedLength);
  839. Assert.Equal ("This is the first line.\nThis is the ", _textView.SelectedText);
  840. break;
  841. case 9:
  842. Assert.Equal (19, _textView.CursorPosition.X);
  843. Assert.Equal (1, _textView.CursorPosition.Y);
  844. Assert.Equal (0, _textView.SelectionStartColumn);
  845. Assert.Equal (0, _textView.SelectionStartRow);
  846. Assert.Equal (43, _textView.SelectedLength);
  847. Assert.Equal ("This is the first line.\nThis is the second ", _textView.SelectedText);
  848. break;
  849. case 10:
  850. Assert.Equal (24, _textView.CursorPosition.X);
  851. Assert.Equal (1, _textView.CursorPosition.Y);
  852. Assert.Equal (0, _textView.SelectionStartColumn);
  853. Assert.Equal (0, _textView.SelectionStartRow);
  854. Assert.Equal (48, _textView.SelectedLength);
  855. Assert.Equal ("This is the first line.\nThis is the second line.", _textView.SelectedText);
  856. break;
  857. default:
  858. iterationsFinished = true;
  859. break;
  860. }
  861. iteration++;
  862. }
  863. }
  864. [Fact][InitShutdown]
  865. public void Kill_To_End_Delete_Forwards_And_Copy_To_The_Clipboard ()
  866. {
  867. _textView.Text = "This is the first line.\nThis is the second line.";
  868. var iteration = 0;
  869. bool iterationsFinished = false;
  870. while (!iterationsFinished) {
  871. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  872. switch (iteration) {
  873. case 0:
  874. Assert.Equal (0, _textView.CursorPosition.X);
  875. Assert.Equal (0, _textView.CursorPosition.Y);
  876. Assert.Equal ($"{System.Environment.NewLine}This is the second line.", _textView.Text);
  877. break;
  878. case 1:
  879. Assert.Equal (0, _textView.CursorPosition.X);
  880. Assert.Equal (0, _textView.CursorPosition.Y);
  881. Assert.Equal ("This is the second line.", _textView.Text);
  882. break;
  883. case 2:
  884. Assert.Equal (0, _textView.CursorPosition.X);
  885. Assert.Equal (0, _textView.CursorPosition.Y);
  886. Assert.Equal ("", _textView.Text);
  887. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  888. Assert.Equal ("This is the second line.", _textView.Text);
  889. break;
  890. default:
  891. iterationsFinished = true;
  892. break;
  893. }
  894. iteration++;
  895. }
  896. }
  897. [Fact][InitShutdown]
  898. public void Kill_To_Start_Delete_Backwards_And_Copy_To_The_Clipboard ()
  899. {
  900. _textView.Text = "This is the first line.\nThis is the second line.";
  901. _textView.MoveEnd ();
  902. var iteration = 0;
  903. bool iterationsFinished = false;
  904. while (!iterationsFinished) {
  905. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  906. switch (iteration) {
  907. case 0:
  908. Assert.Equal (0, _textView.CursorPosition.X);
  909. Assert.Equal (1, _textView.CursorPosition.Y);
  910. Assert.Equal ($"This is the first line.{System.Environment.NewLine}", _textView.Text);
  911. break;
  912. case 1:
  913. Assert.Equal (23, _textView.CursorPosition.X);
  914. Assert.Equal (0, _textView.CursorPosition.Y);
  915. Assert.Equal ("This is the first line.", _textView.Text);
  916. break;
  917. case 2:
  918. Assert.Equal (0, _textView.CursorPosition.X);
  919. Assert.Equal (0, _textView.CursorPosition.Y);
  920. Assert.Equal ("", _textView.Text);
  921. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  922. Assert.Equal ("This is the first line.", _textView.Text);
  923. break;
  924. default:
  925. iterationsFinished = true;
  926. break;
  927. }
  928. iteration++;
  929. }
  930. }
  931. [Fact][InitShutdown]
  932. public void Kill_Delete_WordForward ()
  933. {
  934. _textView.Text = "This is the first line.";
  935. var iteration = 0;
  936. bool iterationsFinished = false;
  937. while (!iterationsFinished) {
  938. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()));
  939. switch (iteration) {
  940. case 0:
  941. Assert.Equal (0, _textView.CursorPosition.X);
  942. Assert.Equal (0, _textView.CursorPosition.Y);
  943. Assert.Equal ("is the first line.", _textView.Text);
  944. break;
  945. case 1:
  946. Assert.Equal (0, _textView.CursorPosition.X);
  947. Assert.Equal (0, _textView.CursorPosition.Y);
  948. Assert.Equal ("the first line.", _textView.Text);
  949. break;
  950. case 2:
  951. Assert.Equal (0, _textView.CursorPosition.X);
  952. Assert.Equal (0, _textView.CursorPosition.Y);
  953. Assert.Equal ("first line.", _textView.Text);
  954. break;
  955. case 3:
  956. Assert.Equal (0, _textView.CursorPosition.X);
  957. Assert.Equal (0, _textView.CursorPosition.Y);
  958. Assert.Equal ("line.", _textView.Text);
  959. break;
  960. case 4:
  961. Assert.Equal (0, _textView.CursorPosition.X);
  962. Assert.Equal (0, _textView.CursorPosition.Y);
  963. Assert.Equal ("", _textView.Text);
  964. break;
  965. default:
  966. iterationsFinished = true;
  967. break;
  968. }
  969. iteration++;
  970. }
  971. }
  972. [Fact][InitShutdown]
  973. public void Kill_Delete_WordBackward ()
  974. {
  975. _textView.Text = "This is the first line.";
  976. _textView.MoveEnd ();
  977. var iteration = 0;
  978. bool iterationsFinished = false;
  979. while (!iterationsFinished) {
  980. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()));
  981. switch (iteration) {
  982. case 0:
  983. Assert.Equal (18, _textView.CursorPosition.X);
  984. Assert.Equal (0, _textView.CursorPosition.Y);
  985. Assert.Equal ("This is the first ", _textView.Text);
  986. break;
  987. case 1:
  988. Assert.Equal (12, _textView.CursorPosition.X);
  989. Assert.Equal (0, _textView.CursorPosition.Y);
  990. Assert.Equal ("This is the ", _textView.Text);
  991. break;
  992. case 2:
  993. Assert.Equal (8, _textView.CursorPosition.X);
  994. Assert.Equal (0, _textView.CursorPosition.Y);
  995. Assert.Equal ("This is ", _textView.Text);
  996. break;
  997. case 3:
  998. Assert.Equal (5, _textView.CursorPosition.X);
  999. Assert.Equal (0, _textView.CursorPosition.Y);
  1000. Assert.Equal ("This ", _textView.Text);
  1001. break;
  1002. case 4:
  1003. Assert.Equal (0, _textView.CursorPosition.X);
  1004. Assert.Equal (0, _textView.CursorPosition.Y);
  1005. Assert.Equal ("", _textView.Text);
  1006. break;
  1007. default:
  1008. iterationsFinished = true;
  1009. break;
  1010. }
  1011. iteration++;
  1012. }
  1013. }
  1014. [Fact][InitShutdown]
  1015. public void Kill_Delete_WordForward_Multiline ()
  1016. {
  1017. _textView.Text = "This is the first line.\nThis is the second line.";
  1018. _textView.Width = 4;
  1019. var iteration = 0;
  1020. bool iterationsFinished = false;
  1021. while (!iterationsFinished) {
  1022. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()));
  1023. switch (iteration) {
  1024. case 0:
  1025. Assert.Equal (0, _textView.CursorPosition.X);
  1026. Assert.Equal (0, _textView.CursorPosition.Y);
  1027. Assert.Equal ("is the first line." + Environment.NewLine
  1028. + "This is the second line.", _textView.Text);
  1029. break;
  1030. case 1:
  1031. Assert.Equal (0, _textView.CursorPosition.X);
  1032. Assert.Equal (0, _textView.CursorPosition.Y);
  1033. Assert.Equal ("the first line." + Environment.NewLine
  1034. + "This is the second line.", _textView.Text);
  1035. break;
  1036. case 2:
  1037. Assert.Equal (0, _textView.CursorPosition.X);
  1038. Assert.Equal (0, _textView.CursorPosition.Y);
  1039. Assert.Equal ("first line." + Environment.NewLine
  1040. + "This is the second line.", _textView.Text);
  1041. break;
  1042. case 3:
  1043. Assert.Equal (0, _textView.CursorPosition.X);
  1044. Assert.Equal (0, _textView.CursorPosition.Y);
  1045. Assert.Equal ("line." + Environment.NewLine
  1046. + "This is the second line.", _textView.Text);
  1047. break;
  1048. case 4:
  1049. Assert.Equal (0, _textView.CursorPosition.X);
  1050. Assert.Equal (0, _textView.CursorPosition.Y);
  1051. Assert.Equal ("" + Environment.NewLine
  1052. + "This is the second line.", _textView.Text);
  1053. break;
  1054. case 5:
  1055. Assert.Equal (0, _textView.CursorPosition.X);
  1056. Assert.Equal (0, _textView.CursorPosition.Y);
  1057. Assert.Equal ("This is the second line.", _textView.Text);
  1058. break;
  1059. case 6:
  1060. Assert.Equal (0, _textView.CursorPosition.X);
  1061. Assert.Equal (0, _textView.CursorPosition.Y);
  1062. Assert.Equal ("is the second line.", _textView.Text);
  1063. break;
  1064. case 7:
  1065. Assert.Equal (0, _textView.CursorPosition.X);
  1066. Assert.Equal (0, _textView.CursorPosition.Y);
  1067. Assert.Equal ("the second line.", _textView.Text);
  1068. break;
  1069. case 8:
  1070. Assert.Equal (0, _textView.CursorPosition.X);
  1071. Assert.Equal (0, _textView.CursorPosition.Y);
  1072. Assert.Equal ("second line.", _textView.Text);
  1073. break;
  1074. case 9:
  1075. Assert.Equal (0, _textView.CursorPosition.X);
  1076. Assert.Equal (0, _textView.CursorPosition.Y);
  1077. Assert.Equal ("line.", _textView.Text);
  1078. break;
  1079. case 10:
  1080. Assert.Equal (0, _textView.CursorPosition.X);
  1081. Assert.Equal (0, _textView.CursorPosition.Y);
  1082. Assert.Equal ("", _textView.Text);
  1083. break;
  1084. default:
  1085. iterationsFinished = true;
  1086. break;
  1087. }
  1088. iteration++;
  1089. }
  1090. }
  1091. [Fact][InitShutdown]
  1092. public void Kill_Delete_WordBackward_Multiline ()
  1093. {
  1094. _textView.Text = "This is the first line.\nThis is the second line.";
  1095. _textView.Width = 4;
  1096. _textView.MoveEnd ();
  1097. var iteration = 0;
  1098. bool iterationsFinished = false;
  1099. while (!iterationsFinished) {
  1100. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()));
  1101. switch (iteration) {
  1102. case 0:
  1103. Assert.Equal (19, _textView.CursorPosition.X);
  1104. Assert.Equal (1, _textView.CursorPosition.Y);
  1105. Assert.Equal ("This is the first line." + Environment.NewLine
  1106. + "This is the second ", _textView.Text);
  1107. break;
  1108. case 1:
  1109. Assert.Equal (12, _textView.CursorPosition.X);
  1110. Assert.Equal (1, _textView.CursorPosition.Y);
  1111. Assert.Equal ("This is the first line." + Environment.NewLine
  1112. + "This is the ", _textView.Text);
  1113. break;
  1114. case 2:
  1115. Assert.Equal (8, _textView.CursorPosition.X);
  1116. Assert.Equal (1, _textView.CursorPosition.Y);
  1117. Assert.Equal ("This is the first line." + Environment.NewLine
  1118. + "This is ", _textView.Text);
  1119. break;
  1120. case 3:
  1121. Assert.Equal (5, _textView.CursorPosition.X);
  1122. Assert.Equal (1, _textView.CursorPosition.Y);
  1123. Assert.Equal ("This is the first line." + Environment.NewLine
  1124. + "This ", _textView.Text);
  1125. break;
  1126. case 4:
  1127. Assert.Equal (0, _textView.CursorPosition.X);
  1128. Assert.Equal (1, _textView.CursorPosition.Y);
  1129. Assert.Equal ("This is the first line." + Environment.NewLine, _textView.Text);
  1130. break;
  1131. case 5:
  1132. Assert.Equal (23, _textView.CursorPosition.X);
  1133. Assert.Equal (0, _textView.CursorPosition.Y);
  1134. Assert.Equal ("This is the first line.", _textView.Text);
  1135. break;
  1136. case 6:
  1137. Assert.Equal (18, _textView.CursorPosition.X);
  1138. Assert.Equal (0, _textView.CursorPosition.Y);
  1139. Assert.Equal ("This is the first ", _textView.Text);
  1140. break;
  1141. case 7:
  1142. Assert.Equal (12, _textView.CursorPosition.X);
  1143. Assert.Equal (0, _textView.CursorPosition.Y);
  1144. Assert.Equal ("This is the ", _textView.Text);
  1145. break;
  1146. case 8:
  1147. Assert.Equal (8, _textView.CursorPosition.X);
  1148. Assert.Equal (0, _textView.CursorPosition.Y);
  1149. Assert.Equal ("This is ", _textView.Text);
  1150. break;
  1151. case 9:
  1152. Assert.Equal (5, _textView.CursorPosition.X);
  1153. Assert.Equal (0, _textView.CursorPosition.Y);
  1154. Assert.Equal ("This ", _textView.Text);
  1155. break;
  1156. case 10:
  1157. Assert.Equal (0, _textView.CursorPosition.X);
  1158. Assert.Equal (0, _textView.CursorPosition.Y);
  1159. Assert.Equal ("", _textView.Text);
  1160. break;
  1161. default:
  1162. iterationsFinished = true;
  1163. break;
  1164. }
  1165. iteration++;
  1166. }
  1167. }
  1168. [Fact][InitShutdown]
  1169. public void Copy_Or_Cut_Null_If_No_Selection ()
  1170. {
  1171. _textView.SelectionStartColumn = 0;
  1172. _textView.SelectionStartRow = 0;
  1173. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1174. Assert.Equal ("", _textView.SelectedText);
  1175. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1176. Assert.Equal ("", _textView.SelectedText);
  1177. }
  1178. [Fact][InitShutdown]
  1179. public void Copy_Or_Cut_Not_Null_If_Has_Selection ()
  1180. {
  1181. _textView.SelectionStartColumn = 20;
  1182. _textView.SelectionStartRow = 0;
  1183. _textView.CursorPosition = new Point (24, 0);
  1184. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1185. Assert.Equal ("text", _textView.SelectedText);
  1186. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1187. Assert.Equal ("", _textView.SelectedText);
  1188. }
  1189. [Fact][InitShutdown]
  1190. public void Copy_Or_Cut_And_Paste_With_Selection ()
  1191. {
  1192. _textView.SelectionStartColumn = 20;
  1193. _textView.SelectionStartRow = 0;
  1194. _textView.CursorPosition = new Point (24, 0);
  1195. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1196. Assert.Equal ("text", _textView.SelectedText);
  1197. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1198. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1199. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1200. _textView.SelectionStartColumn = 20;
  1201. _textView.SelectionStartRow = 0;
  1202. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1203. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1204. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1205. }
  1206. [Fact][InitShutdown]
  1207. public void Copy_Or_Cut_And_Paste_With_No_Selection ()
  1208. {
  1209. _textView.SelectionStartColumn = 20;
  1210. _textView.SelectionStartRow = 0;
  1211. _textView.CursorPosition = new Point (24, 0);
  1212. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1213. Assert.Equal ("text", _textView.SelectedText);
  1214. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1215. _textView.SelectionStartColumn = 0;
  1216. _textView.SelectionStartRow = 0;
  1217. Assert.True (_textView.Selecting);
  1218. _textView.Selecting = false;
  1219. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1220. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1221. _textView.SelectionStartColumn = 24;
  1222. _textView.SelectionStartRow = 0;
  1223. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1224. Assert.Equal ("", _textView.SelectedText);
  1225. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1226. _textView.SelectionStartColumn = 0;
  1227. _textView.SelectionStartRow = 0;
  1228. Assert.True (_textView.Selecting);
  1229. _textView.Selecting = false;
  1230. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1231. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1232. }
  1233. [Fact][InitShutdown]
  1234. public void Cut_Not_Allowed_If_ReadOnly_Is_True ()
  1235. {
  1236. _textView.ReadOnly = true;
  1237. _textView.SelectionStartColumn = 20;
  1238. _textView.SelectionStartRow = 0;
  1239. _textView.CursorPosition = new Point (24, 0);
  1240. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1241. Assert.Equal ("text", _textView.SelectedText);
  1242. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Selecting is set to false after Cut.
  1243. Assert.Equal ("", _textView.SelectedText);
  1244. _textView.ReadOnly = false;
  1245. Assert.False (_textView.Selecting);
  1246. _textView.Selecting = true; // Needed to set Selecting to true.
  1247. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1248. Assert.Equal ("text", _textView.SelectedText);
  1249. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1250. Assert.Equal ("", _textView.SelectedText);
  1251. }
  1252. [Fact][InitShutdown]
  1253. public void Paste_Always_Clear_The_SelectedText ()
  1254. {
  1255. _textView.SelectionStartColumn = 20;
  1256. _textView.SelectionStartRow = 0;
  1257. _textView.CursorPosition = new Point (24, 0);
  1258. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1259. Assert.Equal ("text", _textView.SelectedText);
  1260. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1261. Assert.Equal ("", _textView.SelectedText);
  1262. }
  1263. [Fact][InitShutdown]
  1264. public void TextChanged_Event ()
  1265. {
  1266. _textView.TextChanged += () => {
  1267. if (_textView.Text == "changing") {
  1268. Assert.Equal ("changing", _textView.Text);
  1269. _textView.Text = "changed";
  1270. }
  1271. };
  1272. _textView.Text = "changing";
  1273. Assert.Equal ("changed", _textView.Text);
  1274. }
  1275. [Fact][InitShutdown]
  1276. public void Used_Is_True_By_Default ()
  1277. {
  1278. _textView.CursorPosition = new Point (10, 0);
  1279. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1280. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1281. Assert.Equal ("TAB to jumup between text fields.", _textView.Text);
  1282. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1283. Assert.Equal ("TAB to jumusp between text fields.", _textView.Text);
  1284. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1285. Assert.Equal ("TAB to jumusep between text fields.", _textView.Text);
  1286. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1287. Assert.Equal ("TAB to jumusedp between text fields.", _textView.Text);
  1288. }
  1289. [Fact][InitShutdown]
  1290. public void Used_Is_False ()
  1291. {
  1292. _textView.Used = false;
  1293. _textView.CursorPosition = new Point (10, 0);
  1294. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1295. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1296. Assert.Equal ("TAB to jumu between text fields.", _textView.Text);
  1297. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1298. Assert.Equal ("TAB to jumusbetween text fields.", _textView.Text);
  1299. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1300. Assert.Equal ("TAB to jumuseetween text fields.", _textView.Text);
  1301. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1302. Assert.Equal ("TAB to jumusedtween text fields.", _textView.Text);
  1303. }
  1304. [Fact][InitShutdown]
  1305. public void Copy_Without_Selection ()
  1306. {
  1307. _textView.Text = "This is the first line.\nThis is the second line.\n";
  1308. _textView.CursorPosition = new Point (0, _textView.Lines - 1);
  1309. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1310. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1311. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1312. _textView.CursorPosition = new Point (3, 1);
  1313. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1314. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1315. 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);
  1316. Assert.Equal (new Point (3, 2), _textView.CursorPosition);
  1317. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1318. 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);
  1319. Assert.Equal (new Point (3, 3), _textView.CursorPosition);
  1320. }
  1321. [Fact][InitShutdown]
  1322. public void TabWidth_Setting_To_Zero_Changes_AllowsTab_To_False_If_True ()
  1323. {
  1324. Assert.Equal (4, _textView.TabWidth);
  1325. Assert.True (_textView.AllowsTab);
  1326. Assert.True (_textView.AllowsReturn);
  1327. Assert.True (_textView.Multiline);
  1328. _textView.TabWidth = -1;
  1329. Assert.Equal (0, _textView.TabWidth);
  1330. Assert.False (_textView.AllowsTab);
  1331. Assert.False (_textView.AllowsReturn);
  1332. Assert.False (_textView.Multiline);
  1333. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1334. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1335. _textView.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ()));
  1336. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1337. }
  1338. [Fact][InitShutdown]
  1339. public void AllowsTab_Setting_To_True_Changes_TabWidth_To_Default_If_It_Is_Zero ()
  1340. {
  1341. _textView.TabWidth = 0;
  1342. Assert.Equal (0, _textView.TabWidth);
  1343. Assert.False (_textView.AllowsTab);
  1344. Assert.False (_textView.AllowsReturn);
  1345. Assert.False (_textView.Multiline);
  1346. _textView.AllowsTab = true;
  1347. Assert.True (_textView.AllowsTab);
  1348. Assert.Equal (4, _textView.TabWidth);
  1349. Assert.True (_textView.AllowsReturn);
  1350. Assert.True (_textView.Multiline);
  1351. }
  1352. [Fact][InitShutdown]
  1353. public void AllowsReturn_Setting_To_True_Changes_Multiline_To_True_If_It_Is_False ()
  1354. {
  1355. Assert.True (_textView.AllowsReturn);
  1356. Assert.True (_textView.Multiline);
  1357. Assert.Equal (4, _textView.TabWidth);
  1358. Assert.True (_textView.AllowsTab);
  1359. _textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1360. Assert.Equal (Environment.NewLine +
  1361. "TAB to jump between text fields.", _textView.Text);
  1362. _textView.AllowsReturn = false;
  1363. Assert.False (_textView.AllowsReturn);
  1364. Assert.False (_textView.Multiline);
  1365. Assert.Equal (0, _textView.TabWidth);
  1366. Assert.False (_textView.AllowsTab);
  1367. _textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1368. Assert.Equal (Environment.NewLine +
  1369. "TAB to jump between text fields.", _textView.Text);
  1370. }
  1371. [Fact][InitShutdown]
  1372. public void Multiline_Setting_Changes_AllowsReturn_And_AllowsTab_And_Height ()
  1373. {
  1374. Assert.True (_textView.Multiline);
  1375. Assert.True (_textView.AllowsReturn);
  1376. Assert.Equal (4, _textView.TabWidth);
  1377. Assert.True (_textView.AllowsTab);
  1378. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1379. Assert.Equal ("Dim.Absolute(10)", _textView.Height.ToString ());
  1380. _textView.Multiline = false;
  1381. Assert.False (_textView.Multiline);
  1382. Assert.False (_textView.AllowsReturn);
  1383. Assert.Equal (0, _textView.TabWidth);
  1384. Assert.False (_textView.AllowsTab);
  1385. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1386. Assert.Equal ("Dim.Absolute(1)", _textView.Height.ToString ());
  1387. _textView.Multiline = true;
  1388. Assert.True (_textView.Multiline);
  1389. Assert.True (_textView.AllowsReturn);
  1390. Assert.Equal (4, _textView.TabWidth);
  1391. Assert.True (_textView.AllowsTab);
  1392. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1393. Assert.Equal ("Dim.Absolute(10)", _textView.Height.ToString ());
  1394. }
  1395. [Fact][InitShutdown]
  1396. public void Tab_Test_Follow_By_BackTab ()
  1397. {
  1398. Application.Top.Add (_textView);
  1399. Application.Iteration += () => {
  1400. var width = _textView.Bounds.Width - 1;
  1401. Assert.Equal (30, width + 1);
  1402. Assert.Equal (10, _textView.Height);
  1403. _textView.Text = "";
  1404. var col = 0;
  1405. var leftCol = 0;
  1406. var tabWidth = _textView.TabWidth;
  1407. while (col < 100) {
  1408. col++;
  1409. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1410. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1411. leftCol = GetLeftCol (leftCol);
  1412. Assert.Equal (leftCol, _textView.LeftColumn);
  1413. }
  1414. while (col > 0) {
  1415. col--;
  1416. _textView.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ()));
  1417. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1418. leftCol = GetLeftCol (leftCol);
  1419. Assert.Equal (leftCol, _textView.LeftColumn);
  1420. }
  1421. Application.Top.Remove (_textView);
  1422. Application.RequestStop ();
  1423. };
  1424. Application.Run ();
  1425. }
  1426. [Fact][InitShutdown]
  1427. public void BackTab_Test_Follow_By_Tab ()
  1428. {
  1429. Application.Top.Add (_textView);
  1430. Application.Iteration += () => {
  1431. var width = _textView.Bounds.Width - 1;
  1432. Assert.Equal (30, width + 1);
  1433. Assert.Equal (10, _textView.Height);
  1434. _textView.Text = "";
  1435. for (int i = 0; i < 100; i++) {
  1436. _textView.Text += "\t";
  1437. }
  1438. var col = 100;
  1439. var tabWidth = _textView.TabWidth;
  1440. var leftCol = _textView.LeftColumn;
  1441. _textView.MoveEnd ();
  1442. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1443. leftCol = GetLeftCol (leftCol);
  1444. Assert.Equal (leftCol, _textView.LeftColumn);
  1445. while (col > 0) {
  1446. col--;
  1447. _textView.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ()));
  1448. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1449. leftCol = GetLeftCol (leftCol);
  1450. Assert.Equal (leftCol, _textView.LeftColumn);
  1451. }
  1452. while (col < 100) {
  1453. col++;
  1454. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1455. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1456. leftCol = GetLeftCol (leftCol);
  1457. Assert.Equal (leftCol, _textView.LeftColumn);
  1458. }
  1459. Application.Top.Remove (_textView);
  1460. Application.RequestStop ();
  1461. };
  1462. Application.Run ();
  1463. }
  1464. [Fact][InitShutdown]
  1465. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight ()
  1466. {
  1467. Application.Top.Add (_textView);
  1468. Application.Iteration += () => {
  1469. var width = _textView.Bounds.Width - 1;
  1470. Assert.Equal (30, width + 1);
  1471. Assert.Equal (10, _textView.Height);
  1472. _textView.Text = "";
  1473. var col = 0;
  1474. var leftCol = 0;
  1475. var tabWidth = _textView.TabWidth;
  1476. while (col < 100) {
  1477. col++;
  1478. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1479. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1480. leftCol = GetLeftCol (leftCol);
  1481. Assert.Equal (leftCol, _textView.LeftColumn);
  1482. }
  1483. while (col > 0) {
  1484. col--;
  1485. _textView.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  1486. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1487. leftCol = GetLeftCol (leftCol);
  1488. Assert.Equal (leftCol, _textView.LeftColumn);
  1489. }
  1490. while (col < 100) {
  1491. col++;
  1492. _textView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  1493. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1494. leftCol = GetLeftCol (leftCol);
  1495. Assert.Equal (leftCol, _textView.LeftColumn);
  1496. }
  1497. Application.Top.Remove (_textView);
  1498. Application.RequestStop ();
  1499. };
  1500. Application.Run ();
  1501. }
  1502. [Fact][InitShutdown]
  1503. public void Tab_Test_Follow_By_BackTab_With_Text ()
  1504. {
  1505. Application.Top.Add (_textView);
  1506. Application.Iteration += () => {
  1507. var width = _textView.Bounds.Width - 1;
  1508. Assert.Equal (30, width + 1);
  1509. Assert.Equal (10, _textView.Height);
  1510. var col = 0;
  1511. var leftCol = 0;
  1512. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1513. Assert.Equal (leftCol, _textView.LeftColumn);
  1514. while (col < 100) {
  1515. col++;
  1516. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1517. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1518. leftCol = GetLeftCol (leftCol);
  1519. Assert.Equal (leftCol, _textView.LeftColumn);
  1520. }
  1521. while (col > 0) {
  1522. col--;
  1523. _textView.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ()));
  1524. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1525. leftCol = GetLeftCol (leftCol);
  1526. Assert.Equal (leftCol, _textView.LeftColumn);
  1527. }
  1528. Application.Top.Remove (_textView);
  1529. Application.RequestStop ();
  1530. };
  1531. Application.Run ();
  1532. }
  1533. [Fact][InitShutdown]
  1534. public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_BackTab_With_Text ()
  1535. {
  1536. Application.Top.Add (_textView);
  1537. Application.Iteration += () => {
  1538. var width = _textView.Bounds.Width - 1;
  1539. Assert.Equal (30, width + 1);
  1540. Assert.Equal (10, _textView.Height);
  1541. var col = 0;
  1542. var leftCol = 0;
  1543. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1544. Assert.Equal (leftCol, _textView.LeftColumn);
  1545. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1546. Assert.Equal (32, _textView.Text.Length);
  1547. while (col < 100) {
  1548. col++;
  1549. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1550. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1551. leftCol = GetLeftCol (leftCol);
  1552. Assert.Equal (leftCol, _textView.LeftColumn);
  1553. }
  1554. _textView.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()));
  1555. col = 0;
  1556. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1557. leftCol = 0;
  1558. Assert.Equal (leftCol, _textView.LeftColumn);
  1559. _textView.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()));
  1560. col = _textView.Text.Length;
  1561. Assert.Equal (132, _textView.Text.Length);
  1562. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1563. leftCol = GetLeftCol (leftCol);
  1564. Assert.Equal (leftCol, _textView.LeftColumn);
  1565. var txt = _textView.Text;
  1566. while (col - 1 > 0 && txt [col - 1] != '\t') {
  1567. col--;
  1568. }
  1569. _textView.CursorPosition = new Point (col, 0);
  1570. leftCol = GetLeftCol (leftCol);
  1571. while (col > 0) {
  1572. col--;
  1573. _textView.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ()));
  1574. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1575. leftCol = GetLeftCol (leftCol);
  1576. Assert.Equal (leftCol, _textView.LeftColumn);
  1577. }
  1578. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1579. Assert.Equal (32, _textView.Text.Length);
  1580. Application.Top.Remove (_textView);
  1581. Application.RequestStop ();
  1582. };
  1583. Application.Run ();
  1584. }
  1585. [Fact][InitShutdown]
  1586. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Text ()
  1587. {
  1588. Application.Top.Add (_textView);
  1589. Application.Iteration += () => {
  1590. var width = _textView.Bounds.Width - 1;
  1591. Assert.Equal (30, width + 1);
  1592. Assert.Equal (10, _textView.Height);
  1593. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1594. var col = 0;
  1595. var leftCol = 0;
  1596. var tabWidth = _textView.TabWidth;
  1597. while (col < 100) {
  1598. col++;
  1599. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1600. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1601. leftCol = GetLeftCol (leftCol);
  1602. Assert.Equal (leftCol, _textView.LeftColumn);
  1603. }
  1604. Assert.Equal (132, _textView.Text.Length);
  1605. while (col > 0) {
  1606. col--;
  1607. _textView.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  1608. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1609. leftCol = GetLeftCol (leftCol);
  1610. Assert.Equal (leftCol, _textView.LeftColumn);
  1611. }
  1612. while (col < 100) {
  1613. col++;
  1614. _textView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  1615. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1616. leftCol = GetLeftCol (leftCol);
  1617. Assert.Equal (leftCol, _textView.LeftColumn);
  1618. }
  1619. Application.Top.Remove (_textView);
  1620. Application.RequestStop ();
  1621. };
  1622. Application.Run ();
  1623. }
  1624. private int GetLeftCol (int start)
  1625. {
  1626. var lines = _textView.Text.Split (Environment.NewLine);
  1627. if (lines == null || lines.Length == 0) {
  1628. return 0;
  1629. }
  1630. if (start == _textView.LeftColumn) {
  1631. return start;
  1632. }
  1633. if (_textView.LeftColumn == _textView.CurrentColumn) {
  1634. return _textView.CurrentColumn;
  1635. }
  1636. var cCol = _textView.CurrentColumn;
  1637. var line = lines [_textView.CurrentRow];
  1638. var lCount = cCol > line.Length - 1 ? line.Length - 1 : cCol;
  1639. var width = _textView.Frame.Width;
  1640. var tabWidth = _textView.TabWidth;
  1641. var sumLength = 0;
  1642. var col = 0;
  1643. for (int i = lCount; i >= 0; i--) {
  1644. var r = line [i];
  1645. sumLength += Rune.ColumnWidth (r);
  1646. if (r == '\t') {
  1647. sumLength += tabWidth + 1;
  1648. }
  1649. if (sumLength > width) {
  1650. if (cCol == line.Length) {
  1651. col++;
  1652. }
  1653. break;
  1654. } else if (cCol < line.Length && col > 0 && start < cCol && col == start) {
  1655. break;
  1656. }
  1657. col = i;
  1658. }
  1659. return col;
  1660. }
  1661. }
  1662. }