2021-06-11 22:56:09 +00:00
|
|
|
using System;
|
|
|
|
using Xunit;
|
|
|
|
|
2021-06-19 16:02:33 +00:00
|
|
|
namespace Jellyfin.Extensions.Tests
|
2021-06-11 22:56:09 +00:00
|
|
|
{
|
|
|
|
public class StringExtensionsTests
|
|
|
|
{
|
|
|
|
[Theory]
|
|
|
|
[InlineData("", '_', 0)]
|
|
|
|
[InlineData("___", '_', 3)]
|
|
|
|
[InlineData("test\x00", '\x00', 1)]
|
|
|
|
[InlineData("Imdb=tt0119567|Tmdb=330|TmdbCollection=328", '|', 2)]
|
|
|
|
public void ReadOnlySpan_Count_Success(string str, char needle, int count)
|
|
|
|
{
|
|
|
|
Assert.Equal(count, str.AsSpan().Count(needle));
|
|
|
|
}
|
2021-09-19 18:53:31 +00:00
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[InlineData("", 'q', "")]
|
|
|
|
[InlineData("Banana split", ' ', "Banana")]
|
|
|
|
[InlineData("Banana split", 'q', "Banana split")]
|
|
|
|
public void LeftPart_ValidArgsCharNeedle_Correct(string str, char needle, string expectedResult)
|
|
|
|
{
|
|
|
|
var result = str.AsSpan().LeftPart(needle).ToString();
|
|
|
|
Assert.Equal(expectedResult, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[InlineData("", 'q', "")]
|
|
|
|
[InlineData("Banana split", ' ', "split")]
|
|
|
|
[InlineData("Banana split", 'q', "Banana split")]
|
|
|
|
[InlineData("Banana split.", '.', "")]
|
|
|
|
public void RightPart_ValidArgsCharNeedle_Correct(string str, char needle, string expectedResult)
|
|
|
|
{
|
|
|
|
var result = str.AsSpan().RightPart(needle).ToString();
|
|
|
|
Assert.Equal(expectedResult, result);
|
|
|
|
}
|
2021-06-11 22:56:09 +00:00
|
|
|
}
|
|
|
|
}
|