2
0

StringHelperTests.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using FsCheck;
  3. using FsCheck.Fluent;
  4. using FsCheck.Xunit;
  5. using MediaBrowser.Model.Extensions;
  6. using Xunit;
  7. namespace Jellyfin.Model.Tests.Extensions
  8. {
  9. public class StringHelperTests
  10. {
  11. [Theory]
  12. [InlineData("", "")]
  13. [InlineData("banana", "Banana")]
  14. [InlineData("Banana", "Banana")]
  15. [InlineData("ä", "Ä")]
  16. [InlineData("\027", "\027")]
  17. public void StringHelper_ValidArgs_Success(string input, string expectedResult)
  18. {
  19. Assert.Equal(expectedResult, StringHelper.FirstToUpper(input));
  20. }
  21. [Property]
  22. public Property FirstToUpper_RandomArg_Correct(NonEmptyString input)
  23. {
  24. var result = StringHelper.FirstToUpper(input.Item);
  25. // We check IsLower instead of IsUpper because both return false for non-letters
  26. return (!char.IsLower(result[0])).Label("First char is uppercase")
  27. .And(input.Item.Length == 1 || result[1..].Equals(input.Item[1..], StringComparison.Ordinal)).Label("Remaining chars are unmodified");
  28. }
  29. }
  30. }