Merge pull request #6173 from Bond-009/tests5

Add test for ReadOnlySpan.Count extension
This commit is contained in:
Claus Vium 2021-06-12 08:08:46 +02:00 committed by GitHub
commit 93dbbfea03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -1048,7 +1048,7 @@ namespace Emby.Server.Implementations.Data
// TODO The following is an ugly performance optimization, but it's extremely unlikely that the data in the database would be malformed
var valueSpan = value.AsSpan();
var count = valueSpan.CountOccurrences('|') + 1;
var count = valueSpan.Count('|') + 1;
var position = 0;
var result = new ItemImageInfo[count];

View File

@ -1,7 +1,6 @@
#pragma warning disable CS1591
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
@ -28,7 +27,7 @@ namespace MediaBrowser.Controller.Extensions
/// <param name="value">The haystack to search in.</param>
/// <param name="needle">The character to search for.</param>
/// <returns>The number of occurrences of the [needle] character.</returns>
public static int CountOccurrences(this ReadOnlySpan<char> value, char needle)
public static int Count(this ReadOnlySpan<char> value, char needle)
{
var count = 0;
var length = value.Length;

View File

@ -0,0 +1,19 @@
using System;
using MediaBrowser.Controller.Extensions;
using Xunit;
namespace Jellyfin.Controller.Extensions.Tests
{
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));
}
}
}