You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

EncodingExtensionsTests.cs 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Text;
  2. using EncodingExtensions = LLama.Extensions.EncodingExtensions;
  3. namespace LLama.Unittest
  4. {
  5. public class EncodingExtensionsTests
  6. {
  7. private static void GetCharsTest(string str)
  8. {
  9. var bytes = Encoding.UTF8.GetBytes(str);
  10. var chars = new char[128];
  11. var count = EncodingExtensions.GetCharsImpl(Encoding.UTF8, bytes, chars);
  12. Assert.Equal(str.Length, count);
  13. Assert.True(chars[..count].SequenceEqual(str));
  14. }
  15. private static void GetCharCountTest(string str)
  16. {
  17. var bytes = Encoding.UTF8.GetBytes(str);
  18. var count = EncodingExtensions.GetCharCountImpl(Encoding.UTF8, bytes);
  19. Assert.Equal(str.Length, count);
  20. }
  21. [Fact]
  22. public void GetCharsEmptyString()
  23. {
  24. GetCharsTest("");
  25. }
  26. [Fact]
  27. public void GetCharsString()
  28. {
  29. GetCharsTest("Hello World");
  30. }
  31. [Fact]
  32. public void GetCharsChineseString()
  33. {
  34. GetCharsTest("猫坐在垫子上");
  35. }
  36. [Fact]
  37. public void GetCharCountEmptyString()
  38. {
  39. GetCharCountTest("");
  40. }
  41. [Fact]
  42. public void GetCharCountString()
  43. {
  44. GetCharCountTest("Hello World");
  45. }
  46. [Fact]
  47. public void GetCharCountChineseString()
  48. {
  49. GetCharCountTest("猫坐在垫子上");
  50. }
  51. }
  52. }