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