mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-03 14:28:46 +01:00
Merge remote-tracking branch 'upstream/master' into integration-tests
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using Xunit;
|
||||
|
||||
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 expectedResult)
|
||||
{
|
||||
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 expectedResult)
|
||||
{
|
||||
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 expectedResult)
|
||||
{
|
||||
var result = str.AsSpan().LeftPart(needle, stringComparison).ToString();
|
||||
Assert.Equal(expectedResult, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
tests/Jellyfin.Model.Tests/Extensions/StringHelperTests.cs
Normal file
19
tests/Jellyfin.Model.Tests/Extensions/StringHelperTests.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using MediaBrowser.Model.Extensions;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Model.Tests.Extensions
|
||||
{
|
||||
public class StringHelperTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("", "")]
|
||||
[InlineData("banana", "Banana")]
|
||||
[InlineData("Banana", "Banana")]
|
||||
[InlineData("ä", "Ä")]
|
||||
public void StringHelper_ValidArgs_Success(string input, string expectedResult)
|
||||
{
|
||||
Assert.Equal(expectedResult, StringHelper.FirstToUpper(input));
|
||||
}
|
||||
}
|
||||
}
|
||||
21
tests/Jellyfin.Model.Tests/Jellyfin.Model.Tests.csproj
Normal file
21
tests/Jellyfin.Model.Tests/Jellyfin.Model.Tests.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../MediaBrowser.Model/MediaBrowser.Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -6,61 +6,45 @@ namespace Jellyfin.Naming.Tests.Music
|
||||
{
|
||||
public class MultiDiscAlbumTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestMultiDiscAlbums()
|
||||
private readonly NamingOptions _namingOptions = new NamingOptions();
|
||||
|
||||
[Theory]
|
||||
[InlineData("", false)]
|
||||
[InlineData("C:/", false)]
|
||||
[InlineData("/home/", false)]
|
||||
[InlineData(@"blah blah", false)]
|
||||
[InlineData(@"D:/music/weezer/03 Pinkerton", false)]
|
||||
[InlineData(@"D:/music/michael jackson/Bad (2012 Remaster)", false)]
|
||||
[InlineData(@"cd1", true)]
|
||||
[InlineData(@"disc18", true)]
|
||||
[InlineData(@"disk10", true)]
|
||||
[InlineData(@"vol7", true)]
|
||||
[InlineData(@"volume1", true)]
|
||||
[InlineData(@"cd 1", true)]
|
||||
[InlineData(@"disc 1", true)]
|
||||
[InlineData(@"disk 1", true)]
|
||||
[InlineData(@"disk", false)]
|
||||
[InlineData(@"disk ·", false)]
|
||||
[InlineData(@"disk a", false)]
|
||||
[InlineData(@"disk volume", false)]
|
||||
[InlineData(@"disc disc", false)]
|
||||
[InlineData(@"disk disc 6", false)]
|
||||
[InlineData(@"cd - 1", true)]
|
||||
[InlineData(@"disc- 1", true)]
|
||||
[InlineData(@"disk - 1", true)]
|
||||
[InlineData(@"Disc 01 (Hugo Wolf · 24 Lieder)", true)]
|
||||
[InlineData(@"Disc 04 (Encores and Folk Songs)", true)]
|
||||
[InlineData(@"Disc04 (Encores and Folk Songs)", true)]
|
||||
[InlineData(@"Disc 04(Encores and Folk Songs)", true)]
|
||||
[InlineData(@"Disc04(Encores and Folk Songs)", true)]
|
||||
[InlineData(@"D:/Video/MBTestLibrary/VideoTest/music/.38 special/anth/Disc 2", true)]
|
||||
[InlineData(@"[1985] Opportunities (Let's make lots of money) (1985)", false)]
|
||||
[InlineData(@"Blah 04(Encores and Folk Songs)", false)]
|
||||
public void AlbumParser_MultidiscPath_Identifies(string path, bool result)
|
||||
{
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"blah blah"));
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"D:/music/weezer/03 Pinkerton"));
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"D:/music/michael jackson/Bad (2012 Remaster)"));
|
||||
var parser = new AlbumParser(_namingOptions);
|
||||
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"cd1"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"disc18"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"disk10"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"vol7"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"volume1"));
|
||||
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"cd 1"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"disc 1"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"disk 1"));
|
||||
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"disk"));
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"disk ·"));
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"disk a"));
|
||||
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"disk volume"));
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"disc disc"));
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"disk disc 6"));
|
||||
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"cd - 1"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"disc- 1"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"disk - 1"));
|
||||
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"Disc 01 (Hugo Wolf · 24 Lieder)"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"Disc 04 (Encores and Folk Songs)"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"Disc04 (Encores and Folk Songs)"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"Disc 04(Encores and Folk Songs)"));
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"Disc04(Encores and Folk Songs)"));
|
||||
|
||||
Assert.True(IsMultiDiscAlbumFolder(@"D:/Video/MBTestLibrary/VideoTest/music/.38 special/anth/Disc 2"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMultiDiscAlbums1()
|
||||
{
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"[1985] Opportunities (Let's make lots of money) (1985)"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMultiDiscAlbums2()
|
||||
{
|
||||
Assert.False(IsMultiDiscAlbumFolder(@"Blah 04(Encores and Folk Songs)"));
|
||||
}
|
||||
|
||||
private bool IsMultiDiscAlbumFolder(string path)
|
||||
{
|
||||
var parser = new AlbumParser(new NamingOptions());
|
||||
|
||||
return parser.IsMultiPart(path);
|
||||
Assert.Equal(result, parser.IsMultiPart(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Emby.Naming.Common;
|
||||
using System;
|
||||
using Emby.Naming.Common;
|
||||
using Emby.Naming.Subtitles;
|
||||
using Xunit;
|
||||
|
||||
@@ -6,28 +7,19 @@ namespace Jellyfin.Naming.Tests.Subtitles
|
||||
{
|
||||
public class SubtitleParserTests
|
||||
{
|
||||
private SubtitleParser GetParser()
|
||||
{
|
||||
var options = new NamingOptions();
|
||||
private readonly NamingOptions _namingOptions = new NamingOptions();
|
||||
|
||||
return new SubtitleParser(options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSubtitles()
|
||||
[Theory]
|
||||
[InlineData("The Skin I Live In (2011).srt", null, false, false)]
|
||||
[InlineData("The Skin I Live In (2011).eng.srt", "eng", false, false)]
|
||||
[InlineData("The Skin I Live In (2011).eng.default.srt", "eng", true, false)]
|
||||
[InlineData("The Skin I Live In (2011).eng.forced.srt", "eng", false, true)]
|
||||
[InlineData("The Skin I Live In (2011).eng.foreign.srt", "eng", false, true)]
|
||||
[InlineData("The Skin I Live In (2011).eng.default.foreign.srt", "eng", true, true)]
|
||||
[InlineData("The Skin I Live In (2011).default.foreign.eng.srt", "eng", true, true)]
|
||||
public void SubtitleParser_ValidFileName_Parses(string input, string language, bool isDefault, bool isForced)
|
||||
{
|
||||
Test("The Skin I Live In (2011).srt", null, false, false);
|
||||
Test("The Skin I Live In (2011).eng.srt", "eng", false, false);
|
||||
Test("The Skin I Live In (2011).eng.default.srt", "eng", true, false);
|
||||
Test("The Skin I Live In (2011).eng.forced.srt", "eng", false, true);
|
||||
Test("The Skin I Live In (2011).eng.foreign.srt", "eng", false, true);
|
||||
Test("The Skin I Live In (2011).eng.default.foreign.srt", "eng", true, true);
|
||||
Test("The Skin I Live In (2011).default.foreign.eng.srt", "eng", true, true);
|
||||
}
|
||||
|
||||
private void Test(string input, string language, bool isDefault, bool isForced)
|
||||
{
|
||||
var parser = GetParser();
|
||||
var parser = new SubtitleParser(_namingOptions);
|
||||
|
||||
var result = parser.ParseFile(input);
|
||||
|
||||
@@ -35,5 +27,20 @@ namespace Jellyfin.Naming.Tests.Subtitles
|
||||
Assert.Equal(isDefault, result.IsDefault);
|
||||
Assert.Equal(isForced, result.IsForced);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("The Skin I Live In (2011).mp4")]
|
||||
public void SubtitleParser_InvalidFileName_ReturnsNull(string input)
|
||||
{
|
||||
var parser = new SubtitleParser(_namingOptions);
|
||||
|
||||
Assert.Null(parser.ParseFile(input));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SubtitleParser_EmptyFileName_ThrowsArgumentException()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new SubtitleParser(_namingOptions).ParseFile(string.Empty));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Emby.Server.Implementations.HttpServer;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Server.Implementations.Tests.HttpServer
|
||||
{
|
||||
public class ResponseFilterTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(null, null)]
|
||||
[InlineData("", "")]
|
||||
[InlineData("This is a clean string.", "This is a clean string.")]
|
||||
[InlineData("This isn't \n\ra clean string.", "This isn't a clean string.")]
|
||||
public void RemoveControlCharacters_ValidArgs_Correct(string? input, string? result)
|
||||
{
|
||||
Assert.Equal(result, ResponseFilter.RemoveControlCharacters(input));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Emby.Server.Implementations.Library;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Server.Implementations.Tests.Library
|
||||
{
|
||||
public class PathExtensionsTests
|
||||
{
|
||||
[Theory]
|
||||
[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? expectedResult)
|
||||
{
|
||||
Assert.Equal(expectedResult, PathExtensions.GetAttributeValue(input, attribute));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", "")]
|
||||
[InlineData("Superman: Red Son [imdbid=tt10985510]", "")]
|
||||
[InlineData("", "imdbid")]
|
||||
public void GetAttributeValue_EmptyString_ThrowsArgumentException(string input, string attribute)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => PathExtensions.GetAttributeValue(input, attribute));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user