TextViewTests.cs 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024
  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. if (cCol == line.Length) {
  1709. col++;
  1710. }
  1711. break;
  1712. } else if (cCol < line.Length && col > 0 && start < cCol && col == start) {
  1713. break;
  1714. }
  1715. col = i;
  1716. }
  1717. return col;
  1718. }
  1719. [Fact]
  1720. public void LoadFile_Throws_If_File_Is_Null ()
  1721. {
  1722. var tv = new TextView ();
  1723. Assert.Throws<ArgumentNullException> (() => tv.LoadFile (null));
  1724. }
  1725. [Fact]
  1726. public void LoadFile_Throws_If_File_Is_Empty ()
  1727. {
  1728. var tv = new TextView ();
  1729. Assert.Throws<ArgumentException> (() => tv.LoadFile (""));
  1730. }
  1731. [Fact]
  1732. public void LoadFile_Throws_If_File_Not_Exist ()
  1733. {
  1734. var tv = new TextView ();
  1735. Assert.Throws<System.IO.FileNotFoundException> (() => tv.LoadFile ("blabla"));
  1736. }
  1737. [Fact]
  1738. public void LoadStream_Throws_If_Stream_Is_Null ()
  1739. {
  1740. var tv = new TextView ();
  1741. Assert.Throws<ArgumentNullException> (() => tv.LoadStream (null));
  1742. }
  1743. [Fact]
  1744. public void LoadStream_Stream_Is_Empty ()
  1745. {
  1746. var tv = new TextView ();
  1747. tv.LoadStream (new System.IO.MemoryStream ());
  1748. Assert.Equal ("", tv.Text);
  1749. }
  1750. [Fact]
  1751. public void LoadStream_CRLF ()
  1752. {
  1753. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1754. var tv = new TextView ();
  1755. tv.LoadStream (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  1756. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1757. }
  1758. [Fact]
  1759. public void LoadStream_LF ()
  1760. {
  1761. var text = "This is the first line.\nThis is the second line.\n";
  1762. var tv = new TextView ();
  1763. tv.LoadStream (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  1764. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1765. }
  1766. [Fact]
  1767. public void StringToRunes_Slipts_CRLF ()
  1768. {
  1769. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1770. var tv = new TextView ();
  1771. tv.Text = text;
  1772. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1773. }
  1774. [Fact]
  1775. public void StringToRunes_Slipts_LF ()
  1776. {
  1777. var text = "This is the first line.\nThis is the second line.\n";
  1778. var tv = new TextView ();
  1779. tv.Text = text;
  1780. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1781. }
  1782. [Fact]
  1783. public void CloseFile_Throws_If_FilePath_Is_Null ()
  1784. {
  1785. var tv = new TextView ();
  1786. Assert.Throws<ArgumentNullException> (() => tv.CloseFile ());
  1787. }
  1788. [Fact]
  1789. public void WordWrap_Gets_Sets ()
  1790. {
  1791. var tv = new TextView () { WordWrap = true };
  1792. Assert.True (tv.WordWrap);
  1793. tv.WordWrap = false;
  1794. Assert.False (tv.WordWrap);
  1795. }
  1796. [Fact]
  1797. public void WordWrap_True_Text_Always_Returns_Unwrapped ()
  1798. {
  1799. var text = "This is the first line.\nThis is the second line.\n";
  1800. var tv = new TextView () { Width = 10 };
  1801. tv.Text = text;
  1802. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1803. tv.WordWrap = true;
  1804. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1805. }
  1806. [Fact]
  1807. [InitShutdown]
  1808. public void WordWrap_WrapModel_Output ()
  1809. {
  1810. // 0123456789
  1811. var text = "This is the first line.\nThis is the second line.\n";
  1812. var tv = new TextView () { Width = 10, Height = 10 };
  1813. tv.Text = text;
  1814. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1815. tv.WordWrap = true;
  1816. Application.Top.Add (tv);
  1817. tv.Redraw (tv.Bounds);
  1818. string expected = @"
  1819. This is
  1820. the
  1821. first
  1822. line.
  1823. This is
  1824. the
  1825. second
  1826. line.
  1827. ";
  1828. GraphViewTests.AssertDriverContentsAre (expected, output);
  1829. }
  1830. [Fact]
  1831. public void Internal_Tests ()
  1832. {
  1833. var txt = "This is a text.";
  1834. var txtRunes = TextModel.ToRunes (txt);
  1835. Assert.Equal (txt.Length, txtRunes.Count);
  1836. Assert.Equal ('T', txtRunes [0]);
  1837. Assert.Equal ('h', txtRunes [1]);
  1838. Assert.Equal ('i', txtRunes [2]);
  1839. Assert.Equal ('s', txtRunes [3]);
  1840. Assert.Equal (' ', txtRunes [4]);
  1841. Assert.Equal ('i', txtRunes [5]);
  1842. Assert.Equal ('s', txtRunes [6]);
  1843. Assert.Equal (' ', txtRunes [7]);
  1844. Assert.Equal ('a', txtRunes [8]);
  1845. Assert.Equal (' ', txtRunes [9]);
  1846. Assert.Equal ('t', txtRunes [10]);
  1847. Assert.Equal ('e', txtRunes [11]);
  1848. Assert.Equal ('x', txtRunes [12]);
  1849. Assert.Equal ('t', txtRunes [13]);
  1850. Assert.Equal ('.', txtRunes [^1]);
  1851. int col = 0;
  1852. Assert.True (TextModel.SetCol (ref col, 80, 79));
  1853. Assert.False (TextModel.SetCol (ref col, 80, 80));
  1854. var start = 0;
  1855. var x = 8;
  1856. Assert.Equal (8, TextModel.GetColFromX (txtRunes, start, x));
  1857. Assert.Equal ('a', txtRunes [start + x]);
  1858. start = 1;
  1859. x = 7;
  1860. Assert.Equal (7, TextModel.GetColFromX (txtRunes, start, x));
  1861. Assert.Equal ('a', txtRunes [start + x]);
  1862. Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
  1863. Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
  1864. Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
  1865. Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
  1866. Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
  1867. var tm = new TextModel ();
  1868. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  1869. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  1870. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn));
  1871. Assert.False (gaveFullTurn);
  1872. Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  1873. Assert.False (gaveFullTurn);
  1874. Assert.Equal ((new Point (2, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  1875. Assert.False (gaveFullTurn);
  1876. Assert.Equal ((new Point (5, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  1877. Assert.False (gaveFullTurn);
  1878. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  1879. Assert.True (gaveFullTurn);
  1880. tm.ResetContinuousFind (new Point (0, 0));
  1881. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  1882. Assert.False (gaveFullTurn);
  1883. Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  1884. Assert.False (gaveFullTurn);
  1885. Assert.Equal ((new Point (5, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  1886. Assert.False (gaveFullTurn);
  1887. Assert.Equal ((new Point (2, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  1888. Assert.False (gaveFullTurn);
  1889. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  1890. Assert.True (gaveFullTurn);
  1891. Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really"));
  1892. Assert.Equal (TextModel.ToRunes ("Threally really first line."), tm.GetLine (0));
  1893. Assert.Equal (TextModel.ToRunes ("Threally really last line."), tm.GetLine (1));
  1894. tm = new TextModel ();
  1895. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  1896. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  1897. Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really"));
  1898. Assert.Equal (TextModel.ToRunes ("This really first line."), tm.GetLine (0));
  1899. Assert.Equal (TextModel.ToRunes ("This really last line."), tm.GetLine (1));
  1900. }
  1901. }
  1902. }