TextFieldTests.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  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. Toplevel 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.Current.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.Current.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.Current.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.Current.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.Current.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.Current.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.Current.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 Toplevel ();
  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." };
  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 Toplevel ();
  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.MouseClick += (s, m) => { clickCounter++; };
  806. var top = new Toplevel ();
  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. Toplevel 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.Current.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. };
  1465. }
  1466. }
  1467. [Fact]
  1468. [AutoInitShutdown]
  1469. public void Draw_Esc_Rune ()
  1470. {
  1471. var tf = new TextField
  1472. {
  1473. Driver = ApplicationImpl.Instance.Driver,
  1474. Width = 5, Text = "\u001b"
  1475. };
  1476. tf.BeginInit ();
  1477. tf.EndInit ();
  1478. tf.Draw ();
  1479. DriverAssert.AssertDriverContentsWithFrameAre ("\u241b", output);
  1480. tf.Dispose ();
  1481. }
  1482. }