TextViewTests.cs 74 KB

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