2021-06-11 15:56:09 -07:00
|
|
|
using System;
|
|
|
|
using Xunit;
|
|
|
|
|
2021-06-19 09:02:33 -07:00
|
|
|
namespace Jellyfin.Extensions.Tests
|
2021-06-11 15:56:09 -07:00
|
|
|
{
|
|
|
|
public class StringExtensionsTests
|
|
|
|
{
|
2022-05-05 10:59:17 -07:00
|
|
|
[Theory]
|
|
|
|
[InlineData("", "")] // Identity edge-case (no diactritics)
|
|
|
|
[InlineData("Indiana Jones", "Indiana Jones")] // Identity (no diactritics)
|
|
|
|
[InlineData("a\ud800b", "ab")] // Invalid UTF-16 char stripping
|
2022-12-27 08:53:58 -07:00
|
|
|
[InlineData("åäö", "aao")] // Issue #7484
|
2022-05-05 10:59:17 -07:00
|
|
|
[InlineData("Jön", "Jon")] // Issue #7484
|
|
|
|
[InlineData("Jönssonligan", "Jonssonligan")] // Issue #7484
|
|
|
|
[InlineData("Kieślowski", "Kieslowski")] // Issue #7450
|
|
|
|
[InlineData("Cidadão Kane", "Cidadao Kane")] // Issue #7560
|
|
|
|
[InlineData("운명처럼 널 사랑해", "운명처럼 널 사랑해")] // Issue #6393 (Korean language support)
|
|
|
|
[InlineData("애타는 로맨스", "애타는 로맨스")] // Issue #6393
|
2022-12-27 09:02:23 -07:00
|
|
|
[InlineData("Le cœur a ses raisons", "Le coeur a ses raisons")] // Issue #8893
|
|
|
|
[InlineData("Béla Tarr", "Bela Tarr")] // Issue #8893
|
2022-05-05 10:59:17 -07:00
|
|
|
public void RemoveDiacritics_ValidInput_Corrects(string input, string expectedResult)
|
|
|
|
{
|
|
|
|
string result = input.RemoveDiacritics();
|
|
|
|
Assert.Equal(expectedResult, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[InlineData("", false)] // Identity edge-case (no diactritics)
|
|
|
|
[InlineData("Indiana Jones", false)] // Identity (no diactritics)
|
|
|
|
[InlineData("a\ud800b", true)] // Invalid UTF-16 char stripping
|
2022-12-27 08:53:58 -07:00
|
|
|
[InlineData("åäö", true)] // Issue #7484
|
2022-05-05 10:59:17 -07:00
|
|
|
[InlineData("Jön", true)] // Issue #7484
|
|
|
|
[InlineData("Jönssonligan", true)] // Issue #7484
|
|
|
|
[InlineData("Kieślowski", true)] // Issue #7450
|
|
|
|
[InlineData("Cidadão Kane", true)] // Issue #7560
|
|
|
|
[InlineData("운명처럼 널 사랑해", false)] // Issue #6393 (Korean language support)
|
|
|
|
[InlineData("애타는 로맨스", false)] // Issue #6393
|
2022-12-27 09:02:23 -07:00
|
|
|
[InlineData("Le cœur a ses raisons", true)] // Issue #8893
|
|
|
|
[InlineData("Béla Tarr", true)] // Issue #8893
|
2022-05-05 10:59:17 -07:00
|
|
|
public void HasDiacritics_ValidInput_Corrects(string input, bool expectedResult)
|
|
|
|
{
|
|
|
|
bool result = input.HasDiacritics();
|
|
|
|
Assert.Equal(expectedResult, result);
|
|
|
|
}
|
|
|
|
|
2021-06-11 15:56:09 -07:00
|
|
|
[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 11:53:31 -07:00
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[InlineData("", 'q', "")]
|
|
|
|
[InlineData("Banana split", ' ', "Banana")]
|
|
|
|
[InlineData("Banana split", 'q', "Banana split")]
|
2021-09-19 12:26:00 -07:00
|
|
|
[InlineData("Banana split 2", ' ', "Banana")]
|
2021-09-19 11:53:31 -07:00
|
|
|
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.", '.', "")]
|
2021-09-19 12:26:00 -07:00
|
|
|
[InlineData("Banana split 2", ' ', "2")]
|
2021-09-19 11:53:31 -07:00
|
|
|
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 15:56:09 -07:00
|
|
|
}
|
|
|
|
}
|