aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2020-04-21 10:18:26 +0200
committerBond_009 <bond.009@outlook.com>2020-04-21 10:18:26 +0200
commitc430a7ed8faa40788c32b89852310981b7c1cf83 (patch)
tree4622517191f8e074cd61c6d0a2810dbbdd89007f
parent958681cdffddc7ea24d92d126badb3372cfa5d41 (diff)
Address comments
-rw-r--r--Emby.Server.Implementations/Library/PathExtensions.cs2
-rw-r--r--MediaBrowser.Common/Extensions/StringExtensions.cs22
-rw-r--r--tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs20
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs4
4 files changed, 28 insertions, 20 deletions
diff --git a/Emby.Server.Implementations/Library/PathExtensions.cs b/Emby.Server.Implementations/Library/PathExtensions.cs
index b74cad067..06ff3e611 100644
--- a/Emby.Server.Implementations/Library/PathExtensions.cs
+++ b/Emby.Server.Implementations/Library/PathExtensions.cs
@@ -16,7 +16,7 @@ namespace Emby.Server.Implementations.Library
/// <param name="str">The STR.</param>
/// <param name="attribute">The attrib.</param>
/// <returns>System.String.</returns>
- /// <exception cref="ArgumentException"><c>str</c> or <c>attribute</c> is empty.</exception>
+ /// <exception cref="ArgumentException"><paramref name="str" /> or <paramref name="attribute" /> is empty.</exception>
public static string? GetAttributeValue(this string str, string attribute)
{
if (str.Length == 0)
diff --git a/MediaBrowser.Common/Extensions/StringExtensions.cs b/MediaBrowser.Common/Extensions/StringExtensions.cs
index 2ac29f8e5..764301741 100644
--- a/MediaBrowser.Common/Extensions/StringExtensions.cs
+++ b/MediaBrowser.Common/Extensions/StringExtensions.cs
@@ -10,28 +10,28 @@ namespace MediaBrowser.Common.Extensions
public static class StringExtensions
{
/// <summary>
- /// Returns the part left of the <c>needle</c>.
+ /// Returns the part on the left of the <c>needle</c>.
/// </summary>
- /// <param name="str">The string to seek.</param>
+ /// <param name="haystack">The string to seek.</param>
/// <param name="needle">The needle to find.</param>
- /// <returns>The part left of the <c>needle</c>.</returns>
- public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> str, char needle)
+ /// <returns>The part left of the <paramref name="needle" />.</returns>
+ public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, char needle)
{
- var pos = str.IndexOf(needle);
- return pos == -1 ? str : str[..pos];
+ var pos = haystack.IndexOf(needle);
+ return pos == -1 ? haystack : haystack[..pos];
}
/// <summary>
- /// Returns the part left of the <c>needle</c>.
+ /// Returns the part on the left of the <c>needle</c>.
/// </summary>
- /// <param name="str">The string to seek.</param>
+ /// <param name="haystack">The string to seek.</param>
/// <param name="needle">The needle to find.</param>
/// <param name="stringComparison">One of the enumeration values that specifies the rules for the search.</param>
/// <returns>The part left of the <c>needle</c>.</returns>
- public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> str, ReadOnlySpan<char> needle, StringComparison stringComparison = default)
+ public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, ReadOnlySpan<char> needle, StringComparison stringComparison = default)
{
- var pos = str.IndexOf(needle, stringComparison);
- return pos == -1 ? str : str[..pos];
+ var pos = haystack.IndexOf(needle, stringComparison);
+ return pos == -1 ? haystack : haystack[..pos];
}
}
}
diff --git a/tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs b/tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs
index 0ed7673fd..8bf613f05 100644
--- a/tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs
+++ b/tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs
@@ -7,29 +7,37 @@ namespace Jellyfin.Common.Tests.Extensions
public class StringExtensionsTests
{
[Theory]
+ [InlineData("", 'q', "")]
[InlineData("Banana split", ' ', "Banana")]
[InlineData("Banana split", 'q', "Banana split")]
- public void LeftPart_ValidArgsCharNeedle_Correct(string str, char needle, string result)
+ public void LeftPart_ValidArgsCharNeedle_Correct(string str, char needle, string expectedResult)
{
- Assert.Equal(result, str.AsSpan().LeftPart(needle).ToString());
+ var result = str.AsSpan().LeftPart(needle).ToString();
+ Assert.Equal(expectedResult, result);
}
[Theory]
+ [InlineData("", "", "")]
+ [InlineData("", "q", "")]
+ [InlineData("Banana split", "", "")]
[InlineData("Banana split", " ", "Banana")]
[InlineData("Banana split test", " split", "Banana")]
- public void LeftPart_ValidArgsWithoutStringComparison_Correct(string str, string needle, string result)
+ public void LeftPart_ValidArgsWithoutStringComparison_Correct(string str, string needle, string expectedResult)
{
- Assert.Equal(result, str.AsSpan().LeftPart(needle).ToString());
+ var result = str.AsSpan().LeftPart(needle).ToString();
+ Assert.Equal(expectedResult, result);
}
[Theory]
+ [InlineData("", "", StringComparison.Ordinal, "")]
[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")]
- public void LeftPart_ValidArgs_Correct(string str, string needle, StringComparison stringComparison, string result)
+ public void LeftPart_ValidArgs_Correct(string str, string needle, StringComparison stringComparison, string expectedResult)
{
- Assert.Equal(result, str.AsSpan().LeftPart(needle, stringComparison).ToString());
+ var result = str.AsSpan().LeftPart(needle, stringComparison).ToString();
+ Assert.Equal(expectedResult, result);
}
}
}
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs
index d2ed0d925..c771f5f4a 100644
--- a/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs
+++ b/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs
@@ -10,9 +10,9 @@ namespace Jellyfin.Server.Implementations.Tests.Library
[InlineData("Superman: Red Son [imdbid=tt10985510]", "imdbid", "tt10985510")]
[InlineData("Superman: Red Son - tt10985510", "imdbid", "tt10985510")]
[InlineData("Superman: Red Son", "imdbid", null)]
- public void GetAttributeValue_ValidArgs_Correct(string input, string attribute, string? result)
+ public void GetAttributeValue_ValidArgs_Correct(string input, string attribute, string? expectedResult)
{
- Assert.Equal(result, PathExtensions.GetAttributeValue(input, attribute));
+ Assert.Equal(expectedResult, PathExtensions.GetAttributeValue(input, attribute));
}
[Theory]