Merge pull request #6173 from Bond-009/tests5
Add test for ReadOnlySpan.Count extension
This commit is contained in:
commit
93dbbfea03
|
@ -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
|
// 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 valueSpan = value.AsSpan();
|
||||||
var count = valueSpan.CountOccurrences('|') + 1;
|
var count = valueSpan.Count('|') + 1;
|
||||||
|
|
||||||
var position = 0;
|
var position = 0;
|
||||||
var result = new ItemImageInfo[count];
|
var result = new ItemImageInfo[count];
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -28,7 +27,7 @@ namespace MediaBrowser.Controller.Extensions
|
||||||
/// <param name="value">The haystack to search in.</param>
|
/// <param name="value">The haystack to search in.</param>
|
||||||
/// <param name="needle">The character to search for.</param>
|
/// <param name="needle">The character to search for.</param>
|
||||||
/// <returns>The number of occurrences of the [needle] character.</returns>
|
/// <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 count = 0;
|
||||||
var length = value.Length;
|
var length = value.Length;
|
||||||
|
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user