Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

FixedStringTests.cs 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. using System;
  2. using System.Globalization;
  3. using System.Threading;
  4. using NUnit.Framework;
  5. using Unity.Collections;
  6. using Unity.Collections.LowLevel.Unsafe;
  7. using System.Text;
  8. // change this to change the core type under test
  9. using FixedStringN = Unity.Collections.FixedString128Bytes;
  10. namespace Unity.Collections.Tests
  11. {
  12. internal static class FixedStringTestUtils
  13. {
  14. internal unsafe static void Junk<T>(ref this T fs)
  15. where T : unmanaged, INativeList<byte>, IUTF8Bytes
  16. {
  17. var bytes = fs.GetUnsafePtr();
  18. var cap = fs.Capacity;
  19. // Match MSVC stack init pattern
  20. UnsafeUtility.MemSet(bytes, 0xcc, cap);
  21. }
  22. internal unsafe static void AssertNullTerminated<T>(this T fs)
  23. where T : unmanaged, INativeList<byte>, IUTF8Bytes
  24. {
  25. Assert.AreEqual(0, fs.GetUnsafePtr()[fs.Length]);
  26. }
  27. }
  28. internal class FixedStringTests
  29. {
  30. [Test]
  31. public void FixedStringFormat()
  32. {
  33. Assert.AreEqual("1 0", FixedString.Format("{0} {1}", 1, 0));
  34. Assert.AreEqual("0.1 1.2", FixedString.Format("{0} {1}", 0.1f, 1.2f));
  35. Assert.AreEqual("error 500 in line 350: bubbly", FixedString.Format("error {0} in line {1}: {2}", 500, 350, "bubbly"));
  36. }
  37. [Test]
  38. public void FixedStringNFormatExtension1Params()
  39. {
  40. FixedStringN aa = default;
  41. aa.Junk();
  42. FixedStringN format = "{0}";
  43. FixedString32Bytes arg0 = "a";
  44. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0));
  45. Assert.AreEqual("a", aa);
  46. aa.AssertNullTerminated();
  47. }
  48. [Test]
  49. public void FixedStringNFormatExtension2Params()
  50. {
  51. FixedStringN aa = default;
  52. aa.Junk();
  53. FixedStringN format = "{0} {1}";
  54. FixedString32Bytes arg0 = "a";
  55. FixedString32Bytes arg1 = "b";
  56. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1));
  57. Assert.AreEqual("a b", aa);
  58. aa.AssertNullTerminated();
  59. }
  60. [Test]
  61. public void FixedStringNFormatExtension3Params()
  62. {
  63. FixedStringN aa = default;
  64. aa.Junk();
  65. FixedStringN format = "{0} {1} {2}";
  66. FixedString32Bytes arg0 = "a";
  67. FixedString32Bytes arg1 = "b";
  68. FixedString32Bytes arg2 = "c";
  69. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2));
  70. Assert.AreEqual("a b c", aa);
  71. aa.AssertNullTerminated();
  72. }
  73. [Test]
  74. public void FixedStringNFormatExtension4Params()
  75. {
  76. FixedStringN aa = default;
  77. aa.Junk();
  78. FixedStringN format = "{0} {1} {2} {3}";
  79. FixedString32Bytes arg0 = "a";
  80. FixedString32Bytes arg1 = "b";
  81. FixedString32Bytes arg2 = "c";
  82. FixedString32Bytes arg3 = "d";
  83. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3));
  84. Assert.AreEqual("a b c d", aa);
  85. aa.AssertNullTerminated();
  86. }
  87. [Test]
  88. public void FixedStringNFormatExtension5Params()
  89. {
  90. FixedStringN aa = default;
  91. aa.Junk();
  92. FixedStringN format = "{0} {1} {2} {3} {4}";
  93. FixedString32Bytes arg0 = "a";
  94. FixedString32Bytes arg1 = "b";
  95. FixedString32Bytes arg2 = "c";
  96. FixedString32Bytes arg3 = "d";
  97. FixedString32Bytes arg4 = "e";
  98. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4));
  99. Assert.AreEqual("a b c d e", aa);
  100. aa.AssertNullTerminated();
  101. }
  102. [Test]
  103. public void FixedStringNFormatExtension6Params()
  104. {
  105. FixedStringN aa = default;
  106. aa.Junk();
  107. FixedStringN format = "{0} {1} {2} {3} {4} {5}";
  108. FixedString32Bytes arg0 = "a";
  109. FixedString32Bytes arg1 = "b";
  110. FixedString32Bytes arg2 = "c";
  111. FixedString32Bytes arg3 = "d";
  112. FixedString32Bytes arg4 = "e";
  113. FixedString32Bytes arg5 = "f";
  114. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5));
  115. Assert.AreEqual("a b c d e f", aa);
  116. aa.AssertNullTerminated();
  117. }
  118. [Test]
  119. public void FixedStringNFormatExtension7Params()
  120. {
  121. FixedStringN aa = default;
  122. aa.Junk();
  123. FixedStringN format = "{0} {1} {2} {3} {4} {5} {6}";
  124. FixedString32Bytes arg0 = "a";
  125. FixedString32Bytes arg1 = "b";
  126. FixedString32Bytes arg2 = "c";
  127. FixedString32Bytes arg3 = "d";
  128. FixedString32Bytes arg4 = "e";
  129. FixedString32Bytes arg5 = "f";
  130. FixedString32Bytes arg6 = "g";
  131. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6));
  132. Assert.AreEqual("a b c d e f g", aa);
  133. aa.AssertNullTerminated();
  134. }
  135. [Test]
  136. public void FixedStringNFormatExtension8Params()
  137. {
  138. FixedStringN aa = default;
  139. aa.Junk();
  140. FixedStringN format = "{0} {1} {2} {3} {4} {5} {6} {7}";
  141. FixedString32Bytes arg0 = "a";
  142. FixedString32Bytes arg1 = "b";
  143. FixedString32Bytes arg2 = "c";
  144. FixedString32Bytes arg3 = "d";
  145. FixedString32Bytes arg4 = "e";
  146. FixedString32Bytes arg5 = "f";
  147. FixedString32Bytes arg6 = "g";
  148. FixedString32Bytes arg7 = "h";
  149. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7));
  150. Assert.AreEqual("a b c d e f g h", aa);
  151. aa.AssertNullTerminated();
  152. }
  153. [Test]
  154. public void FixedStringNFormatExtension9Params()
  155. {
  156. FixedStringN aa = default;
  157. aa.Junk();
  158. FixedStringN format = "{0} {1} {2} {3} {4} {5} {6} {7} {8}";
  159. FixedString32Bytes arg0 = "a";
  160. FixedString32Bytes arg1 = "b";
  161. FixedString32Bytes arg2 = "c";
  162. FixedString32Bytes arg3 = "d";
  163. FixedString32Bytes arg4 = "e";
  164. FixedString32Bytes arg5 = "f";
  165. FixedString32Bytes arg6 = "g";
  166. FixedString32Bytes arg7 = "h";
  167. FixedString32Bytes arg8 = "i";
  168. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8));
  169. Assert.AreEqual("a b c d e f g h i", aa);
  170. aa.AssertNullTerminated();
  171. }
  172. [Test]
  173. public void FixedStringNFormatExtension10Params()
  174. {
  175. FixedStringN aa = default;
  176. aa.Junk();
  177. FixedStringN format = "{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}";
  178. FixedString32Bytes arg0 = "a";
  179. FixedString32Bytes arg1 = "b";
  180. FixedString32Bytes arg2 = "c";
  181. FixedString32Bytes arg3 = "d";
  182. FixedString32Bytes arg4 = "e";
  183. FixedString32Bytes arg5 = "f";
  184. FixedString32Bytes arg6 = "g";
  185. FixedString32Bytes arg7 = "h";
  186. FixedString32Bytes arg8 = "i";
  187. FixedString32Bytes arg9 = "j";
  188. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9));
  189. Assert.AreEqual("a b c d e f g h i j", aa);
  190. aa.AssertNullTerminated();
  191. }
  192. [Test]
  193. public void FixedStringNFormatBadFormat()
  194. {
  195. FixedStringN aa = default;
  196. aa.Junk();
  197. FixedStringN format = "{10}";
  198. FixedString32Bytes arg0 = "a";
  199. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  200. format = "{0 } ";
  201. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  202. format = "{ 0} ";
  203. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  204. format = "{0a} ";
  205. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  206. format = "{012 ";
  207. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  208. format = "{0{ ";
  209. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  210. format = "{0{ ";
  211. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  212. format = "{0} } ";
  213. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  214. format = "{ {0} ";
  215. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  216. format = "{{{0}} ";
  217. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  218. format = "{{0} ";
  219. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  220. format = "{0}} ";
  221. Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
  222. aa.AssertNullTerminated();
  223. }
  224. [Test]
  225. public void FixedStringNFormatOverflow()
  226. {
  227. FixedString32Bytes aa = default;
  228. aa.Junk();
  229. FixedStringN format = "{0}";
  230. FixedStringN arg0 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  231. Assert.AreEqual(FormatError.Overflow, aa.AppendFormat(format, arg0));
  232. }
  233. [Test]
  234. public void FixedStringNFormatBraces()
  235. {
  236. FixedStringN aa = default;
  237. aa.Junk();
  238. FixedStringN format = "{{0}}";
  239. FixedString32Bytes arg0 = "42";
  240. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0));
  241. Assert.AreEqual("{0}", aa);
  242. aa.AssertNullTerminated();
  243. aa = default;
  244. format = "{{{0}}}";
  245. arg0 = "43";
  246. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0));
  247. Assert.AreEqual("{43}", aa);
  248. aa.AssertNullTerminated();
  249. aa = default;
  250. format = "{{{0}";
  251. arg0 = "44";
  252. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0));
  253. Assert.AreEqual("{44", aa);
  254. aa.AssertNullTerminated();
  255. aa = default;
  256. format = "{0}}}";
  257. arg0 = "45";
  258. Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0));
  259. Assert.AreEqual("45}", aa);
  260. aa.AssertNullTerminated();
  261. }
  262. [Test]
  263. public void FixedStringNAppendString()
  264. {
  265. FixedStringN aa = default;
  266. Assert.AreEqual(CopyError.None, aa.CopyFrom(new FixedString32Bytes("aa")));
  267. Assert.AreEqual("aa", aa.ToString());
  268. Assert.AreEqual(FormatError.None, aa.Append("bb"));
  269. Assert.AreEqual("aabb", aa.ToString());
  270. }
  271. [Test]
  272. public void FixedStringRuneWorks()
  273. {
  274. var rune = new Unicode.Rune(0xfbad);
  275. FixedStringN a = new FixedStringN(rune, 3);
  276. FixedStringN b = default;
  277. Assert.AreEqual(FormatError.None, b.Append(rune));
  278. Assert.AreEqual(FormatError.None, b.Append(rune, 2));
  279. Assert.AreEqual(a.ToString(), b.ToString());
  280. }
  281. [TestCase("Antidisestablishmentarianism")]
  282. [TestCase("⁣🌹🌻🌷🌿🌵🌾⁣")]
  283. public void FixedStringNCopyFromBytesWorks(String a)
  284. {
  285. FixedStringN aa = default;
  286. aa.Junk();
  287. Assert.AreEqual(CopyError.None, aa.CopyFrom(a));
  288. Assert.AreEqual(a, aa.ToString());
  289. aa.AssertNullTerminated();
  290. Assert.AreEqual(FormatError.None, aa.Append("tail"));
  291. Assert.AreEqual(a + "tail", aa.ToString());
  292. aa.AssertNullTerminated();
  293. }
  294. [TestCase("red")]
  295. [TestCase("紅色", TestName = "{m}(Chinese-Red)")]
  296. [TestCase("George Washington")]
  297. [TestCase("村上春樹", TestName = "{m}(HarukiMurakami)")]
  298. public void FixedStringNToStringWorks(String a)
  299. {
  300. FixedStringN aa = new FixedStringN(a);
  301. Assert.AreEqual(a, aa.ToString());
  302. aa.AssertNullTerminated();
  303. }
  304. [TestCase("monkey", "monkey")]
  305. [TestCase("yellow", "green")]
  306. [TestCase("violet", "紅色", TestName = "{m}(Violet-Chinese-Red")]
  307. [TestCase("绿色", "蓝色", TestName = "{m}(Chinese-Green-Blue")]
  308. [TestCase("靛蓝色", "紫罗兰色", TestName = "{m}(Chinese-Indigo-Violet")]
  309. [TestCase("James Monroe", "John Quincy Adams")]
  310. [TestCase("Andrew Jackson", "村上春樹", TestName = "{m}(AndrewJackson-HarukiMurakami")]
  311. [TestCase("三島 由紀夫", "吉本ばなな", TestName = "{m}(MishimaYukio-YoshimotoBanana")]
  312. public void FixedStringNEqualsWorks(String a, String b)
  313. {
  314. FixedStringN aa = new FixedStringN(a);
  315. FixedStringN bb = new FixedStringN(b);
  316. Assert.AreEqual(aa.Equals(bb), a.Equals(b));
  317. aa.AssertNullTerminated();
  318. bb.AssertNullTerminated();
  319. }
  320. [Test]
  321. public void FixedStringNForEach()
  322. {
  323. FixedStringN actual = "A🌕Z🌑";
  324. FixedList32Bytes<int> expected = default;
  325. expected.Add('A');
  326. expected.Add(0x1F315);
  327. expected.Add('Z');
  328. expected.Add(0x1F311);
  329. int index = 0;
  330. foreach (var rune in actual)
  331. {
  332. Assert.AreEqual(expected[index], rune.value);
  333. ++index;
  334. }
  335. }
  336. [Test]
  337. public void FixedStringNSubstring()
  338. {
  339. FixedStringN a = "This is substring.";
  340. #if ENABLE_UNITY_COLLECTIONS_CHECKS || UNITY_DOTS_DEBUG
  341. Assert.Throws<ArgumentOutOfRangeException>(() => a.Substring(-8, 9));
  342. Assert.Throws<ArgumentOutOfRangeException>(() => a.Substring(200, 9));
  343. Assert.Throws<ArgumentOutOfRangeException>(() => a.Substring(8, -9));
  344. #endif
  345. {
  346. FixedStringN b = a.Substring(8, 9);
  347. Assert.IsTrue(b.Equals("substring"));
  348. }
  349. {
  350. FixedStringN b = a.Substring(8, 100);
  351. Assert.IsTrue(b.Equals("substring."));
  352. }
  353. }
  354. [Test]
  355. public void FixedStringNIndexOf()
  356. {
  357. FixedStringN a = "bookkeeper bookkeeper";
  358. FixedStringN b = "ookkee";
  359. Assert.AreEqual(1, a.IndexOf(b));
  360. Assert.AreEqual(-1, b.IndexOf(a));
  361. }
  362. [Test]
  363. public void FixedStringNLastIndexOf()
  364. {
  365. FixedStringN a = "bookkeeper bookkeeper";
  366. FixedStringN b = "ookkee";
  367. Assert.AreEqual(12, a.LastIndexOf(b));
  368. Assert.AreEqual(-1, b.LastIndexOf(a));
  369. }
  370. [Test]
  371. public void FixedStringNContains()
  372. {
  373. FixedStringN a = "bookkeeper";
  374. FixedStringN b = "ookkee";
  375. Assert.AreEqual(true, a.Contains(b));
  376. }
  377. [Test]
  378. public void FixedStringNComparisons()
  379. {
  380. FixedStringN a = "apple";
  381. FixedStringN b = "banana";
  382. Assert.AreEqual(false, a.Equals(b));
  383. Assert.AreEqual(true, !b.Equals(a));
  384. }
  385. [Test]
  386. public void FixedStringNSizeOf()
  387. {
  388. Assert.AreEqual(UnsafeUtility.SizeOf<FixedStringN>(), 128);
  389. }
  390. [TestCase("red", new byte[] { 3, 0, 114, 101, 100, 0 }, TestName = "{m}(red)")]
  391. [TestCase("紅色", new byte[] { 6, 0, 231, 180, 133, 232, 137, 178, 0 }, TestName = "{m}(Chinese-Red)")]
  392. [TestCase("црвена", new byte[] { 12, 0, 209, 134, 209, 128, 208, 178, 208, 181, 208, 189, 208, 176, 0 }, TestName = "{m}(Serbian-Red)")]
  393. [TestCase("George Washington", new byte[] { 17, 0, 71, 101, 111, 114, 103, 101, 32, 87, 97, 115, 104, 105, 110, 103, 116, 111, 110, 0 }, TestName = "{m}(George Washington)")]
  394. [TestCase("村上春樹", new byte[] { 12, 0, 230, 157, 145, 228, 184, 138, 230, 152, 165, 230, 168, 185, 0 }, TestName = "{m}(HarukiMurakami)")]
  395. [TestCase("🌕🌖🌗🌘🌑🌒🌓🌔", new byte[] { 32, 0, 240, 159, 140, 149, 240, 159, 140, 150, 240, 159, 140, 151, 240, 159, 140, 152, 240, 159, 140, 145, 240, 159, 140, 146, 240, 159, 140, 147, 240, 159, 140, 148, 0 }, TestName = "{m}(MoonPhases)")]
  396. [TestCase("𝒞𝒯𝒮𝒟𝒳𝒩𝒫𝒢", new byte[] { 32, 0, 240, 157, 146, 158, 240, 157, 146, 175, 240, 157, 146, 174, 240, 157, 146, 159, 240, 157, 146, 179, 240, 157, 146, 169, 240, 157, 146, 171, 240, 157, 146, 162, 0 }, TestName = "{m}(Cursive)")]
  397. [TestCase("로마는 하루아침에 이루어진 것이 아니다", new byte[] { 55, 0, 235, 161, 156, 235, 167, 136, 235, 138, 148, 32, 237, 149, 152, 235, 163, 168, 236, 149, 132, 236, 185, 168, 236, 151, 144, 32, 236, 157, 180, 235, 163, 168, 236, 150, 180, 236, 167, 132, 32, 234, 178, 131, 236, 157, 180, 32, 236, 149, 132, 235, 139, 136, 235, 139, 164, 0 }, TestName = "{m}(Korean - Rome was not made overnight)")]
  398. [TestCase("Лако ти је плитку воду замутити и будалу наљутити", new byte[] { 90, 0, 208, 155, 208, 176, 208, 186, 208, 190, 32, 209, 130, 208, 184, 32, 209, 152, 208, 181, 32, 208, 191, 208, 187, 208, 184, 209, 130, 208, 186, 209, 131, 32, 208, 178, 208, 190, 208, 180, 209, 131, 32, 208, 183, 208, 176, 208, 188, 209, 131, 209, 130, 208, 184, 209, 130, 208, 184, 32, 208, 184, 32, 208, 177, 209, 131, 208, 180, 208, 176, 208, 187, 209, 131, 32, 208, 189, 208, 176, 209, 153, 209, 131, 209, 130, 208, 184, 209, 130, 208, 184, 0 }, TestName = "{m}(Serbian-Proverb)")]
  399. [TestCase("Үнэн үг хэлсэн хүнд ноёд өстэй, үхэр унасан хүнд ноход өстэй.", new byte[] { 110, 0, 210, 174, 208, 189, 209, 141, 208, 189, 32, 210, 175, 208, 179, 32, 209, 133, 209, 141, 208, 187, 209, 129, 209, 141, 208, 189, 32, 209, 133, 210, 175, 208, 189, 208, 180, 32, 208, 189, 208, 190, 209, 145, 208, 180, 32, 211, 169, 209, 129, 209, 130, 209, 141, 208, 185, 44, 32, 210, 175, 209, 133, 209, 141, 209, 128, 32, 209, 131, 208, 189, 208, 176, 209, 129, 208, 176, 208, 189, 32, 209, 133, 210, 175, 208, 189, 208, 180, 32, 208, 189, 208, 190, 209, 133, 208, 190, 208, 180, 32, 211, 169, 209, 129, 209, 130, 209, 141, 208, 185, 46, 0 }, TestName = "{m}(Mongolian-Proverb1)")]
  400. unsafe public void FixedStringNLayout(String a, byte[] expected)
  401. {
  402. fixed (byte* expectedBytes = expected)
  403. {
  404. FixedStringN actual = a;
  405. byte* actualBytes = (byte*)&actual;
  406. Assert.AreEqual(0, UnsafeUtility.MemCmp(expectedBytes, actualBytes, expected.Length));
  407. }
  408. }
  409. [TestCase("red", 'r', 'd')]
  410. [TestCase("紅色", '紅', '色')]
  411. [TestCase("црвена", 'ц', 'а')]
  412. [TestCase("George Washington", 'G', 'n')]
  413. [TestCase("村上春樹", '村', '樹')]
  414. [TestCase("로마는 하루아침에 이루어진 것이 아니다", '로', '다')]
  415. [TestCase("Лако ти је плитку воду замутити и будалу наљутити", 'Л', 'и')]
  416. [TestCase("Үнэн үг хэлсэн хүнд ноёд өстэй, үхэр унасан хүнд ноход өстэй.", 'Ү', '.')]
  417. public void FixedStringStartsEndsWithChar(String a, char starts, char ends)
  418. {
  419. FixedStringN actual = a;
  420. Assert.True(actual.StartsWith(starts));
  421. Assert.True(actual.EndsWith(ends));
  422. }
  423. [TestCase("red", "r", "d")]
  424. [TestCase("紅色", "紅", "色")]
  425. [TestCase("црвена", "црв", "ена")]
  426. [TestCase("George Washington", "George", "Washington")]
  427. [TestCase("村上春樹", "村上", "春樹")]
  428. [TestCase("🌕🌖🌗🌘🌑🌒🌓🌔", "🌕🌖🌗", "🌒🌓🌔")]
  429. [TestCase("𝒞𝒯𝒮𝒟𝒳𝒩𝒫𝒢", "𝒞𝒯𝒮", "𝒩𝒫𝒢")]
  430. [TestCase("로마는 하루아침에 이루어진 것이 아니다", "로마는", "아니다")]
  431. [TestCase("Лако ти је плитку воду замутити и будалу наљутити", "Лако", "наљутити")]
  432. [TestCase("Үнэн үг хэлсэн хүнд ноёд өстэй, үхэр унасан хүнд ноход өстэй.", "Үнэн", "өстэй.")]
  433. public void FixedStringStartsEndsWithString(String a, String starts, String ends)
  434. {
  435. FixedStringN actual = a;
  436. Assert.True(actual.StartsWith((FixedStringN)starts));
  437. Assert.True(actual.EndsWith((FixedStringN)ends));
  438. }
  439. [TestCase("red ", ' ', "red ", "red", "red")]
  440. [TestCase(" red ", ' ', "red ", " red", "red")]
  441. [TestCase(" ", ' ', "", "", "")]
  442. public void FixedStringTrimStart(String a, char trim, String expectedStart, String expectedEnd, String expected)
  443. {
  444. FixedStringN actual = a;
  445. Assert.AreEqual(expectedStart, actual.TrimStart());
  446. Assert.AreEqual(expectedEnd, actual.TrimEnd());
  447. Assert.AreEqual(expected, actual.Trim());
  448. }
  449. [TestCase(" red ", "ed ", " red", "ed")]
  450. [TestCase("црвена", "црвена", "црвена", "црвена")]
  451. [TestCase(" ", "", "", "")]
  452. public void FixedStringTrimStartWithRunes(String a, String expectedStart, String expectedEnd, String expected)
  453. {
  454. FixedStringN actual = a;
  455. Assert.AreEqual(expectedStart, actual.TrimStart(new Unicode.Rune[]{ ' ', 'r'}));
  456. Assert.AreEqual(expectedEnd, actual.TrimEnd(new Unicode.Rune[] { ' ', 'r' }));
  457. Assert.AreEqual(expected, actual.Trim(new Unicode.Rune[] { ' ', 'r' }));
  458. }
  459. [TestCase("Red", "red", "RED")]
  460. [TestCase("црвена", "црвена", "црвена")]
  461. [TestCase(" ", " ", " ")]
  462. public void FixedStringToLowerUpperAscii(String a, String expectedLower, String expectedUpped)
  463. {
  464. FixedStringN actual = a;
  465. Assert.AreEqual(expectedLower, actual.ToLowerAscii());
  466. Assert.AreEqual(expectedUpped, actual.ToUpperAscii());
  467. }
  468. }
  469. }