mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-18 13:40:45 +01:00
Improved tests
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
@@ -22,7 +23,7 @@ namespace Emby.Naming.Audio
|
||||
{
|
||||
var filename = Path.GetFileName(path);
|
||||
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
if (path.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -39,18 +40,22 @@ namespace Emby.Naming.Audio
|
||||
filename = filename.Replace(')', ' ');
|
||||
filename = Regex.Replace(filename, @"\s+", " ");
|
||||
|
||||
filename = filename.TrimStart();
|
||||
ReadOnlySpan<char> trimmedFilename = filename.TrimStart();
|
||||
|
||||
foreach (var prefix in _options.AlbumStackingPrefixes)
|
||||
{
|
||||
if (filename.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) != 0)
|
||||
if (!trimmedFilename.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var tmp = filename.Substring(prefix.Length);
|
||||
var tmp = trimmedFilename.Slice(prefix.Length).Trim();
|
||||
|
||||
tmp = tmp.Trim().Split(' ').FirstOrDefault() ?? string.Empty;
|
||||
int index = tmp.IndexOf(' ');
|
||||
if (index != -1)
|
||||
{
|
||||
tmp = tmp.Slice(0, index);
|
||||
}
|
||||
|
||||
if (int.TryParse(tmp, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
@@ -11,7 +12,7 @@ namespace Emby.Naming.Audio
|
||||
{
|
||||
public static bool IsAudioFile(string path, NamingOptions options)
|
||||
{
|
||||
var extension = Path.GetExtension(path) ?? string.Empty;
|
||||
var extension = Path.GetExtension(path);
|
||||
return options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,6 @@ namespace Emby.Naming.Common
|
||||
{
|
||||
}
|
||||
|
||||
public EpisodeExpression()
|
||||
: this(null)
|
||||
{
|
||||
}
|
||||
|
||||
public string Expression
|
||||
{
|
||||
get => _expression;
|
||||
@@ -48,6 +43,6 @@ namespace Emby.Naming.Common
|
||||
|
||||
public string[] DateTimeFormats { get; set; }
|
||||
|
||||
public Regex Regex => _regex ?? (_regex = new Regex(Expression, RegexOptions.IgnoreCase | RegexOptions.Compiled));
|
||||
public Regex Regex => _regex ??= new Regex(Expression, RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
@@ -16,11 +17,11 @@ namespace Emby.Naming.Subtitles
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public SubtitleInfo ParseFile(string path)
|
||||
public SubtitleInfo? ParseFile(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
if (path.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
throw new ArgumentException("String can't be empty.", nameof(path));
|
||||
}
|
||||
|
||||
var extension = Path.GetExtension(path);
|
||||
@@ -52,11 +53,6 @@ namespace Emby.Naming.Subtitles
|
||||
|
||||
private string[] GetFlags(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
|
||||
// Note: the tags need be be surrounded be either a space ( ), hyphen -, dot . or underscore _.
|
||||
|
||||
var file = Path.GetFileName(path);
|
||||
|
||||
Reference in New Issue
Block a user