jellyfin/tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs

44 lines
1.8 KiB
C#
Raw Normal View History

2020-04-19 13:18:28 +00:00
using System;
using MediaBrowser.Common.Extensions;
using Xunit;
namespace Jellyfin.Common.Tests.Extensions
{
public class StringExtensionsTests
{
[Theory]
2020-04-21 08:18:26 +00:00
[InlineData("", 'q', "")]
2020-04-19 13:18:28 +00:00
[InlineData("Banana split", ' ', "Banana")]
[InlineData("Banana split", 'q', "Banana split")]
2020-04-21 08:18:26 +00:00
public void LeftPart_ValidArgsCharNeedle_Correct(string str, char needle, string expectedResult)
2020-04-19 13:18:28 +00:00
{
2020-04-21 08:18:26 +00:00
var result = str.AsSpan().LeftPart(needle).ToString();
Assert.Equal(expectedResult, result);
2020-04-19 13:18:28 +00:00
}
[Theory]
2020-04-21 08:18:26 +00:00
[InlineData("", "", "")]
[InlineData("", "q", "")]
[InlineData("Banana split", "", "")]
2020-04-19 13:18:28 +00:00
[InlineData("Banana split", " ", "Banana")]
[InlineData("Banana split test", " split", "Banana")]
2020-04-21 08:18:26 +00:00
public void LeftPart_ValidArgsWithoutStringComparison_Correct(string str, string needle, string expectedResult)
2020-04-19 13:18:28 +00:00
{
2020-04-21 08:18:26 +00:00
var result = str.AsSpan().LeftPart(needle).ToString();
Assert.Equal(expectedResult, result);
2020-04-19 13:18:28 +00:00
}
[Theory]
2020-04-21 08:18:26 +00:00
[InlineData("", "", StringComparison.Ordinal, "")]
2020-04-19 13:18:28 +00:00
[InlineData("Banana split", " ", StringComparison.Ordinal, "Banana")]
[InlineData("Banana split test", " split", StringComparison.Ordinal, "Banana")]
[InlineData("Banana split test", " Split", StringComparison.Ordinal, "Banana split test")]
[InlineData("Banana split test", " Splït", StringComparison.InvariantCultureIgnoreCase, "Banana split test")]
2020-04-21 08:18:26 +00:00
public void LeftPart_ValidArgs_Correct(string str, string needle, StringComparison stringComparison, string expectedResult)
2020-04-19 13:18:28 +00:00
{
2020-04-21 08:18:26 +00:00
var result = str.AsSpan().LeftPart(needle, stringComparison).ToString();
Assert.Equal(expectedResult, result);
2020-04-19 13:18:28 +00:00
}
}
}