Przeglądaj źródła

Address comments

Bond_009 5 lat temu
rodzic
commit
c430a7ed8f

+ 1 - 1
Emby.Server.Implementations/Library/PathExtensions.cs

@@ -16,7 +16,7 @@ namespace Emby.Server.Implementations.Library
         /// <param name="str">The STR.</param>
         /// <param name="str">The STR.</param>
         /// <param name="attribute">The attrib.</param>
         /// <param name="attribute">The attrib.</param>
         /// <returns>System.String.</returns>
         /// <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)
         public static string? GetAttributeValue(this string str, string attribute)
         {
         {
             if (str.Length == 0)
             if (str.Length == 0)

+ 11 - 11
MediaBrowser.Common/Extensions/StringExtensions.cs

@@ -10,28 +10,28 @@ namespace MediaBrowser.Common.Extensions
     public static class StringExtensions
     public static class StringExtensions
     {
     {
         /// <summary>
         /// <summary>
-        /// Returns the part left of the <c>needle</c>.
+        /// Returns the part on the left of the <c>needle</c>.
         /// </summary>
         /// </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="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>
         /// <summary>
-        /// Returns the part left of the <c>needle</c>.
+        /// Returns the part on the left of the <c>needle</c>.
         /// </summary>
         /// </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="needle">The needle to find.</param>
         /// <param name="stringComparison">One of the enumeration values that specifies the rules for the search.</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>
         /// <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];
         }
         }
     }
     }
 }
 }

+ 14 - 6
tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs

@@ -7,29 +7,37 @@ namespace Jellyfin.Common.Tests.Extensions
     public class StringExtensionsTests
     public class StringExtensionsTests
     {
     {
         [Theory]
         [Theory]
+        [InlineData("", 'q', "")]
         [InlineData("Banana split", ' ', "Banana")]
         [InlineData("Banana split", ' ', "Banana")]
         [InlineData("Banana split", 'q', "Banana split")]
         [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]
         [Theory]
+        [InlineData("", "", "")]
+        [InlineData("", "q", "")]
+        [InlineData("Banana split", "", "")]
         [InlineData("Banana split", " ", "Banana")]
         [InlineData("Banana split", " ", "Banana")]
         [InlineData("Banana split test", " 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]
         [Theory]
+        [InlineData("", "", StringComparison.Ordinal, "")]
         [InlineData("Banana split", " ", StringComparison.Ordinal, "Banana")]
         [InlineData("Banana split", " ", StringComparison.Ordinal, "Banana")]
         [InlineData("Banana split test", " 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", " Split", StringComparison.Ordinal, "Banana split test")]
         [InlineData("Banana split test", " Splït", StringComparison.InvariantCultureIgnoreCase, "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);
         }
         }
     }
     }
 }
 }

+ 2 - 2
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 [imdbid=tt10985510]", "imdbid", "tt10985510")]
         [InlineData("Superman: Red Son - tt10985510", "imdbid", "tt10985510")]
         [InlineData("Superman: Red Son - tt10985510", "imdbid", "tt10985510")]
         [InlineData("Superman: Red Son", "imdbid", null)]
         [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]
         [Theory]