TextFormatterTests.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. using NStack;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.IO;
  6. using System.Linq;
  7. using Terminal.Gui;
  8. using Xunit;
  9. // Alais Console to MockConsole so we don't accidentally use Console
  10. using Console = Terminal.Gui.FakeConsole;
  11. namespace Terminal.Gui {
  12. public class TextFormatterTests {
  13. [Fact]
  14. public void FindHotKey_Invalid_ReturnsFalse ()
  15. {
  16. var text = ustring.Empty;
  17. Rune hotKeySpecifier = '_';
  18. bool supportFirstUpperCase = false;
  19. int hotPos = 0;
  20. Key hotKey = Key.Unknown;
  21. bool result = false;
  22. text = null;
  23. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  24. Assert.False (result);
  25. Assert.Equal (-1, hotPos);
  26. Assert.Equal (Key.Unknown, hotKey);
  27. text = "";
  28. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  29. Assert.False (result);
  30. Assert.Equal (-1, hotPos);
  31. Assert.Equal (Key.Unknown, hotKey);
  32. text = "no hotkey";
  33. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  34. Assert.False (result);
  35. Assert.Equal (-1, hotPos);
  36. Assert.Equal (Key.Unknown, hotKey);
  37. text = "No hotkey, Upper Case";
  38. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  39. Assert.False (result);
  40. Assert.Equal (-1, hotPos);
  41. Assert.Equal (Key.Unknown, hotKey);
  42. text = "Non-english: Сохранить";
  43. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  44. Assert.False (result);
  45. Assert.Equal (-1, hotPos);
  46. Assert.Equal (Key.Unknown, hotKey);
  47. }
  48. [Fact]
  49. public void FindHotKey_AlphaUpperCase_Succeeds ()
  50. {
  51. var text = ustring.Empty;
  52. Rune hotKeySpecifier = '_';
  53. bool supportFirstUpperCase = false;
  54. int hotPos = 0;
  55. Key hotKey = Key.Unknown;
  56. bool result = false;
  57. text = "_K Before";
  58. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  59. Assert.True (result);
  60. Assert.Equal (0, hotPos);
  61. Assert.Equal ((Key)'K', hotKey);
  62. text = "a_K Second";
  63. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  64. Assert.True (result);
  65. Assert.Equal (1, hotPos);
  66. Assert.Equal ((Key)'K', hotKey);
  67. text = "Last _K";
  68. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  69. Assert.True (result);
  70. Assert.Equal (5, hotPos);
  71. Assert.Equal ((Key)'K', hotKey);
  72. text = "After K_";
  73. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  74. Assert.False (result);
  75. Assert.Equal (-1, hotPos);
  76. Assert.Equal (Key.Unknown, hotKey);
  77. text = "Multiple _K and _R";
  78. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  79. Assert.True (result);
  80. Assert.Equal (9, hotPos);
  81. Assert.Equal ((Key)'K', hotKey);
  82. // Cryllic K (К)
  83. text = "Non-english: _Кдать";
  84. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  85. Assert.True (result);
  86. Assert.Equal (13, hotPos);
  87. Assert.Equal ((Key)'К', hotKey);
  88. // Turn on FirstUpperCase and verify same results
  89. supportFirstUpperCase = true;
  90. text = "_K Before";
  91. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  92. Assert.True (result);
  93. Assert.Equal (0, hotPos);
  94. Assert.Equal ((Key)'K', hotKey);
  95. text = "a_K Second";
  96. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  97. Assert.True (result);
  98. Assert.Equal (1, hotPos);
  99. Assert.Equal ((Key)'K', hotKey);
  100. text = "Last _K";
  101. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  102. Assert.True (result);
  103. Assert.Equal (5, hotPos);
  104. Assert.Equal ((Key)'K', hotKey);
  105. text = "After K_";
  106. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  107. Assert.False (result);
  108. Assert.Equal (-1, hotPos);
  109. Assert.Equal (Key.Unknown, hotKey);
  110. text = "Multiple _K and _R";
  111. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  112. Assert.True (result);
  113. Assert.Equal (9, hotPos);
  114. Assert.Equal ((Key)'K', hotKey);
  115. // Cryllic K (К)
  116. text = "Non-english: _Кдать";
  117. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  118. Assert.True (result);
  119. Assert.Equal (13, hotPos);
  120. Assert.Equal ((Key)'К', hotKey);
  121. }
  122. [Fact]
  123. public void FindHotKey_AlphaLowerCase_Succeeds ()
  124. {
  125. var text = ustring.Empty;
  126. Rune hotKeySpecifier = '_';
  127. bool supportFirstUpperCase = false;
  128. int hotPos = 0;
  129. Key hotKey = Key.Unknown;
  130. bool result = false;
  131. // lower case should return uppercase Hotkey
  132. text = "_k Before";
  133. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  134. Assert.True (result);
  135. Assert.Equal (0, hotPos);
  136. Assert.Equal ((Key)'K', hotKey);
  137. text = "a_k Second";
  138. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  139. Assert.True (result);
  140. Assert.Equal (1, hotPos);
  141. Assert.Equal ((Key)'K', hotKey);
  142. text = "Last _k";
  143. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  144. Assert.True (result);
  145. Assert.Equal (5, hotPos);
  146. Assert.Equal ((Key)'K', hotKey);
  147. text = "After k_";
  148. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  149. Assert.False (result);
  150. Assert.Equal (-1, hotPos);
  151. Assert.Equal (Key.Unknown, hotKey);
  152. text = "Multiple _k and _R";
  153. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  154. Assert.True (result);
  155. Assert.Equal (9, hotPos);
  156. Assert.Equal ((Key)'K', hotKey);
  157. // Lower case Cryllic K (к)
  158. text = "Non-english: _кдать";
  159. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  160. Assert.True (result);
  161. Assert.Equal (13, hotPos);
  162. Assert.Equal ((Key)'К', hotKey);
  163. // Turn on FirstUpperCase and verify same results
  164. supportFirstUpperCase = true;
  165. text = "_k Before";
  166. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  167. Assert.True (result);
  168. Assert.Equal (0, hotPos);
  169. Assert.Equal ((Key)'K', hotKey);
  170. text = "a_k Second";
  171. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  172. Assert.True (result);
  173. Assert.Equal (1, hotPos);
  174. Assert.Equal ((Key)'K', hotKey);
  175. text = "Last _k";
  176. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  177. Assert.True (result);
  178. Assert.Equal (5, hotPos);
  179. Assert.Equal ((Key)'K', hotKey);
  180. text = "After k_";
  181. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  182. Assert.False (result);
  183. Assert.Equal (-1, hotPos);
  184. Assert.Equal (Key.Unknown, hotKey);
  185. text = "Multiple _k and _R";
  186. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  187. Assert.True (result);
  188. Assert.Equal (9, hotPos);
  189. Assert.Equal ((Key)'K', hotKey);
  190. // Lower case Cryllic K (к)
  191. text = "Non-english: _кдать";
  192. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  193. Assert.True (result);
  194. Assert.Equal (13, hotPos);
  195. Assert.Equal ((Key)'К', hotKey);
  196. }
  197. [Fact]
  198. public void FindHotKey_Numeric_Succeeds ()
  199. {
  200. var text = ustring.Empty;
  201. Rune hotKeySpecifier = '_';
  202. bool supportFirstUpperCase = false;
  203. int hotPos = 0;
  204. Key hotKey = Key.Unknown;
  205. bool result = false;
  206. // Digits
  207. text = "_1 Before";
  208. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  209. Assert.True (result);
  210. Assert.Equal (0, hotPos);
  211. Assert.Equal ((Key)'1', hotKey);
  212. text = "a_1 Second";
  213. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  214. Assert.True (result);
  215. Assert.Equal (1, hotPos);
  216. Assert.Equal ((Key)'1', hotKey);
  217. text = "Last _1";
  218. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  219. Assert.True (result);
  220. Assert.Equal (5, hotPos);
  221. Assert.Equal ((Key)'1', hotKey);
  222. text = "After 1_";
  223. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  224. Assert.False (result);
  225. Assert.Equal (-1, hotPos);
  226. Assert.Equal (Key.Unknown, hotKey);
  227. text = "Multiple _1 and _2";
  228. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  229. Assert.True (result);
  230. Assert.Equal (9, hotPos);
  231. Assert.Equal ((Key)'1', hotKey);
  232. // Turn on FirstUpperCase and verify same results
  233. supportFirstUpperCase = true;
  234. text = "_1 Before";
  235. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  236. Assert.True (result);
  237. Assert.Equal (0, hotPos);
  238. Assert.Equal ((Key)'1', hotKey);
  239. text = "a_1 Second";
  240. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  241. Assert.True (result);
  242. Assert.Equal (1, hotPos);
  243. Assert.Equal ((Key)'1', hotKey);
  244. text = "Last _1";
  245. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  246. Assert.True (result);
  247. Assert.Equal (5, hotPos);
  248. Assert.Equal ((Key)'1', hotKey);
  249. text = "After 1_";
  250. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  251. Assert.False (result);
  252. Assert.Equal (-1, hotPos);
  253. Assert.Equal (Key.Unknown, hotKey);
  254. text = "Multiple _1 and _2";
  255. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  256. Assert.True (result);
  257. Assert.Equal (9, hotPos);
  258. Assert.Equal ((Key)'1', hotKey);
  259. }
  260. [Fact]
  261. public void FindHotKey_Legacy_FirstUpperCase_Succeeds ()
  262. {
  263. bool supportFirstUpperCase = true;
  264. var text = ustring.Empty;
  265. Rune hotKeySpecifier = (Rune)0;
  266. int hotPos = 0;
  267. Key hotKey = Key.Unknown;
  268. bool result = false;
  269. text = "K Before";
  270. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  271. Assert.True (result);
  272. Assert.Equal (0, hotPos);
  273. Assert.Equal ((Key)'K', hotKey);
  274. text = "aK Second";
  275. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  276. Assert.True (result);
  277. Assert.Equal (1, hotPos);
  278. Assert.Equal ((Key)'K', hotKey);
  279. text = "last K";
  280. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  281. Assert.True (result);
  282. Assert.Equal (5, hotPos);
  283. Assert.Equal ((Key)'K', hotKey);
  284. text = "multiple K and R";
  285. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  286. Assert.True (result);
  287. Assert.Equal (9, hotPos);
  288. Assert.Equal ((Key)'K', hotKey);
  289. // Cryllic K (К)
  290. text = "non-english: Кдать";
  291. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  292. Assert.True (result);
  293. Assert.Equal (13, hotPos);
  294. Assert.Equal ((Key)'К', hotKey);
  295. }
  296. [Fact]
  297. public void FindHotKey_Legacy_FirstUpperCase_NotFound_Returns_False ()
  298. {
  299. bool supportFirstUpperCase = true;
  300. var text = ustring.Empty;
  301. Rune hotKeySpecifier = (Rune)0;
  302. int hotPos = 0;
  303. Key hotKey = Key.Unknown;
  304. bool result = false;
  305. text = "k before";
  306. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  307. Assert.False (result);
  308. Assert.Equal (-1, hotPos);
  309. Assert.Equal (Key.Unknown, hotKey);
  310. text = "ak second";
  311. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  312. Assert.False (result);
  313. Assert.Equal (-1, hotPos);
  314. Assert.Equal (Key.Unknown, hotKey);
  315. text = "last k";
  316. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  317. Assert.False (result);
  318. Assert.Equal (-1, hotPos);
  319. Assert.Equal (Key.Unknown, hotKey);
  320. text = "multiple k and r";
  321. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  322. Assert.False (result);
  323. Assert.Equal (-1, hotPos);
  324. Assert.Equal (Key.Unknown, hotKey);
  325. text = "12345";
  326. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  327. Assert.False (result);
  328. Assert.Equal (-1, hotPos);
  329. Assert.Equal (Key.Unknown, hotKey);
  330. // punctuation
  331. text = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?";
  332. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  333. Assert.False (result);
  334. Assert.Equal (-1, hotPos);
  335. Assert.Equal (Key.Unknown, hotKey);
  336. // ~IsLetterOrDigit + Unicode
  337. text = " ~  s  gui.cs   master ↑10";
  338. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  339. Assert.False (result);
  340. Assert.Equal (-1, hotPos);
  341. Assert.Equal (Key.Unknown, hotKey);
  342. // Lower case Cryllic K (к)
  343. text = "non-english: кдать";
  344. result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey);
  345. Assert.False (result);
  346. Assert.Equal (-1, hotPos);
  347. Assert.Equal (Key.Unknown, hotKey);
  348. }
  349. static ustring testHotKeyAtStart = "_K Before";
  350. static ustring testHotKeyAtSecondPos = "a_K Second";
  351. static ustring testHotKeyAtLastPos = "Last _K";
  352. static ustring testHotKeyAfterLastChar = "After K_";
  353. static ustring testMultiHotKeys = "Multiple _K and _R";
  354. static ustring testNonEnglish = "Non-english: _Кдать";
  355. [Fact]
  356. public void RemoveHotKeySpecifier_InValid_ReturnsOriginal ()
  357. {
  358. Rune hotKeySpecifier = '_';
  359. Assert.Null (TextFormatter.RemoveHotKeySpecifier (null, 0, hotKeySpecifier));
  360. Assert.Equal ("", TextFormatter.RemoveHotKeySpecifier ("", 0, hotKeySpecifier));
  361. Assert.Equal ("", TextFormatter.RemoveHotKeySpecifier ("", -1, hotKeySpecifier));
  362. Assert.Equal ("", TextFormatter.RemoveHotKeySpecifier ("", 100, hotKeySpecifier));
  363. Assert.Equal ("a", TextFormatter.RemoveHotKeySpecifier ("a", -1, hotKeySpecifier));
  364. Assert.Equal ("a", TextFormatter.RemoveHotKeySpecifier ("a", 100, hotKeySpecifier));
  365. }
  366. [Fact]
  367. public void RemoveHotKeySpecifier_Valid_ReturnsStripped ()
  368. {
  369. Rune hotKeySpecifier = '_';
  370. Assert.Equal ("K Before", TextFormatter.RemoveHotKeySpecifier ("_K Before", 0, hotKeySpecifier));
  371. Assert.Equal ("aK Second", TextFormatter.RemoveHotKeySpecifier ("a_K Second", 1, hotKeySpecifier));
  372. Assert.Equal ("Last K", TextFormatter.RemoveHotKeySpecifier ("Last _K", 5, hotKeySpecifier));
  373. Assert.Equal ("After K", TextFormatter.RemoveHotKeySpecifier ("After K_", 7, hotKeySpecifier));
  374. Assert.Equal ("Multiple K and _R", TextFormatter.RemoveHotKeySpecifier ("Multiple _K and _R", 9, hotKeySpecifier));
  375. Assert.Equal ("Non-english: Кдать", TextFormatter.RemoveHotKeySpecifier ("Non-english: _Кдать", 13, hotKeySpecifier));
  376. }
  377. [Fact]
  378. public void RemoveHotKeySpecifier_Valid_Legacy_ReturnsOriginal ()
  379. {
  380. Rune hotKeySpecifier = '_';
  381. Assert.Equal ("all lower case", TextFormatter.RemoveHotKeySpecifier ("all lower case", 0, hotKeySpecifier));
  382. Assert.Equal ("K Before", TextFormatter.RemoveHotKeySpecifier ("K Before", 0, hotKeySpecifier));
  383. Assert.Equal ("aK Second", TextFormatter.RemoveHotKeySpecifier ("aK Second", 1, hotKeySpecifier));
  384. Assert.Equal ("Last K", TextFormatter.RemoveHotKeySpecifier ("Last K", 5, hotKeySpecifier));
  385. Assert.Equal ("After K", TextFormatter.RemoveHotKeySpecifier ("After K", 7, hotKeySpecifier));
  386. Assert.Equal ("Multiple K and R", TextFormatter.RemoveHotKeySpecifier ("Multiple K and R", 9, hotKeySpecifier));
  387. Assert.Equal ("Non-english: Кдать", TextFormatter.RemoveHotKeySpecifier ("Non-english: Кдать", 13, hotKeySpecifier));
  388. }
  389. [Fact]
  390. public void CalcRect_Invalid_Returns_Empty ()
  391. {
  392. Assert.Equal (Rect.Empty, TextFormatter.CalcRect (0, 0, null));
  393. Assert.Equal (Rect.Empty, TextFormatter.CalcRect (0, 0, ""));
  394. Assert.Equal (Rect.Empty, TextFormatter.CalcRect (1, 2, ""));
  395. Assert.Equal (Rect.Empty, TextFormatter.CalcRect (-1, -2, ""));
  396. }
  397. [Fact]
  398. public void CalcRect_SingleLine_Returns_1High ()
  399. {
  400. var text = ustring.Empty;
  401. text = "test";
  402. Assert.Equal (new Rect (0, 0, text.RuneCount, 1), TextFormatter.CalcRect (0, 0, text));
  403. }
  404. [Fact]
  405. public void CalcRect_MultiLine_Returns_nHigh ()
  406. {
  407. var text = ustring.Empty;
  408. var lines = 0;
  409. text = "line1\nline2";
  410. lines = 2;
  411. Assert.Equal (new Rect (0, 0, 5, lines), TextFormatter.CalcRect (0, 0, text));
  412. text = "line1\nline2\nline3long!";
  413. lines = 3;
  414. Assert.Equal (new Rect (0, 0, 10, lines), TextFormatter.CalcRect (0, 0, text));
  415. text = "line1\nline2\n\n";
  416. lines = 4;
  417. Assert.Equal (new Rect (0, 0, 5, lines), TextFormatter.CalcRect (0, 0, text));
  418. text = "line1\r\nline2";
  419. lines = 2;
  420. Assert.Equal (new Rect (0, 0, 5, lines), TextFormatter.CalcRect (0, 0, text));
  421. }
  422. [Fact]
  423. public void ClipAndJustify_Invalid_Returns_Original ()
  424. {
  425. var text = ustring.Empty;
  426. Assert.Equal (text, TextFormatter.ClipAndJustify (text, 0, TextAlignment.Left));
  427. text = null;
  428. Assert.Equal (text, TextFormatter.ClipAndJustify (text, 0, TextAlignment.Left));
  429. text = "test";
  430. Assert.Throws<ArgumentOutOfRangeException> (() => TextFormatter.ClipAndJustify (text, -1, TextAlignment.Left));
  431. }
  432. [Fact]
  433. public void ClipAndJustify_Valid_Left ()
  434. {
  435. var align = TextAlignment.Left;
  436. var text = ustring.Empty;
  437. var justifiedText = ustring.Empty;
  438. int width = 0;
  439. text = "test";
  440. width = 0;
  441. Assert.Equal (ustring.Empty, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  442. text = "test";
  443. width = 2;
  444. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  445. text = "test";
  446. width = int.MaxValue;
  447. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  448. Assert.True (justifiedText.RuneCount <= width);
  449. text = "A sentence has words.";
  450. width = int.MaxValue;
  451. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  452. Assert.True (justifiedText.RuneCount <= width);
  453. text = "A sentence has words.";
  454. width = 10;
  455. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  456. Assert.True (justifiedText.RuneCount <= width);
  457. text = "A\tsentence\thas\twords.";
  458. width = int.MaxValue;
  459. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  460. Assert.True (justifiedText.RuneCount <= width);
  461. text = "A\tsentence\thas\twords.";
  462. width = 10;
  463. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  464. Assert.True (justifiedText.RuneCount <= width);
  465. text = "line1\nline2\nline3long!";
  466. width = int.MaxValue;
  467. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  468. Assert.True (justifiedText.RuneCount <= width);
  469. text = "line1\nline2\nline3long!";
  470. width = 10;
  471. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  472. Assert.True (justifiedText.RuneCount <= width);
  473. text = " ~  s  gui.cs   master ↑10";
  474. width = 10;
  475. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  476. Assert.True (justifiedText.RuneCount <= width);
  477. }
  478. [Fact]
  479. public void ClipAndJustify_Valid_Right ()
  480. {
  481. var align = TextAlignment.Right;
  482. var text = ustring.Empty;
  483. var justifiedText = ustring.Empty;
  484. int width = 0;
  485. text = "test";
  486. width = 0;
  487. Assert.Equal (ustring.Empty, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  488. text = "test";
  489. width = 2;
  490. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  491. text = "test";
  492. width = int.MaxValue;
  493. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  494. Assert.True (justifiedText.RuneCount <= width);
  495. text = "A sentence has words.";
  496. width = int.MaxValue;
  497. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  498. Assert.True (justifiedText.RuneCount <= width);
  499. text = "A sentence has words.";
  500. width = 10;
  501. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  502. Assert.True (justifiedText.RuneCount <= width);
  503. text = "A\tsentence\thas\twords.";
  504. width = int.MaxValue;
  505. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  506. Assert.True (justifiedText.RuneCount <= width);
  507. text = "A\tsentence\thas\twords.";
  508. width = 10;
  509. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  510. Assert.True (justifiedText.RuneCount <= width);
  511. text = "line1\nline2\nline3long!";
  512. width = int.MaxValue;
  513. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  514. Assert.True (justifiedText.RuneCount <= width);
  515. text = "line1\nline2\nline3long!";
  516. width = 10;
  517. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  518. Assert.True (justifiedText.RuneCount <= width);
  519. text = " ~  s  gui.cs   master ↑10";
  520. width = 10;
  521. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  522. Assert.True (justifiedText.RuneCount <= width);
  523. }
  524. [Fact]
  525. public void ClipAndJustify_Valid_Centered ()
  526. {
  527. var align = TextAlignment.Centered;
  528. var text = ustring.Empty;
  529. var justifiedText = ustring.Empty;
  530. int width = 0;
  531. text = "test";
  532. width = 0;
  533. Assert.Equal (ustring.Empty, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  534. text = "test";
  535. width = 2;
  536. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  537. text = "test";
  538. width = int.MaxValue;
  539. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  540. Assert.True (justifiedText.RuneCount <= width);
  541. text = "A sentence has words.";
  542. width = int.MaxValue;
  543. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  544. Assert.True (justifiedText.RuneCount <= width);
  545. text = "A sentence has words.";
  546. width = 10;
  547. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  548. Assert.True (justifiedText.RuneCount <= width);
  549. text = "A\tsentence\thas\twords.";
  550. width = int.MaxValue;
  551. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  552. Assert.True (justifiedText.RuneCount <= width);
  553. text = "A\tsentence\thas\twords.";
  554. width = 10;
  555. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  556. Assert.True (justifiedText.RuneCount <= width);
  557. text = "line1\nline2\nline3long!";
  558. width = int.MaxValue;
  559. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  560. Assert.True (justifiedText.RuneCount <= width);
  561. text = "line1\nline2\nline3long!";
  562. width = 10;
  563. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  564. Assert.True (justifiedText.RuneCount <= width);
  565. text = " ~  s  gui.cs   master ↑10";
  566. width = 10;
  567. Assert.Equal (text [0, width], justifiedText = TextFormatter.ClipAndJustify (text, width, align));
  568. Assert.True (justifiedText.RuneCount <= width);
  569. text = "";
  570. width = text.RuneCount;
  571. Assert.Equal (text, justifiedText = TextFormatter.ClipAndJustify (text, width, align)); ;
  572. Assert.True (justifiedText.RuneCount <= width);
  573. }
  574. [Fact]
  575. public void ClipAndJustify_Valid_Justified ()
  576. {
  577. var text = ustring.Empty;
  578. int width = 0;
  579. var align = TextAlignment.Justified;
  580. text = "test";
  581. width = 0;
  582. Assert.Equal (ustring.Empty, TextFormatter.ClipAndJustify (text, width, align));
  583. text = "test";
  584. width = 2;
  585. Assert.Equal (text [0, width], TextFormatter.ClipAndJustify (text, width, align));
  586. text = "test";
  587. width = int.MaxValue;
  588. Assert.Equal (text, TextFormatter.ClipAndJustify (text, width, align));
  589. Assert.True (text.RuneCount <= width);
  590. // see Justify_ tests below
  591. }
  592. [Fact]
  593. public void Justify_Invalid ()
  594. {
  595. var text = ustring.Empty;
  596. Assert.Equal (text, TextFormatter.Justify (text, 0));
  597. text = null;
  598. Assert.Equal (text, TextFormatter.Justify (text, 0));
  599. text = "test";
  600. Assert.Throws<ArgumentOutOfRangeException> (() => TextFormatter.Justify (text, -1));
  601. }
  602. [Fact]
  603. public void Justify_SingleWord ()
  604. {
  605. var text = ustring.Empty;
  606. var justifiedText = ustring.Empty;
  607. int width = 0;
  608. char fillChar = '+';
  609. text = "word";
  610. justifiedText = "word";
  611. width = text.RuneCount;
  612. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  613. text = "word";
  614. justifiedText = "word";
  615. width = text.RuneCount + 1;
  616. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  617. text = "word";
  618. justifiedText = "word";
  619. width = text.RuneCount + 2;
  620. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  621. text = "word";
  622. justifiedText = "word";
  623. width = text.RuneCount + 10;
  624. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  625. text = "word";
  626. justifiedText = "word";
  627. width = text.RuneCount + 11;
  628. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  629. }
  630. [Fact]
  631. public void Justify_Sentence ()
  632. {
  633. var text = ustring.Empty;
  634. var justifiedText = ustring.Empty;
  635. int width = 0;
  636. char fillChar = '+';
  637. text = "A sentence has words.";
  638. justifiedText = "A+sentence+has+words.";
  639. width = text.RuneCount;
  640. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  641. Assert.True (justifiedText.RuneCount <= width);
  642. text = "A sentence has words.";
  643. justifiedText = "A+sentence+has+words.";
  644. width = text.RuneCount + 1;
  645. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  646. Assert.True (justifiedText.RuneCount <= width);
  647. text = "A sentence has words.";
  648. justifiedText = "A+sentence+has+words.";
  649. width = text.RuneCount + 2;
  650. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  651. Assert.True (justifiedText.RuneCount <= width);
  652. text = "A sentence has words.";
  653. justifiedText = "A++sentence++has++words.";
  654. width = text.RuneCount + 3;
  655. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  656. Assert.True (justifiedText.RuneCount <= width);
  657. text = "A sentence has words.";
  658. justifiedText = "A++sentence++has++words.";
  659. width = text.RuneCount + 4;
  660. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  661. Assert.True (justifiedText.RuneCount <= width);
  662. text = "A sentence has words.";
  663. justifiedText = "A++sentence++has++words.";
  664. width = text.RuneCount + 5;
  665. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  666. Assert.True (justifiedText.RuneCount <= width);
  667. text = "A sentence has words.";
  668. justifiedText = "A+++sentence+++has+++words.";
  669. width = text.RuneCount + 6;
  670. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  671. Assert.True (justifiedText.RuneCount <= width);
  672. text = "A sentence has words.";
  673. justifiedText = "A+++++++sentence+++++++has+++++++words.";
  674. width = text.RuneCount + 20;
  675. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  676. Assert.True (justifiedText.RuneCount <= width);
  677. text = "A sentence has words.";
  678. justifiedText = "A++++++++sentence++++++++has++++++++words.";
  679. width = text.RuneCount + 23;
  680. Assert.Equal (justifiedText.ToString (), TextFormatter.Justify (text, width, fillChar).ToString ());
  681. Assert.True (justifiedText.RuneCount <= width);
  682. //TODO: Unicode
  683. }
  684. [Fact]
  685. public void WordWrap_Invalid ()
  686. {
  687. var text = ustring.Empty;
  688. int width = 0;
  689. Assert.Empty (TextFormatter.WordWrap (null, width));
  690. Assert.Empty (TextFormatter.WordWrap (text, width));
  691. Assert.Throws<ArgumentOutOfRangeException> (() => TextFormatter.WordWrap (text, -1));
  692. }
  693. [Fact]
  694. public void WordWrap_SingleWordLine ()
  695. {
  696. var text = ustring.Empty;
  697. int width = 0;
  698. List<ustring> wrappedLines;
  699. text = "Constantinople";
  700. width = text.RuneCount;
  701. wrappedLines = TextFormatter.WordWrap (text, width);
  702. Assert.True (wrappedLines.Count == 1);
  703. width = text.RuneCount - 1;
  704. wrappedLines = TextFormatter.WordWrap (text, width);
  705. Assert.Equal (2, wrappedLines.Count);
  706. Assert.Equal (text [0, text.RuneCount - 1].ToString (), wrappedLines [0].ToString ());
  707. Assert.Equal ("e", wrappedLines [1].ToString ());
  708. width = text.RuneCount - 2;
  709. wrappedLines = TextFormatter.WordWrap (text, width);
  710. Assert.Equal (2, wrappedLines.Count);
  711. Assert.Equal (text [0, text.RuneCount - 2].ToString (), wrappedLines [0].ToString ());
  712. width = text.RuneCount - 5;
  713. wrappedLines = TextFormatter.WordWrap (text, width);
  714. Assert.Equal (2, wrappedLines.Count);
  715. width = (int)Math.Ceiling ((double)(text.RuneCount / 2F));
  716. wrappedLines = TextFormatter.WordWrap (text, width);
  717. Assert.Equal (2, wrappedLines.Count);
  718. Assert.Equal ("Constan", wrappedLines [0].ToString ());
  719. Assert.Equal ("tinople", wrappedLines [1].ToString ());
  720. width = (int)Math.Ceiling ((double)(text.RuneCount / 3F));
  721. wrappedLines = TextFormatter.WordWrap (text, width);
  722. Assert.Equal (3, wrappedLines.Count);
  723. Assert.Equal ("Const", wrappedLines [0].ToString ());
  724. Assert.Equal ("antin", wrappedLines [1].ToString ());
  725. Assert.Equal ("ople", wrappedLines [2].ToString ());
  726. width = (int)Math.Ceiling ((double)(text.RuneCount / 4F));
  727. wrappedLines = TextFormatter.WordWrap (text, width);
  728. Assert.Equal (4, wrappedLines.Count);
  729. width = (int)Math.Ceiling ((double)text.RuneCount / text.RuneCount);
  730. wrappedLines = TextFormatter.WordWrap (text, width);
  731. Assert.Equal (text.RuneCount, wrappedLines.Count);
  732. Assert.Equal ("C", wrappedLines [0].ToString ());
  733. Assert.Equal ("o", wrappedLines [1].ToString ());
  734. Assert.Equal ("n", wrappedLines [2].ToString ());
  735. Assert.Equal ("s", wrappedLines [3].ToString ());
  736. Assert.Equal ("t", wrappedLines [4].ToString ());
  737. Assert.Equal ("a", wrappedLines [5].ToString ());
  738. Assert.Equal ("n", wrappedLines [6].ToString ());
  739. Assert.Equal ("t", wrappedLines [7].ToString ());
  740. Assert.Equal ("i", wrappedLines [8].ToString ());
  741. Assert.Equal ("n", wrappedLines [9].ToString ());
  742. Assert.Equal ("o", wrappedLines [10].ToString ());
  743. Assert.Equal ("p", wrappedLines [11].ToString ());
  744. Assert.Equal ("l", wrappedLines [12].ToString ());
  745. Assert.Equal ("e", wrappedLines [13].ToString ());
  746. }
  747. [Fact]
  748. public void WordWrap_NoNewLines ()
  749. {
  750. var text = ustring.Empty;
  751. int width = 0;
  752. List<ustring> wrappedLines;
  753. text = "A sentence has words.";
  754. width = text.RuneCount;
  755. wrappedLines = TextFormatter.WordWrap (text, width);
  756. Assert.True (wrappedLines.Count == 1);
  757. width = text.RuneCount - 1;
  758. wrappedLines = TextFormatter.WordWrap (text, width);
  759. Assert.Equal (2, wrappedLines.Count);
  760. Assert.Equal ("A sentence has", wrappedLines [0].ToString ());
  761. Assert.Equal ("words.", wrappedLines [1].ToString ());
  762. width = text.RuneCount - "words.".Length;
  763. wrappedLines = TextFormatter.WordWrap (text, width);
  764. Assert.Equal (2, wrappedLines.Count);
  765. Assert.Equal ("A sentence has", wrappedLines [0].ToString ());
  766. Assert.Equal ("words.", wrappedLines [1].ToString ());
  767. width = text.RuneCount - " words.".Length;
  768. wrappedLines = TextFormatter.WordWrap (text, width);
  769. Assert.Equal (2, wrappedLines.Count);
  770. Assert.Equal ("A sentence has", wrappedLines [0].ToString ());
  771. Assert.Equal ("words.", wrappedLines [1].ToString ());
  772. width = text.RuneCount - "s words.".Length;
  773. wrappedLines = TextFormatter.WordWrap (text, width);
  774. Assert.Equal (2, wrappedLines.Count);
  775. Assert.Equal ("A sentence", wrappedLines [0].ToString ());
  776. Assert.Equal ("has words.", wrappedLines [1].ToString ());
  777. // Unicode
  778. // TODO: Lots of bugs
  779. //text = "A Unicode sentence (пÑивеÑ) has words.";
  780. //width = text.RuneCount;
  781. //wrappedLines = TextFormatter.WordWrap (text, width);
  782. //Assert.True (wrappedLines.Count == 1);
  783. //width = text.RuneCount - 1;
  784. //wrappedLines = TextFormatter.WordWrap (text, width);
  785. //Assert.Equal (2, wrappedLines.Count);
  786. //Assert.Equal ("A Unicode sentence (пÑивеÑ) has", wrappedLines [0].ToString ());
  787. //Assert.Equal ("words.", wrappedLines [1].ToString ());
  788. //width = text.RuneCount - "words.".Length;
  789. //wrappedLines = TextFormatter.WordWrap (text, width);
  790. //Assert.Equal (2, wrappedLines.Count);
  791. //Assert.Equal ("A Unicode sentence (пÑивеÑ) has", wrappedLines [0].ToString ());
  792. //Assert.Equal ("words.", wrappedLines [1].ToString ());
  793. //width = text.RuneCount - " words.".Length;
  794. //wrappedLines = TextFormatter.WordWrap (text, width);
  795. //Assert.Equal (2, wrappedLines.Count);
  796. //Assert.Equal ("A Unicode sentence (пÑивеÑ) has", wrappedLines [0].ToString ());
  797. //Assert.Equal ("words.", wrappedLines [1].ToString ());
  798. //width = text.RuneCount - "s words.".Length;
  799. //wrappedLines = TextFormatter.WordWrap (text, width);
  800. //Assert.Equal (2, wrappedLines.Count);
  801. //Assert.Equal ("A Unicode sentence (пÑивеÑ)", wrappedLines [0].ToString ());
  802. //Assert.Equal ("has words.", wrappedLines [1].ToString ());
  803. //width = text.RuneCount - "веÑ) has words.".Length;
  804. //wrappedLines = TextFormatter.WordWrap (text, width);
  805. //Assert.Equal (2, wrappedLines.Count);
  806. //Assert.Equal ("A Unicode sentence", wrappedLines [0].ToString ());
  807. //Assert.Equal ("(пÑивеÑ) has words.", wrappedLines [1].ToString ());
  808. }
  809. [Fact]
  810. public void ReplaceHotKeyWithTag ()
  811. {
  812. ustring text = "test";
  813. int hotPos = 0;
  814. uint tag = 0x100000 | 't';
  815. Assert.Equal (ustring.Make (new Rune [] { tag, 'e', 's', 't' }), TextFormatter.ReplaceHotKeyWithTag (text, hotPos));
  816. tag = 0x100000 | 'e';
  817. hotPos = 1;
  818. Assert.Equal (ustring.Make (new Rune [] { 't', tag, 's', 't' }), TextFormatter.ReplaceHotKeyWithTag (text, hotPos));
  819. var result = TextFormatter.ReplaceHotKeyWithTag (text, hotPos);
  820. Assert.Equal ('e', (uint)(result.ToRunes () [1] & ~0x100000));
  821. text = "Ok";
  822. tag = 0x100000 | 'O';
  823. hotPos = 0;
  824. Assert.Equal (ustring.Make (new Rune [] { tag, 'k' }), result = TextFormatter.ReplaceHotKeyWithTag (text, hotPos));
  825. Assert.Equal ('O', (uint)(result.ToRunes () [0] & ~0x100000));
  826. text = "[◦ Ok ◦]";
  827. text = ustring.Make(new Rune [] { '[', '◦', ' ', 'O', 'k', ' ', '◦', ']' });
  828. var runes = text.ToRuneList ();
  829. Assert.Equal (text.RuneCount, runes.Count);
  830. Assert.Equal (text, ustring.Make(runes));
  831. tag = 0x100000 | 'O';
  832. hotPos = 3;
  833. Assert.Equal (ustring.Make (new Rune [] { '[', '◦', ' ', tag, 'k', ' ', '◦', ']' }), result = TextFormatter.ReplaceHotKeyWithTag (text, hotPos));
  834. Assert.Equal ('O', (uint)(result.ToRunes () [3] & ~0x100000));
  835. text = "^k";
  836. tag = '^';
  837. hotPos = 0;
  838. Assert.Equal (ustring.Make (new Rune [] { tag, 'k' }), result = TextFormatter.ReplaceHotKeyWithTag (text, hotPos));
  839. Assert.Equal ('^', (uint)(result.ToRunes () [0] & ~0x100000));
  840. }
  841. }
  842. }