TextFieldTests.cs 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. using System.Globalization;
  2. using System.Reflection;
  3. using System.Text;
  4. using UnitTests;
  5. using Xunit.Abstractions;
  6. namespace UnitTests.ViewsTests;
  7. public class TextFieldTests (ITestOutputHelper output)
  8. {
  9. private static TextField _textField;
  10. [Fact]
  11. [TextFieldTestsAutoInitShutdown]
  12. public void CanFocus_False_Wont_Focus_With_Mouse ()
  13. {
  14. Runnable top = new ();
  15. var tf = new TextField { Width = Dim.Fill (), CanFocus = false, ReadOnly = true, Text = "some text" };
  16. var fv = new FrameView
  17. {
  18. Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = false, Title = "I shouldn't get focus"
  19. };
  20. fv.Add (tf);
  21. top.Add (fv);
  22. Application.Begin (top);
  23. Assert.False (tf.CanFocus);
  24. Assert.False (tf.HasFocus);
  25. Assert.False (fv.CanFocus);
  26. Assert.False (fv.HasFocus);
  27. tf.NewMouseEvent (
  28. new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }
  29. );
  30. Assert.Null (tf.SelectedText);
  31. Assert.False (tf.CanFocus);
  32. Assert.False (tf.HasFocus);
  33. Assert.False (fv.CanFocus);
  34. Assert.False (fv.HasFocus);
  35. fv.CanFocus = true;
  36. tf.CanFocus = true;
  37. tf.NewMouseEvent (
  38. new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }
  39. );
  40. Assert.Equal ("some ", tf.SelectedText);
  41. Assert.True (tf.CanFocus);
  42. Assert.True (tf.HasFocus);
  43. Assert.True (fv.CanFocus);
  44. Assert.True (fv.HasFocus);
  45. fv.CanFocus = false;
  46. tf.NewMouseEvent (
  47. new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }
  48. );
  49. Assert.Equal ("some ", tf.SelectedText); // Setting CanFocus to false don't change the SelectedText
  50. Assert.True (tf.CanFocus); // v2: CanFocus is not longer automatically changed
  51. Assert.False (tf.HasFocus);
  52. Assert.False (fv.CanFocus);
  53. Assert.False (fv.HasFocus);
  54. top.Dispose ();
  55. }
  56. [Theory]
  57. [AutoInitShutdown]
  58. [InlineData ("0123456789", "0123456789")]
  59. [InlineData ("01234567890", "0123456789")]
  60. public void CaptionedTextField_DoesNotOverspillBounds (string caption, string expectedRender)
  61. {
  62. TextField tf = GetTextFieldsInView ();
  63. // Caption has no effect when focused
  64. tf.Title = caption;
  65. Application.RaiseKeyDownEvent ('\t');
  66. Assert.False (tf.HasFocus);
  67. tf.Draw ();
  68. DriverAssert.AssertDriverContentsAre (expectedRender, output);
  69. Application.TopRunnableView.Dispose ();
  70. }
  71. [Fact]
  72. [AutoInitShutdown]
  73. public void CaptionedTextField_DoesNotOverspillViewport_Unicode ()
  74. {
  75. string caption = "Mise" + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) + "rables";
  76. Assert.Equal (11, caption.Length);
  77. Assert.Equal (10, caption.EnumerateRunes ().Sum (c => c.GetColumns ()));
  78. Assert.Equal (10, caption.GetColumns ());
  79. TextField tf = GetTextFieldsInView ();
  80. tf.Title = caption;
  81. Application.RaiseKeyDownEvent ('\t');
  82. Assert.False (tf.HasFocus);
  83. tf.Draw ();
  84. DriverAssert.AssertDriverContentsAre ("Misérables", output);
  85. Application.TopRunnableView.Dispose ();
  86. }
  87. [Theory (Skip = "Broke with ContextMenuv2")]
  88. [AutoInitShutdown]
  89. [InlineData ("blah")]
  90. [InlineData (" ")]
  91. public void CaptionedTextField_DoNotRenderCaption_WhenTextPresent (string content)
  92. {
  93. TextField tf = GetTextFieldsInView ();
  94. tf.Draw ();
  95. DriverAssert.AssertDriverContentsAre ("", output);
  96. tf.Title = "Enter txt";
  97. Application.RaiseKeyDownEvent ('\t');
  98. // Caption should appear when not focused and no text
  99. Assert.False (tf.HasFocus);
  100. tf.SetClipToScreen ();
  101. tf.Draw ();
  102. DriverAssert.AssertDriverContentsAre ("Enter txt", output);
  103. // but disapear when text is added
  104. tf.Text = content;
  105. tf.SetClipToScreen ();
  106. tf.Draw ();
  107. DriverAssert.AssertDriverContentsAre (content, output);
  108. Application.TopRunnableView.Dispose ();
  109. }
  110. [Fact]
  111. [AutoInitShutdown]
  112. public void CaptionedTextField_RendersCaption_WhenNotFocused ()
  113. {
  114. TextField tf = GetTextFieldsInView ();
  115. tf.Draw ();
  116. DriverAssert.AssertDriverContentsAre ("", output);
  117. // Caption has no effect when focused
  118. tf.Title = "Enter txt";
  119. Assert.True (tf.HasFocus);
  120. tf.SetClipToScreen ();
  121. tf.Draw ();
  122. DriverAssert.AssertDriverContentsAre ("", output);
  123. Application.RaiseKeyDownEvent ('\t');
  124. Assert.False (tf.HasFocus);
  125. tf.SetClipToScreen ();
  126. tf.Draw ();
  127. DriverAssert.AssertDriverContentsAre ("Enter txt", output);
  128. Application.TopRunnableView.Dispose ();
  129. }
  130. [Fact]
  131. [AutoInitShutdown]
  132. public void Title_RendersAsCaption_WithCorrectAttributes ()
  133. {
  134. TextField tf = GetTextFieldsInView ();
  135. // Set a title (caption)
  136. tf.Title = "Enter text";
  137. // Remove focus so caption appears
  138. Application.RaiseKeyDownEvent ('\t');
  139. Assert.False (tf.HasFocus);
  140. tf.SetClipToScreen ();
  141. tf.Draw ();
  142. // Verify the caption text is rendered
  143. DriverAssert.AssertDriverContentsAre ("Enter text", output);
  144. // Verify the caption uses dimmed color attribute
  145. Attribute captionAttr = new Attribute (
  146. tf.GetAttributeForRole (VisualRole.Editable).Foreground.GetDimColor (),
  147. tf.GetAttributeForRole (VisualRole.Editable).Background);
  148. // All characters in "Enter text" should have the caption attribute
  149. DriverAssert.AssertDriverAttributesAre ("0000000000", output, Application.Driver, captionAttr);
  150. Application.TopRunnableView.Dispose ();
  151. }
  152. [Fact]
  153. [AutoInitShutdown]
  154. public void Title_WithHotkey_RendersUnderlined ()
  155. {
  156. TextField tf = GetTextFieldsInView ();
  157. // Title with hotkey should be rendered with the hotkey underlined when not focused
  158. tf.Title = "_Find";
  159. // Remove focus so caption appears
  160. Application.RaiseKeyDownEvent ('\t');
  161. Assert.False (tf.HasFocus);
  162. tf.SetClipToScreen ();
  163. tf.Draw ();
  164. // The hotkey character 'F' should be rendered (without the underscore in the actual text)
  165. DriverAssert.AssertDriverContentsAre ("Find", output);
  166. // Verify the hotkey character 'F' has underline style
  167. Attribute captionAttr = new Attribute (
  168. tf.GetAttributeForRole (VisualRole.Editable).Foreground.GetDimColor (),
  169. tf.GetAttributeForRole (VisualRole.Editable).Background);
  170. Attribute hotkeyAttr = new Attribute (
  171. tf.GetAttributeForRole (VisualRole.Editable).Foreground.GetDimColor (),
  172. tf.GetAttributeForRole (VisualRole.Editable).Background,
  173. tf.GetAttributeForRole (VisualRole.Editable).Style | TextStyle.Underline);
  174. // F is underlined (index 1), remaining characters use normal caption attribute (index 0)
  175. DriverAssert.AssertDriverAttributesAre ("1000", output, Application.Driver, captionAttr, hotkeyAttr);
  176. Application.TopRunnableView.Dispose ();
  177. }
  178. [Fact]
  179. [AutoInitShutdown]
  180. public void Title_WithHotkey_MiddleCharacter_RendersUnderlined ()
  181. {
  182. TextField tf = GetTextFieldsInView ();
  183. // Title with hotkey in middle of text
  184. tf.Title = "Enter _Text";
  185. // Remove focus so caption appears
  186. Application.RaiseKeyDownEvent ('\t');
  187. Assert.False (tf.HasFocus);
  188. tf.SetClipToScreen ();
  189. tf.Draw ();
  190. // The underscore should not be rendered, 'T' should be underlined
  191. DriverAssert.AssertDriverContentsAre ("Enter Text", output);
  192. // Verify the hotkey character 'T' has underline style
  193. Attribute captionAttr = new Attribute (
  194. tf.GetAttributeForRole (VisualRole.Editable).Foreground.GetDimColor (),
  195. tf.GetAttributeForRole (VisualRole.Editable).Background);
  196. Attribute hotkeyAttr = new Attribute (
  197. tf.GetAttributeForRole (VisualRole.Editable).Foreground.GetDimColor (),
  198. tf.GetAttributeForRole (VisualRole.Editable).Background,
  199. tf.GetAttributeForRole (VisualRole.Editable).Style | TextStyle.Underline);
  200. // "Enter " (6 chars) + "T" (underlined) + "ext" (3 chars)
  201. DriverAssert.AssertDriverAttributesAre ("0000001000", output, Application.Driver, captionAttr, hotkeyAttr);
  202. Application.TopRunnableView.Dispose ();
  203. }
  204. [Fact]
  205. [TextFieldTestsAutoInitShutdown]
  206. public void Changing_SelectedStart_Or_CursorPosition_Update_SelectedLength_And_SelectedText ()
  207. {
  208. _textField.BeginInit ();
  209. _textField.EndInit ();
  210. _textField.SelectedStart = 2;
  211. Assert.Equal (32, _textField.CursorPosition);
  212. Assert.Equal (30, _textField.SelectedLength);
  213. Assert.Equal ("B to jump between text fields.", _textField.SelectedText);
  214. _textField.CursorPosition = 20;
  215. Assert.Equal (2, _textField.SelectedStart);
  216. Assert.Equal (18, _textField.SelectedLength);
  217. Assert.Equal ("B to jump between ", _textField.SelectedText);
  218. }
  219. [Fact]
  220. [TextFieldTestsAutoInitShutdown]
  221. public void Copy_Or_Cut__Not_Allowed_If_Secret_Is_True ()
  222. {
  223. _textField.Secret = true;
  224. _textField.SelectedStart = 20;
  225. _textField.CursorPosition = 24;
  226. _textField.Copy ();
  227. Assert.Null (_textField.SelectedText);
  228. _textField.Cut ();
  229. Assert.Null (_textField.SelectedText);
  230. _textField.Secret = false;
  231. _textField.Copy ();
  232. Assert.Equal ("text", _textField.SelectedText);
  233. _textField.Cut ();
  234. Assert.Null (_textField.SelectedText);
  235. }
  236. [Fact]
  237. [TextFieldTestsAutoInitShutdown]
  238. public void Copy_Or_Cut_And_Paste_With_No_Selection ()
  239. {
  240. _textField.SelectedStart = 20;
  241. _textField.CursorPosition = 24;
  242. _textField.Copy ();
  243. Assert.Equal ("text", _textField.SelectedText);
  244. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  245. _textField.SelectedStart = -1;
  246. _textField.Paste ();
  247. Assert.Equal ("TAB to jump between texttext fields.", _textField.Text);
  248. _textField.SelectedStart = 24;
  249. _textField.Cut ();
  250. Assert.Null (_textField.SelectedText);
  251. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  252. _textField.SelectedStart = -1;
  253. _textField.Paste ();
  254. Assert.Equal ("TAB to jump between texttext fields.", _textField.Text);
  255. }
  256. [Fact]
  257. [TextFieldTestsAutoInitShutdown]
  258. public void Copy_Or_Cut_And_Paste_With_Selection ()
  259. {
  260. _textField.SelectedStart = 20;
  261. _textField.CursorPosition = 24;
  262. _textField.Copy ();
  263. Assert.Equal ("text", _textField.SelectedText);
  264. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  265. _textField.Paste ();
  266. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  267. _textField.SelectedStart = 20;
  268. _textField.Cut ();
  269. _textField.Paste ();
  270. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  271. }
  272. [Fact]
  273. [TextFieldTestsAutoInitShutdown]
  274. public void Copy_Or_Cut_Not_Null_If_Has_Selection ()
  275. {
  276. _textField.SelectedStart = 20;
  277. _textField.CursorPosition = 24;
  278. _textField.Copy ();
  279. Assert.Equal ("text", _textField.SelectedText);
  280. _textField.Cut ();
  281. Assert.Null (_textField.SelectedText);
  282. }
  283. [Fact]
  284. [TextFieldTestsAutoInitShutdown]
  285. public void Copy_Or_Cut_Null_If_No_Selection ()
  286. {
  287. _textField.SelectedStart = -1;
  288. _textField.Copy ();
  289. Assert.Null (_textField.SelectedText);
  290. _textField.Cut ();
  291. Assert.Null (_textField.SelectedText);
  292. }
  293. [Fact]
  294. [TextFieldTestsAutoInitShutdown]
  295. public void Copy_Paste_Surrogate_Pairs ()
  296. {
  297. _textField.Text = "TextField with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!";
  298. _textField.SelectAll ();
  299. _textField.Cut ();
  300. Assert.Equal (
  301. "TextField with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!",
  302. Application.Driver?.Clipboard!.GetClipboardData ()
  303. );
  304. Assert.Equal (string.Empty, _textField.Text);
  305. _textField.Paste ();
  306. Assert.Equal ("TextField with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!", _textField.Text);
  307. }
  308. [Fact]
  309. [TextFieldTestsAutoInitShutdown]
  310. public void Copy_Paste_Text_Changing_Updates_Cursor_Position ()
  311. {
  312. _textField.BeginInit ();
  313. _textField.EndInit ();
  314. _textField.TextChanging += TextFieldTextChanging;
  315. void TextFieldTextChanging (object sender, ResultEventArgs<string> e)
  316. {
  317. if (e.Result.GetRuneCount () > 11)
  318. {
  319. e.Result = e.Result [..11];
  320. }
  321. }
  322. Assert.Equal (32, _textField.CursorPosition);
  323. _textField.SelectAll ();
  324. _textField.Cut ();
  325. Assert.Equal ("TAB to jump between text fields.", Application.Driver?.Clipboard!.GetClipboardData ());
  326. Assert.Equal (string.Empty, _textField.Text);
  327. Assert.Equal (0, _textField.CursorPosition);
  328. _textField.Paste ();
  329. Assert.Equal ("TAB to jump", _textField.Text);
  330. Assert.Equal (11, _textField.CursorPosition);
  331. _textField.TextChanging -= TextFieldTextChanging;
  332. }
  333. [Fact]
  334. [TextFieldTestsAutoInitShutdown]
  335. public void Cursor_Position_Initialization ()
  336. {
  337. Assert.False (_textField.IsInitialized);
  338. // BUGBUG: IsInitialized is false and
  339. // CursorPosition wasn't calculated yet
  340. Assert.Equal (0, _textField.CursorPosition);
  341. _textField.BeginInit ();
  342. _textField.EndInit ();
  343. Assert.Equal (32, _textField.CursorPosition);
  344. Assert.Equal (0, _textField.SelectedLength);
  345. Assert.Null (_textField.SelectedText);
  346. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  347. }
  348. [Fact]
  349. [TextFieldTestsAutoInitShutdown]
  350. public void CursorPosition_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  351. {
  352. _textField.CursorPosition = 33;
  353. Assert.Equal (32, _textField.CursorPosition);
  354. Assert.Equal (0, _textField.SelectedLength);
  355. Assert.Null (_textField.SelectedText);
  356. }
  357. [Fact]
  358. [TextFieldTestsAutoInitShutdown]
  359. public void CursorPosition_With_Value_Less_Than_Zero_Changes_To_Zero ()
  360. {
  361. _textField.CursorPosition = -1;
  362. Assert.Equal (0, _textField.CursorPosition);
  363. Assert.Equal (0, _textField.SelectedLength);
  364. Assert.Null (_textField.SelectedText);
  365. }
  366. [Fact]
  367. [AutoInitShutdown]
  368. public void DeleteSelectedText_InsertText_DeleteCharLeft_DeleteCharRight_Cut ()
  369. {
  370. var newText = "";
  371. var oldText = "";
  372. var tf = new TextField { Width = 10, Text = "-1" };
  373. tf.TextChanging += (s, e) =>
  374. {
  375. newText = e.Result;
  376. oldText = tf.Text;
  377. };
  378. var top = new Runnable ();
  379. top.Add (tf);
  380. Application.Begin (top);
  381. Assert.Equal ("-1", tf.Text);
  382. // InsertText
  383. tf.SelectedStart = 1;
  384. tf.CursorPosition = 2;
  385. Assert.Equal (1, tf.SelectedLength);
  386. Assert.Equal ("1", tf.SelectedText);
  387. Assert.True (tf.NewKeyDownEvent (Key.D2));
  388. Assert.Equal ("-2", newText);
  389. Assert.Equal ("-1", oldText);
  390. Assert.Equal ("-2", tf.Text);
  391. // DeleteCharLeft
  392. tf.SelectedStart = 1;
  393. tf.CursorPosition = 2;
  394. Assert.Equal (1, tf.SelectedLength);
  395. Assert.Equal ("2", tf.SelectedText);
  396. Assert.True (tf.NewKeyDownEvent (Key.Backspace));
  397. Assert.Equal ("-", newText);
  398. Assert.Equal ("-2", oldText);
  399. Assert.Equal ("-", tf.Text);
  400. // DeleteCharRight
  401. tf.Text = "-1";
  402. tf.SelectedStart = 1;
  403. tf.CursorPosition = 2;
  404. Assert.Equal (1, tf.SelectedLength);
  405. Assert.Equal ("1", tf.SelectedText);
  406. Assert.True (tf.NewKeyDownEvent (Key.Delete));
  407. Assert.Equal ("-", newText);
  408. Assert.Equal ("-1", oldText);
  409. Assert.Equal ("-", tf.Text);
  410. // Cut
  411. tf.Text = "-1";
  412. tf.SelectedStart = 1;
  413. tf.CursorPosition = 2;
  414. Assert.Equal (1, tf.SelectedLength);
  415. Assert.Equal ("1", tf.SelectedText);
  416. Assert.True (tf.NewKeyDownEvent (Key.X.WithCtrl));
  417. Assert.Equal ("-", newText);
  418. Assert.Equal ("-1", oldText);
  419. Assert.Equal ("-", tf.Text);
  420. // Delete word with accented char
  421. tf.Text = "Les Misérables movie.";
  422. Assert.True (
  423. tf.NewMouseEvent (
  424. new () { Position = new (7, 1), Flags = MouseFlags.Button1DoubleClicked, View = tf }
  425. )
  426. );
  427. Assert.Equal ("Misérables ", tf.SelectedText);
  428. Assert.Equal (11, tf.SelectedLength);
  429. Assert.True (tf.NewKeyDownEvent (Key.Delete));
  430. Assert.Equal ("Les movie.", newText);
  431. Assert.Equal ("Les Misérables movie.", oldText);
  432. Assert.Equal ("Les movie.", tf.Text);
  433. top.Dispose ();
  434. }
  435. [Fact]
  436. [SetupFakeApplication]
  437. public void KeyBindings_Command ()
  438. {
  439. var tf = new TextField { Width = 20, Text = "This is a test.", App = ApplicationImpl.Instance };
  440. tf.BeginInit ();
  441. tf.EndInit ();
  442. Assert.Equal (15, tf.Text.Length);
  443. Assert.Equal (15, tf.CursorPosition);
  444. Assert.False (tf.ReadOnly);
  445. Assert.True (tf.NewKeyDownEvent (Key.Delete));
  446. Assert.Equal ("This is a test.", tf.Text);
  447. tf.CursorPosition = 0;
  448. Assert.True (tf.NewKeyDownEvent (Key.Delete));
  449. Assert.Equal ("his is a test.", tf.Text);
  450. tf.ReadOnly = true;
  451. Assert.True (tf.NewKeyDownEvent (Key.D.WithCtrl));
  452. Assert.Equal ("his is a test.", tf.Text);
  453. Assert.True (tf.NewKeyDownEvent (Key.Delete));
  454. Assert.Equal ("his is a test.", tf.Text);
  455. tf.ReadOnly = false;
  456. tf.CursorPosition = 1;
  457. Assert.True (tf.NewKeyDownEvent (Key.Backspace));
  458. Assert.Equal ("is is a test.", tf.Text);
  459. tf.CursorPosition = 5;
  460. Assert.True (tf.NewKeyDownEvent (Key.Home.WithShift));
  461. Assert.Equal ("is is a test.", tf.Text);
  462. Assert.Equal ("is is", tf.SelectedText);
  463. tf.CursorPosition = 5;
  464. tf.SelectedStart = -1;
  465. Assert.Null (tf.SelectedText);
  466. Assert.True (tf.NewKeyDownEvent (Key.Home.WithShift.WithCtrl));
  467. Assert.Equal ("is is a test.", tf.Text);
  468. Assert.Equal ("is is", tf.SelectedText);
  469. tf.CursorPosition = 5;
  470. tf.SelectedStart = -1;
  471. Assert.Null (tf.SelectedText);
  472. Assert.True (tf.NewKeyDownEvent (Key.A.WithShift.WithCtrl));
  473. Assert.Equal ("is is a test.", tf.Text);
  474. Assert.Equal ("is is", tf.SelectedText);
  475. tf.CursorPosition = 5;
  476. tf.SelectedStart = -1;
  477. Assert.Null (tf.SelectedText);
  478. Assert.True (tf.NewKeyDownEvent (Key.End.WithShift));
  479. Assert.Equal ("is is a test.", tf.Text);
  480. Assert.Equal (" a test.", tf.SelectedText);
  481. tf.CursorPosition = 5;
  482. tf.SelectedStart = -1;
  483. Assert.Null (tf.SelectedText);
  484. Assert.True (tf.NewKeyDownEvent (Key.End.WithShift.WithCtrl));
  485. Assert.Equal ("is is a test.", tf.Text);
  486. Assert.Equal (" a test.", tf.SelectedText);
  487. tf.CursorPosition = 5;
  488. tf.SelectedStart = -1;
  489. Assert.Null (tf.SelectedText);
  490. Assert.True (tf.NewKeyDownEvent (Key.E.WithShift.WithCtrl));
  491. Assert.Equal ("is is a test.", tf.Text);
  492. Assert.Equal (" a test.", tf.SelectedText);
  493. tf.CursorPosition = 5;
  494. tf.SelectedStart = -1;
  495. Assert.Null (tf.SelectedText);
  496. Assert.True (tf.NewKeyDownEvent (Key.Home));
  497. Assert.Equal ("is is a test.", tf.Text);
  498. Assert.Equal (0, tf.CursorPosition);
  499. tf.CursorPosition = 5;
  500. Assert.Null (tf.SelectedText);
  501. Assert.True (tf.NewKeyDownEvent (Key.Home.WithCtrl));
  502. Assert.Equal ("is is a test.", tf.Text);
  503. Assert.Equal (0, tf.CursorPosition);
  504. tf.CursorPosition = 5;
  505. Assert.Null (tf.SelectedText);
  506. Assert.True (tf.NewKeyDownEvent (Key.A.WithCtrl));
  507. Assert.Equal ("is is a test.", tf.Text);
  508. Assert.Equal (tf.Text.Length, tf.CursorPosition);
  509. tf.CursorPosition = 5;
  510. tf.SelectedStart = -1;
  511. Assert.Null (tf.SelectedText);
  512. Assert.True (tf.NewKeyDownEvent (Key.CursorLeft.WithShift));
  513. Assert.Equal ("is is a test.", tf.Text);
  514. Assert.Equal ("s", tf.SelectedText);
  515. Assert.True (tf.NewKeyDownEvent (Key.CursorUp.WithShift));
  516. Assert.Equal ("is is a test.", tf.Text);
  517. Assert.Equal ("is", tf.SelectedText);
  518. Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithShift));
  519. Assert.Equal ("is is a test.", tf.Text);
  520. Assert.Equal ("s", tf.SelectedText);
  521. Assert.True (tf.NewKeyDownEvent (Key.CursorDown.WithShift));
  522. Assert.Equal ("is is a test.", tf.Text);
  523. Assert.Null (tf.SelectedText);
  524. tf.CursorPosition = 7;
  525. tf.SelectedStart = -1;
  526. Assert.Null (tf.SelectedText);
  527. Assert.True (tf.NewKeyDownEvent (Key.CursorLeft.WithShift.WithCtrl));
  528. Assert.Equal ("is is a test.", tf.Text);
  529. Assert.Equal ("a", tf.SelectedText);
  530. Assert.True (tf.NewKeyDownEvent (Key.CursorUp.WithShift.WithCtrl));
  531. Assert.Equal ("is is a test.", tf.Text);
  532. Assert.Equal ("is a", tf.SelectedText);
  533. #if UNIX_KEY_BINDINGS
  534. Assert.True (tf.NewKeyDownEvent (Key.B.WithShift.WithAlt));
  535. #else
  536. Assert.True (tf.NewKeyDownEvent (Key.CursorUp.WithShift.WithCtrl));
  537. #endif
  538. Assert.Equal ("is is a test.", tf.Text);
  539. Assert.Equal ("is is a", tf.SelectedText);
  540. tf.CursorPosition = 3;
  541. tf.SelectedStart = -1;
  542. Assert.Null (tf.SelectedText);
  543. Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithShift.WithCtrl));
  544. Assert.Equal ("is is a test.", tf.Text);
  545. Assert.Equal ("is ", tf.SelectedText);
  546. Assert.True (tf.NewKeyDownEvent (Key.CursorDown.WithShift.WithCtrl));
  547. Assert.Equal ("is is a test.", tf.Text);
  548. Assert.Equal ("is a ", tf.SelectedText);
  549. #if UNIX_KEY_BINDINGS
  550. Assert.True (tf.NewKeyDownEvent (Key.F.WithShift.WithAlt));
  551. #else
  552. Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithShift.WithCtrl));
  553. #endif
  554. Assert.Equal ("is is a test.", tf.Text);
  555. Assert.Equal ("is a test", tf.SelectedText);
  556. Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithShift.WithCtrl));
  557. Assert.Equal ("is a test.", tf.SelectedText);
  558. Assert.Equal (13, tf.CursorPosition);
  559. Assert.True (tf.NewKeyDownEvent (Key.CursorLeft));
  560. Assert.Equal ("is is a test.", tf.Text);
  561. Assert.Null (tf.SelectedText);
  562. Assert.Equal (12, tf.CursorPosition);
  563. Assert.True (tf.NewKeyDownEvent (Key.CursorLeft));
  564. Assert.Equal ("is is a test.", tf.Text);
  565. Assert.Equal (11, tf.CursorPosition);
  566. Assert.True (tf.NewKeyDownEvent (Key.End));
  567. Assert.Equal ("is is a test.", tf.Text);
  568. Assert.Equal (13, tf.CursorPosition);
  569. tf.CursorPosition = 0;
  570. Assert.True (tf.NewKeyDownEvent (Key.End.WithCtrl));
  571. Assert.Equal ("is is a test.", tf.Text);
  572. Assert.Equal (13, tf.CursorPosition);
  573. tf.CursorPosition = 0;
  574. Assert.True (tf.NewKeyDownEvent (Key.E.WithCtrl));
  575. Assert.Equal ("is is a test.", tf.Text);
  576. Assert.Equal (13, tf.CursorPosition);
  577. tf.CursorPosition = 0;
  578. Assert.True (tf.NewKeyDownEvent (Key.CursorRight));
  579. Assert.Equal ("is is a test.", tf.Text);
  580. Assert.Equal (1, tf.CursorPosition);
  581. Assert.True (tf.NewKeyDownEvent (Key.F.WithCtrl));
  582. Assert.Equal ("is is a test.", tf.Text);
  583. Assert.Equal (2, tf.CursorPosition);
  584. tf.CursorPosition = 9;
  585. tf.ReadOnly = true;
  586. Assert.True (tf.NewKeyDownEvent (Key.K.WithCtrl));
  587. Assert.Equal ("is is a test.", tf.Text);
  588. tf.ReadOnly = false;
  589. Assert.True (tf.NewKeyDownEvent (Key.K.WithCtrl));
  590. Assert.Equal ("is is a t", tf.Text);
  591. Assert.Equal ("est.", Clipboard.Contents);
  592. Assert.True (tf.NewKeyDownEvent (Key.Z.WithCtrl));
  593. Assert.Equal ("is is a test.", tf.Text);
  594. Assert.True (tf.NewKeyDownEvent (Key.Y.WithCtrl));
  595. Assert.Equal ("is is a t", tf.Text);
  596. #if UNIX_KEY_BINDINGS
  597. Assert.True (tf.NewKeyDownEvent (Key.Backspace.WithAlt));
  598. #else
  599. Assert.True (tf.NewKeyDownEvent (Key.Z.WithCtrl));
  600. #endif
  601. Assert.Equal ("is is a test.", tf.Text);
  602. Assert.True (tf.NewKeyDownEvent (Key.Y.WithCtrl));
  603. Assert.Equal ("is is a t", tf.Text);
  604. Assert.True (tf.NewKeyDownEvent (Key.CursorLeft.WithCtrl));
  605. Assert.Equal ("is is a t", tf.Text);
  606. Assert.Equal (8, tf.CursorPosition);
  607. Assert.True (tf.NewKeyDownEvent (Key.CursorUp.WithCtrl));
  608. Assert.Equal ("is is a t", tf.Text);
  609. Assert.Equal (6, tf.CursorPosition);
  610. #if UNIX_KEY_BINDINGS
  611. Assert.True (tf.NewKeyDownEvent (Key.B.WithAlt));
  612. #else
  613. Assert.True (tf.NewKeyDownEvent (Key.CursorLeft.WithCtrl));
  614. #endif
  615. Assert.Equal ("is is a t", tf.Text);
  616. Assert.Equal (3, tf.CursorPosition);
  617. Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithCtrl));
  618. Assert.Equal ("is is a t", tf.Text);
  619. Assert.Equal (6, tf.CursorPosition);
  620. Assert.True (tf.NewKeyDownEvent (Key.CursorDown.WithCtrl));
  621. Assert.Equal ("is is a t", tf.Text);
  622. Assert.Equal (8, tf.CursorPosition);
  623. #if UNIX_KEY_BINDINGS
  624. Assert.True (tf.NewKeyDownEvent (Key.F.WithAlt));
  625. #else
  626. Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithCtrl));
  627. #endif
  628. Assert.Equal ("is is a t", tf.Text);
  629. Assert.Equal (9, tf.CursorPosition);
  630. Assert.True (tf.Used);
  631. Assert.True (tf.NewKeyDownEvent (Key.InsertChar));
  632. Assert.Equal ("is is a t", tf.Text);
  633. Assert.Equal (9, tf.CursorPosition);
  634. Assert.False (tf.Used);
  635. tf.SelectedStart = 3;
  636. tf.CursorPosition = 7;
  637. Assert.Equal ("is a", tf.SelectedText);
  638. Assert.Equal ("est.", Clipboard.Contents);
  639. Assert.True (tf.NewKeyDownEvent (Key.C.WithCtrl));
  640. Assert.Equal ("is is a t", tf.Text);
  641. Assert.Equal ("is a", Clipboard.Contents);
  642. Assert.True (tf.NewKeyDownEvent (Key.X.WithCtrl));
  643. Assert.Equal ("is t", tf.Text);
  644. Assert.Equal ("is a", Clipboard.Contents);
  645. Assert.True (tf.NewKeyDownEvent (Key.V.WithCtrl));
  646. Assert.Equal ("is is a t", tf.Text);
  647. Assert.Equal ("is a", Clipboard.Contents);
  648. Assert.Equal (7, tf.CursorPosition);
  649. #if UNIX_KEY_BINDINGS
  650. Assert.True (tf.NewKeyDownEvent (Key.K.WithAlt));
  651. #else
  652. Assert.True (tf.NewKeyDownEvent (Key.K.WithCtrl.WithShift));
  653. #endif
  654. Assert.Equal (" t", tf.Text);
  655. Assert.Equal ("is is a", Clipboard.Contents);
  656. tf.Text = "TAB to jump between text fields.";
  657. Assert.Equal (0, tf.CursorPosition);
  658. Assert.True (tf.NewKeyDownEvent (Key.Delete.WithCtrl));
  659. Assert.Equal ("to jump between text fields.", tf.Text);
  660. tf.CursorPosition = tf.Text.Length;
  661. Assert.True (tf.NewKeyDownEvent (Key.Backspace.WithCtrl));
  662. Assert.Equal ("to jump between text fields", tf.Text);
  663. Assert.True (tf.NewKeyDownEvent (Key.A.WithCtrl));
  664. Assert.Equal ("to jump between text fields", tf.SelectedText);
  665. Assert.True (tf.NewKeyDownEvent (Key.D.WithCtrl.WithShift));
  666. Assert.Equal ("", tf.Text);
  667. }
  668. [Theory]
  669. [InlineData (false, 1)]
  670. [InlineData (true, 0)]
  671. public void Accepted_Handler_Handled_Prevents_Default_Button_Accept (bool handleAccept, int expectedButtonAccepts)
  672. {
  673. var superView = new Window
  674. {
  675. Id = "superView"
  676. };
  677. var tf = new TextField
  678. {
  679. Id = "tf"
  680. };
  681. var button = new Button
  682. {
  683. Id = "button",
  684. IsDefault = true
  685. };
  686. superView.Add (tf, button);
  687. var buttonAccept = 0;
  688. button.Accepting += ButtonAccept;
  689. var textFieldAccept = 0;
  690. tf.Accepting += TextFieldAccept;
  691. tf.SetFocus ();
  692. Assert.True (tf.HasFocus);
  693. superView.NewKeyDownEvent (Key.Enter);
  694. Assert.Equal (1, textFieldAccept);
  695. Assert.Equal (expectedButtonAccepts, buttonAccept);
  696. button.SetFocus ();
  697. superView.NewKeyDownEvent (Key.Enter);
  698. Assert.Equal (1, textFieldAccept);
  699. Assert.Equal (expectedButtonAccepts + 1, buttonAccept);
  700. return;
  701. void TextFieldAccept (object sender, CommandEventArgs e)
  702. {
  703. textFieldAccept++;
  704. e.Handled = handleAccept;
  705. }
  706. void ButtonAccept (object sender, CommandEventArgs e) { buttonAccept++; }
  707. }
  708. [Fact]
  709. [TextFieldTestsAutoInitShutdown]
  710. public void Paste_Always_Clear_The_SelectedText ()
  711. {
  712. _textField.SelectedStart = 20;
  713. _textField.CursorPosition = 24;
  714. _textField.Copy ();
  715. Assert.Equal ("text", _textField.SelectedText);
  716. _textField.Paste ();
  717. Assert.Null (_textField.SelectedText);
  718. }
  719. [Fact]
  720. [AutoInitShutdown]
  721. public void ScrollOffset_Initialize ()
  722. {
  723. var tf = new TextField { X = 1, Y = 1, Width = 20, Text = "Testing Scrolls." };
  724. tf.BeginInit ();
  725. tf.EndInit ();
  726. Assert.Equal (0, tf.ScrollOffset);
  727. Assert.Equal (16, tf.CursorPosition);
  728. }
  729. [Fact]
  730. [TextFieldTestsAutoInitShutdown]
  731. public void Selected_Text_Shows ()
  732. {
  733. // Proves #3022 is fixed (TextField selected text does not show in v2)
  734. _textField.CursorPosition = 0;
  735. var top = new Runnable ();
  736. top.Add (_textField);
  737. SessionToken rs = Application.Begin (top);
  738. Attribute [] attributes =
  739. {
  740. _textField.GetAttributeForRole (VisualRole.Focus),
  741. new (
  742. _textField.GetAttributeForRole (VisualRole.Focus).Background,
  743. _textField.GetAttributeForRole (VisualRole.Focus).Foreground
  744. )
  745. };
  746. // TAB to jump between text fields.
  747. DriverAssert.AssertDriverAttributesAre ("0000000", output, Application.Driver, attributes);
  748. // Cursor is at the end
  749. Assert.Equal (32, _textField.CursorPosition);
  750. _textField.CursorPosition = 0;
  751. _textField.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift);
  752. AutoInitShutdownAttribute.RunIteration ();
  753. Assert.Equal (4, _textField.CursorPosition);
  754. // TAB to jump between text fields.
  755. DriverAssert.AssertDriverAttributesAre ("1111000", output, Application.Driver, attributes);
  756. top.Dispose ();
  757. }
  758. [Fact]
  759. [TextFieldTestsAutoInitShutdown]
  760. public void SelectedStart_And_CursorPosition_With_Value_Greater_Than_Text_Length_Changes_Both_To_Text_Length ()
  761. {
  762. _textField.CursorPosition = 33;
  763. _textField.SelectedStart = 33;
  764. Assert.Equal (32, _textField.CursorPosition);
  765. Assert.Equal (32, _textField.SelectedStart);
  766. Assert.Equal (0, _textField.SelectedLength);
  767. Assert.Null (_textField.SelectedText);
  768. }
  769. [Fact]
  770. [TextFieldTestsAutoInitShutdown]
  771. public void SelectedStart_Greater_Than_CursorPosition_All_Selection_Is_Overwritten_On_Typing ()
  772. {
  773. _textField.SelectedStart = 19;
  774. _textField.CursorPosition = 12;
  775. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  776. _textField.NewKeyDownEvent (Key.U); // u
  777. Assert.Equal ("TAB to jump u text fields.", _textField.Text);
  778. }
  779. [Fact]
  780. [TextFieldTestsAutoInitShutdown]
  781. public void SelectedStart_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  782. {
  783. _textField.CursorPosition = 2;
  784. _textField.SelectedStart = 33;
  785. Assert.Equal (32, _textField.SelectedStart);
  786. Assert.Equal (30, _textField.SelectedLength);
  787. Assert.Equal ("B to jump between text fields.", _textField.SelectedText);
  788. }
  789. [Fact]
  790. [TextFieldTestsAutoInitShutdown]
  791. public void SelectedStart_With_Value_Less_Than_Minus_One_Changes_To_Minus_One ()
  792. {
  793. _textField.SelectedStart = -2;
  794. Assert.Equal (-1, _textField.SelectedStart);
  795. Assert.Equal (0, _textField.SelectedLength);
  796. Assert.Null (_textField.SelectedText);
  797. }
  798. [Fact]
  799. [AutoInitShutdown]
  800. public void MouseEvent_Handled_Prevents_RightClick ()
  801. {
  802. Application.MouseEvent += HandleRightClick;
  803. var tf = new TextField { Width = 10 };
  804. var clickCounter = 0;
  805. tf.MouseEvent += (s, m) => { clickCounter++; };
  806. var top = new Runnable ();
  807. top.Add (tf);
  808. Application.Begin (top);
  809. var mouseEvent = new MouseEventArgs { Flags = MouseFlags.Button1Clicked, View = tf };
  810. Application.RaiseMouseEvent (mouseEvent);
  811. Assert.Equal (1, clickCounter);
  812. // Get a fresh instance that represents a right click.
  813. // Should be ignored because of SuppressRightClick callback
  814. mouseEvent = new () { Flags = MouseFlags.Button3Clicked, View = tf };
  815. Application.RaiseMouseEvent (mouseEvent);
  816. Assert.Equal (1, clickCounter);
  817. Application.MouseEvent -= HandleRightClick;
  818. // Get a fresh instance that represents a right click.
  819. // Should no longer be ignored as the callback was removed
  820. mouseEvent = new () { Flags = MouseFlags.Button3Clicked, View = tf };
  821. // In #3183 OnMouseClicked is no longer called before MouseEvent().
  822. // This call causes the context menu to pop, and MouseEvent() returns true.
  823. // Thus, the clickCounter is NOT incremented.
  824. // Which is correct, because the user did NOT click with the left mouse button.
  825. Application.RaiseMouseEvent (mouseEvent);
  826. Assert.Equal (1, clickCounter);
  827. top.Dispose ();
  828. return;
  829. void HandleRightClick (object sender, MouseEventArgs arg)
  830. {
  831. if (arg.Flags.HasFlag (MouseFlags.Button3Clicked))
  832. {
  833. arg.Handled = true;
  834. }
  835. }
  836. }
  837. [Fact]
  838. [TextFieldTestsAutoInitShutdown]
  839. public void Text_Replaces_Tabs_With_Empty_String ()
  840. {
  841. _textField.Text = "\t\tTAB to jump between text fields.";
  842. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  843. _textField.Text = "";
  844. Clipboard.Contents = "\t\tTAB to jump between text fields.";
  845. _textField.Paste ();
  846. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  847. }
  848. [Fact]
  849. [TextFieldTestsAutoInitShutdown]
  850. public void TextChanged_Event ()
  851. {
  852. var eventFired = false;
  853. _textField.TextChanged += (s, e) => eventFired = true;
  854. _textField.Text = "changed";
  855. Assert.True (eventFired);
  856. Assert.Equal ("changed", _textField.Text);
  857. }
  858. [Fact]
  859. [TextFieldTestsAutoInitShutdown]
  860. public void TextChanging_Event ()
  861. {
  862. var cancel = true;
  863. _textField.TextChanging += (s, e) =>
  864. {
  865. Assert.Equal ("changing", e.Result);
  866. if (cancel)
  867. {
  868. e.Handled = true;
  869. }
  870. };
  871. _textField.Text = "changing";
  872. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  873. cancel = false;
  874. _textField.Text = "changing";
  875. Assert.Equal ("changing", _textField.Text);
  876. }
  877. [Fact]
  878. [TextFieldTestsAutoInitShutdown]
  879. public void Used_Is_False ()
  880. {
  881. _textField.Used = false;
  882. _textField.CursorPosition = 10;
  883. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  884. _textField.NewKeyDownEvent (Key.U); // u
  885. Assert.Equal ("TAB to jumu between text fields.", _textField.Text);
  886. _textField.NewKeyDownEvent (Key.S); // s
  887. Assert.Equal ("TAB to jumusbetween text fields.", _textField.Text);
  888. _textField.NewKeyDownEvent (Key.E); // e
  889. Assert.Equal ("TAB to jumuseetween text fields.", _textField.Text);
  890. _textField.NewKeyDownEvent (Key.D); // d
  891. Assert.Equal ("TAB to jumusedtween text fields.", _textField.Text);
  892. }
  893. [Fact]
  894. [TextFieldTestsAutoInitShutdown]
  895. public void Used_Is_True_By_Default ()
  896. {
  897. _textField.CursorPosition = 10;
  898. Assert.Equal ("TAB to jump between text fields.", _textField.Text);
  899. _textField.NewKeyDownEvent (Key.U); // u
  900. Assert.Equal ("TAB to jumup between text fields.", _textField.Text);
  901. _textField.NewKeyDownEvent (Key.S); // s
  902. Assert.Equal ("TAB to jumusp between text fields.", _textField.Text);
  903. _textField.NewKeyDownEvent (Key.E); // e
  904. Assert.Equal ("TAB to jumusep between text fields.", _textField.Text);
  905. _textField.NewKeyDownEvent (Key.D); // d
  906. Assert.Equal ("TAB to jumusedp between text fields.", _textField.Text);
  907. }
  908. [Fact]
  909. [TextFieldTestsAutoInitShutdown]
  910. public void WordBackward_With_No_Selection ()
  911. {
  912. _textField.CursorPosition = _textField.Text.Length;
  913. var iteration = 0;
  914. while (_textField.CursorPosition > 0)
  915. {
  916. _textField.NewKeyDownEvent (Key.CursorLeft.WithCtrl);
  917. switch (iteration)
  918. {
  919. case 0:
  920. Assert.Equal (31, _textField.CursorPosition);
  921. Assert.Equal (-1, _textField.SelectedStart);
  922. Assert.Equal (0, _textField.SelectedLength);
  923. Assert.Null (_textField.SelectedText);
  924. break;
  925. case 1:
  926. Assert.Equal (25, _textField.CursorPosition);
  927. Assert.Equal (-1, _textField.SelectedStart);
  928. Assert.Equal (0, _textField.SelectedLength);
  929. Assert.Null (_textField.SelectedText);
  930. break;
  931. case 2:
  932. Assert.Equal (20, _textField.CursorPosition);
  933. Assert.Equal (-1, _textField.SelectedStart);
  934. Assert.Equal (0, _textField.SelectedLength);
  935. Assert.Null (_textField.SelectedText);
  936. break;
  937. case 3:
  938. Assert.Equal (12, _textField.CursorPosition);
  939. Assert.Equal (-1, _textField.SelectedStart);
  940. Assert.Equal (0, _textField.SelectedLength);
  941. Assert.Null (_textField.SelectedText);
  942. break;
  943. case 4:
  944. Assert.Equal (7, _textField.CursorPosition);
  945. Assert.Equal (-1, _textField.SelectedStart);
  946. Assert.Equal (0, _textField.SelectedLength);
  947. Assert.Null (_textField.SelectedText);
  948. break;
  949. case 5:
  950. Assert.Equal (4, _textField.CursorPosition);
  951. Assert.Equal (-1, _textField.SelectedStart);
  952. Assert.Equal (0, _textField.SelectedLength);
  953. Assert.Null (_textField.SelectedText);
  954. break;
  955. case 6:
  956. Assert.Equal (0, _textField.CursorPosition);
  957. Assert.Equal (-1, _textField.SelectedStart);
  958. Assert.Equal (0, _textField.SelectedLength);
  959. Assert.Null (_textField.SelectedText);
  960. break;
  961. }
  962. iteration++;
  963. }
  964. }
  965. [Fact]
  966. [TextFieldTestsAutoInitShutdown]
  967. public void WordBackward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  968. {
  969. // 1 2 3 4 5
  970. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  971. _textField.Text = "TAB t o jump b etween t ext f ields .";
  972. _textField.CursorPosition = _textField.Text.Length;
  973. var iteration = 0;
  974. while (_textField.CursorPosition > 0)
  975. {
  976. _textField.NewKeyDownEvent (Key.CursorLeft.WithCtrl);
  977. switch (iteration)
  978. {
  979. case 0:
  980. Assert.Equal (54, _textField.CursorPosition);
  981. Assert.Equal (-1, _textField.SelectedStart);
  982. Assert.Equal (0, _textField.SelectedLength);
  983. Assert.Null (_textField.SelectedText);
  984. break;
  985. case 1:
  986. Assert.Equal (48, _textField.CursorPosition);
  987. Assert.Equal (-1, _textField.SelectedStart);
  988. Assert.Equal (0, _textField.SelectedLength);
  989. Assert.Null (_textField.SelectedText);
  990. break;
  991. case 2:
  992. Assert.Equal (46, _textField.CursorPosition);
  993. Assert.Equal (-1, _textField.SelectedStart);
  994. Assert.Equal (0, _textField.SelectedLength);
  995. Assert.Null (_textField.SelectedText);
  996. break;
  997. case 3:
  998. Assert.Equal (40, _textField.CursorPosition);
  999. Assert.Equal (-1, _textField.SelectedStart);
  1000. Assert.Equal (0, _textField.SelectedLength);
  1001. Assert.Null (_textField.SelectedText);
  1002. break;
  1003. case 4:
  1004. Assert.Equal (38, _textField.CursorPosition);
  1005. Assert.Equal (-1, _textField.SelectedStart);
  1006. Assert.Equal (0, _textField.SelectedLength);
  1007. Assert.Null (_textField.SelectedText);
  1008. break;
  1009. case 5:
  1010. Assert.Equal (28, _textField.CursorPosition);
  1011. Assert.Equal (-1, _textField.SelectedStart);
  1012. Assert.Equal (0, _textField.SelectedLength);
  1013. Assert.Null (_textField.SelectedText);
  1014. break;
  1015. case 6:
  1016. Assert.Equal (25, _textField.CursorPosition);
  1017. Assert.Equal (-1, _textField.SelectedStart);
  1018. Assert.Equal (0, _textField.SelectedLength);
  1019. Assert.Null (_textField.SelectedText);
  1020. break;
  1021. case 7:
  1022. Assert.Equal (12, _textField.CursorPosition);
  1023. Assert.Equal (-1, _textField.SelectedStart);
  1024. Assert.Equal (0, _textField.SelectedLength);
  1025. Assert.Null (_textField.SelectedText);
  1026. break;
  1027. case 8:
  1028. Assert.Equal (9, _textField.CursorPosition);
  1029. Assert.Equal (-1, _textField.SelectedStart);
  1030. Assert.Equal (0, _textField.SelectedLength);
  1031. Assert.Null (_textField.SelectedText);
  1032. break;
  1033. case 9:
  1034. Assert.Equal (6, _textField.CursorPosition);
  1035. Assert.Equal (-1, _textField.SelectedStart);
  1036. Assert.Equal (0, _textField.SelectedLength);
  1037. Assert.Null (_textField.SelectedText);
  1038. break;
  1039. case 10:
  1040. Assert.Equal (0, _textField.CursorPosition);
  1041. Assert.Equal (-1, _textField.SelectedStart);
  1042. Assert.Equal (0, _textField.SelectedLength);
  1043. Assert.Null (_textField.SelectedText);
  1044. break;
  1045. }
  1046. iteration++;
  1047. }
  1048. }
  1049. [Fact]
  1050. [TextFieldTestsAutoInitShutdown]
  1051. public void WordBackward_With_Selection ()
  1052. {
  1053. _textField.CursorPosition = _textField.Text.Length;
  1054. _textField.SelectedStart = _textField.Text.Length;
  1055. var iteration = 0;
  1056. while (_textField.CursorPosition > 0)
  1057. {
  1058. _textField.NewKeyDownEvent (
  1059. new (
  1060. KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask
  1061. )
  1062. );
  1063. switch (iteration)
  1064. {
  1065. case 0:
  1066. Assert.Equal (31, _textField.CursorPosition);
  1067. Assert.Equal (32, _textField.SelectedStart);
  1068. Assert.Equal (1, _textField.SelectedLength);
  1069. Assert.Equal (".", _textField.SelectedText);
  1070. break;
  1071. case 1:
  1072. Assert.Equal (25, _textField.CursorPosition);
  1073. Assert.Equal (32, _textField.SelectedStart);
  1074. Assert.Equal (7, _textField.SelectedLength);
  1075. Assert.Equal ("fields.", _textField.SelectedText);
  1076. break;
  1077. case 2:
  1078. Assert.Equal (20, _textField.CursorPosition);
  1079. Assert.Equal (32, _textField.SelectedStart);
  1080. Assert.Equal (12, _textField.SelectedLength);
  1081. Assert.Equal ("text fields.", _textField.SelectedText);
  1082. break;
  1083. case 3:
  1084. Assert.Equal (12, _textField.CursorPosition);
  1085. Assert.Equal (32, _textField.SelectedStart);
  1086. Assert.Equal (20, _textField.SelectedLength);
  1087. Assert.Equal ("between text fields.", _textField.SelectedText);
  1088. break;
  1089. case 4:
  1090. Assert.Equal (7, _textField.CursorPosition);
  1091. Assert.Equal (32, _textField.SelectedStart);
  1092. Assert.Equal (25, _textField.SelectedLength);
  1093. Assert.Equal ("jump between text fields.", _textField.SelectedText);
  1094. break;
  1095. case 5:
  1096. Assert.Equal (4, _textField.CursorPosition);
  1097. Assert.Equal (32, _textField.SelectedStart);
  1098. Assert.Equal (28, _textField.SelectedLength);
  1099. Assert.Equal ("to jump between text fields.", _textField.SelectedText);
  1100. break;
  1101. case 6:
  1102. Assert.Equal (0, _textField.CursorPosition);
  1103. Assert.Equal (32, _textField.SelectedStart);
  1104. Assert.Equal (32, _textField.SelectedLength);
  1105. Assert.Equal ("TAB to jump between text fields.", _textField.SelectedText);
  1106. break;
  1107. }
  1108. iteration++;
  1109. }
  1110. }
  1111. [Fact]
  1112. [TextFieldTestsAutoInitShutdown]
  1113. public void
  1114. WordBackward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  1115. {
  1116. _textField.CursorPosition = 10;
  1117. _textField.SelectedStart = 10;
  1118. var iteration = 0;
  1119. while (_textField.CursorPosition > 0)
  1120. {
  1121. _textField.NewKeyDownEvent (
  1122. new (
  1123. KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask
  1124. )
  1125. );
  1126. switch (iteration)
  1127. {
  1128. case 0:
  1129. Assert.Equal (7, _textField.CursorPosition);
  1130. Assert.Equal (10, _textField.SelectedStart);
  1131. Assert.Equal (3, _textField.SelectedLength);
  1132. Assert.Equal ("jum", _textField.SelectedText);
  1133. break;
  1134. case 1:
  1135. Assert.Equal (4, _textField.CursorPosition);
  1136. Assert.Equal (10, _textField.SelectedStart);
  1137. Assert.Equal (6, _textField.SelectedLength);
  1138. Assert.Equal ("to jum", _textField.SelectedText);
  1139. break;
  1140. case 2:
  1141. Assert.Equal (0, _textField.CursorPosition);
  1142. Assert.Equal (10, _textField.SelectedStart);
  1143. Assert.Equal (10, _textField.SelectedLength);
  1144. Assert.Equal ("TAB to jum", _textField.SelectedText);
  1145. break;
  1146. }
  1147. iteration++;
  1148. }
  1149. }
  1150. [Fact]
  1151. [TextFieldTestsAutoInitShutdown]
  1152. public void WordForward_With_No_Selection ()
  1153. {
  1154. _textField.CursorPosition = 0;
  1155. var iteration = 0;
  1156. while (_textField.CursorPosition < _textField.Text.Length)
  1157. {
  1158. _textField.NewKeyDownEvent (Key.CursorRight.WithCtrl);
  1159. switch (iteration)
  1160. {
  1161. case 0:
  1162. Assert.Equal (4, _textField.CursorPosition);
  1163. Assert.Equal (-1, _textField.SelectedStart);
  1164. Assert.Equal (0, _textField.SelectedLength);
  1165. Assert.Null (_textField.SelectedText);
  1166. break;
  1167. case 1:
  1168. Assert.Equal (7, _textField.CursorPosition);
  1169. Assert.Equal (-1, _textField.SelectedStart);
  1170. Assert.Equal (0, _textField.SelectedLength);
  1171. Assert.Null (_textField.SelectedText);
  1172. break;
  1173. case 2:
  1174. Assert.Equal (12, _textField.CursorPosition);
  1175. Assert.Equal (-1, _textField.SelectedStart);
  1176. Assert.Equal (0, _textField.SelectedLength);
  1177. Assert.Null (_textField.SelectedText);
  1178. break;
  1179. case 3:
  1180. Assert.Equal (20, _textField.CursorPosition);
  1181. Assert.Equal (-1, _textField.SelectedStart);
  1182. Assert.Equal (0, _textField.SelectedLength);
  1183. Assert.Null (_textField.SelectedText);
  1184. break;
  1185. case 4:
  1186. Assert.Equal (25, _textField.CursorPosition);
  1187. Assert.Equal (-1, _textField.SelectedStart);
  1188. Assert.Equal (0, _textField.SelectedLength);
  1189. Assert.Null (_textField.SelectedText);
  1190. break;
  1191. case 5:
  1192. Assert.Equal (31, _textField.CursorPosition);
  1193. Assert.Equal (-1, _textField.SelectedStart);
  1194. Assert.Equal (0, _textField.SelectedLength);
  1195. Assert.Null (_textField.SelectedText);
  1196. break;
  1197. case 6:
  1198. Assert.Equal (32, _textField.CursorPosition);
  1199. Assert.Equal (-1, _textField.SelectedStart);
  1200. Assert.Equal (0, _textField.SelectedLength);
  1201. Assert.Null (_textField.SelectedText);
  1202. break;
  1203. }
  1204. iteration++;
  1205. }
  1206. }
  1207. [Fact]
  1208. [TextFieldTestsAutoInitShutdown]
  1209. public void WordForward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  1210. {
  1211. // 1 2 3 4 5
  1212. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  1213. _textField.Text = "TAB t o jump b etween t ext f ields .";
  1214. _textField.CursorPosition = 0;
  1215. var iteration = 0;
  1216. while (_textField.CursorPosition < _textField.Text.Length)
  1217. {
  1218. _textField.NewKeyDownEvent (Key.CursorRight.WithCtrl);
  1219. switch (iteration)
  1220. {
  1221. case 0:
  1222. Assert.Equal (6, _textField.CursorPosition);
  1223. Assert.Equal (-1, _textField.SelectedStart);
  1224. Assert.Equal (0, _textField.SelectedLength);
  1225. Assert.Null (_textField.SelectedText);
  1226. break;
  1227. case 1:
  1228. Assert.Equal (9, _textField.CursorPosition);
  1229. Assert.Equal (-1, _textField.SelectedStart);
  1230. Assert.Equal (0, _textField.SelectedLength);
  1231. Assert.Null (_textField.SelectedText);
  1232. break;
  1233. case 2:
  1234. Assert.Equal (12, _textField.CursorPosition);
  1235. Assert.Equal (-1, _textField.SelectedStart);
  1236. Assert.Equal (0, _textField.SelectedLength);
  1237. Assert.Null (_textField.SelectedText);
  1238. break;
  1239. case 3:
  1240. Assert.Equal (25, _textField.CursorPosition);
  1241. Assert.Equal (-1, _textField.SelectedStart);
  1242. Assert.Equal (0, _textField.SelectedLength);
  1243. Assert.Null (_textField.SelectedText);
  1244. break;
  1245. case 4:
  1246. Assert.Equal (28, _textField.CursorPosition);
  1247. Assert.Equal (-1, _textField.SelectedStart);
  1248. Assert.Equal (0, _textField.SelectedLength);
  1249. Assert.Null (_textField.SelectedText);
  1250. break;
  1251. case 5:
  1252. Assert.Equal (38, _textField.CursorPosition);
  1253. Assert.Equal (-1, _textField.SelectedStart);
  1254. Assert.Equal (0, _textField.SelectedLength);
  1255. Assert.Null (_textField.SelectedText);
  1256. break;
  1257. case 6:
  1258. Assert.Equal (40, _textField.CursorPosition);
  1259. Assert.Equal (-1, _textField.SelectedStart);
  1260. Assert.Equal (0, _textField.SelectedLength);
  1261. Assert.Null (_textField.SelectedText);
  1262. break;
  1263. case 7:
  1264. Assert.Equal (46, _textField.CursorPosition);
  1265. Assert.Equal (-1, _textField.SelectedStart);
  1266. Assert.Equal (0, _textField.SelectedLength);
  1267. Assert.Null (_textField.SelectedText);
  1268. break;
  1269. case 8:
  1270. Assert.Equal (48, _textField.CursorPosition);
  1271. Assert.Equal (-1, _textField.SelectedStart);
  1272. Assert.Equal (0, _textField.SelectedLength);
  1273. Assert.Null (_textField.SelectedText);
  1274. break;
  1275. case 9:
  1276. Assert.Equal (54, _textField.CursorPosition);
  1277. Assert.Equal (-1, _textField.SelectedStart);
  1278. Assert.Equal (0, _textField.SelectedLength);
  1279. Assert.Null (_textField.SelectedText);
  1280. break;
  1281. case 10:
  1282. Assert.Equal (55, _textField.CursorPosition);
  1283. Assert.Equal (-1, _textField.SelectedStart);
  1284. Assert.Equal (0, _textField.SelectedLength);
  1285. Assert.Null (_textField.SelectedText);
  1286. break;
  1287. }
  1288. iteration++;
  1289. }
  1290. }
  1291. [Fact]
  1292. [TextFieldTestsAutoInitShutdown]
  1293. public void WordForward_With_Selection ()
  1294. {
  1295. _textField.CursorPosition = 0;
  1296. _textField.SelectedStart = 0;
  1297. var iteration = 0;
  1298. while (_textField.CursorPosition < _textField.Text.Length)
  1299. {
  1300. _textField.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift);
  1301. switch (iteration)
  1302. {
  1303. case 0:
  1304. Assert.Equal (4, _textField.CursorPosition);
  1305. Assert.Equal (0, _textField.SelectedStart);
  1306. Assert.Equal (4, _textField.SelectedLength);
  1307. Assert.Equal ("TAB ", _textField.SelectedText);
  1308. break;
  1309. case 1:
  1310. Assert.Equal (7, _textField.CursorPosition);
  1311. Assert.Equal (0, _textField.SelectedStart);
  1312. Assert.Equal (7, _textField.SelectedLength);
  1313. Assert.Equal ("TAB to ", _textField.SelectedText);
  1314. break;
  1315. case 2:
  1316. Assert.Equal (12, _textField.CursorPosition);
  1317. Assert.Equal (0, _textField.SelectedStart);
  1318. Assert.Equal (12, _textField.SelectedLength);
  1319. Assert.Equal ("TAB to jump ", _textField.SelectedText);
  1320. break;
  1321. case 3:
  1322. Assert.Equal (20, _textField.CursorPosition);
  1323. Assert.Equal (0, _textField.SelectedStart);
  1324. Assert.Equal (20, _textField.SelectedLength);
  1325. Assert.Equal ("TAB to jump between ", _textField.SelectedText);
  1326. break;
  1327. case 4:
  1328. Assert.Equal (25, _textField.CursorPosition);
  1329. Assert.Equal (0, _textField.SelectedStart);
  1330. Assert.Equal (25, _textField.SelectedLength);
  1331. Assert.Equal ("TAB to jump between text ", _textField.SelectedText);
  1332. break;
  1333. case 5:
  1334. Assert.Equal (31, _textField.CursorPosition);
  1335. Assert.Equal (0, _textField.SelectedStart);
  1336. Assert.Equal (31, _textField.SelectedLength);
  1337. Assert.Equal ("TAB to jump between text fields", _textField.SelectedText);
  1338. break;
  1339. case 6:
  1340. Assert.Equal (32, _textField.CursorPosition);
  1341. Assert.Equal (0, _textField.SelectedStart);
  1342. Assert.Equal (32, _textField.SelectedLength);
  1343. Assert.Equal ("TAB to jump between text fields.", _textField.SelectedText);
  1344. break;
  1345. }
  1346. iteration++;
  1347. }
  1348. }
  1349. [Fact]
  1350. [TextFieldTestsAutoInitShutdown]
  1351. public void
  1352. WordForward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  1353. {
  1354. _textField.CursorPosition = 10;
  1355. _textField.SelectedStart = 10;
  1356. var iteration = 0;
  1357. while (_textField.CursorPosition < _textField.Text.Length)
  1358. {
  1359. _textField.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift);
  1360. switch (iteration)
  1361. {
  1362. case 0:
  1363. Assert.Equal (12, _textField.CursorPosition);
  1364. Assert.Equal (10, _textField.SelectedStart);
  1365. Assert.Equal (2, _textField.SelectedLength);
  1366. Assert.Equal ("p ", _textField.SelectedText);
  1367. break;
  1368. case 1:
  1369. Assert.Equal (20, _textField.CursorPosition);
  1370. Assert.Equal (10, _textField.SelectedStart);
  1371. Assert.Equal (10, _textField.SelectedLength);
  1372. Assert.Equal ("p between ", _textField.SelectedText);
  1373. break;
  1374. case 2:
  1375. Assert.Equal (25, _textField.CursorPosition);
  1376. Assert.Equal (10, _textField.SelectedStart);
  1377. Assert.Equal (15, _textField.SelectedLength);
  1378. Assert.Equal ("p between text ", _textField.SelectedText);
  1379. break;
  1380. case 3:
  1381. Assert.Equal (31, _textField.CursorPosition);
  1382. Assert.Equal (10, _textField.SelectedStart);
  1383. Assert.Equal (21, _textField.SelectedLength);
  1384. Assert.Equal ("p between text fields", _textField.SelectedText);
  1385. break;
  1386. case 4:
  1387. Assert.Equal (32, _textField.CursorPosition);
  1388. Assert.Equal (10, _textField.SelectedStart);
  1389. Assert.Equal (22, _textField.SelectedLength);
  1390. Assert.Equal ("p between text fields.", _textField.SelectedText);
  1391. break;
  1392. }
  1393. iteration++;
  1394. }
  1395. }
  1396. [Fact]
  1397. [SetupFakeApplication]
  1398. public void Words_With_Accents_Incorrect_Order_Will_Result_With_Wrong_Accent_Place ()
  1399. {
  1400. var tf = new TextField
  1401. {
  1402. Driver = ApplicationImpl.Instance.Driver,
  1403. Width = 30, Text = "Les Misérables"
  1404. };
  1405. tf.SetRelativeLayout (new (100, 100));
  1406. tf.Draw ();
  1407. DriverAssert.AssertDriverContentsWithFrameAre (
  1408. @"
  1409. Les Misérables",
  1410. output
  1411. );
  1412. tf.Text = "Les Mise" + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) + "rables";
  1413. tf.Draw ();
  1414. DriverAssert.AssertDriverContentsWithFrameAre (
  1415. @"
  1416. Les Misérables",
  1417. output
  1418. );
  1419. // incorrect order will result with a wrong accent place
  1420. tf.Text = "Les Mis" + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) + "erables";
  1421. tf.SetClipToScreen ();
  1422. tf.Draw ();
  1423. DriverAssert.AssertDriverContentsWithFrameAre (
  1424. @"
  1425. Les Miśerables",
  1426. output
  1427. );
  1428. }
  1429. private TextField GetTextFieldsInView ()
  1430. {
  1431. var tf = new TextField { Width = 10 };
  1432. var tf2 = new TextField { Y = 1, Width = 10 };
  1433. Runnable top = new ();
  1434. top.Add (tf);
  1435. top.Add (tf2);
  1436. Application.Begin (top);
  1437. Assert.Same (tf, top.Focused);
  1438. return tf;
  1439. }
  1440. // This class enables test functions annotated with the [InitShutdown] attribute
  1441. // to have a function called before the test function is called and after.
  1442. //
  1443. // This is necessary because a) Application is a singleton and Init/Shutdown must be called
  1444. // as a pair, and b) all unit test functions should be atomic.
  1445. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
  1446. public class TextFieldTestsAutoInitShutdown : AutoInitShutdownAttribute
  1447. {
  1448. public override void After (MethodInfo methodUnderTest)
  1449. {
  1450. _textField.Dispose ();
  1451. _textField = null;
  1452. base.After (methodUnderTest);
  1453. }
  1454. public override void Before (MethodInfo methodUnderTest)
  1455. {
  1456. base.Before (methodUnderTest);
  1457. //Application.TopRunnable.Scheme = Colors.Schemes ["Base"];
  1458. _textField = new ()
  1459. {
  1460. // 1 2 3
  1461. // 01234567890123456789012345678901=32 (Length)
  1462. Text = "TAB to jump between text fields.",
  1463. Width = 32,
  1464. App = ApplicationImpl.Instance
  1465. };
  1466. }
  1467. }
  1468. [Fact]
  1469. [AutoInitShutdown]
  1470. public void Draw_Esc_Rune ()
  1471. {
  1472. var tf = new TextField
  1473. {
  1474. Driver = ApplicationImpl.Instance.Driver,
  1475. Width = 5, Text = "\u001b"
  1476. };
  1477. tf.BeginInit ();
  1478. tf.EndInit ();
  1479. tf.Draw ();
  1480. DriverAssert.AssertDriverContentsWithFrameAre ("\u241b", output);
  1481. tf.Dispose ();
  1482. }
  1483. }