TextFieldTests.cs 63 KB

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