2020-04-19 09:57:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Emby.Naming.Common;
|
2019-12-06 19:40:06 +00:00
|
|
|
|
using Emby.Naming.Subtitles;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Jellyfin.Naming.Tests.Subtitles
|
|
|
|
|
{
|
|
|
|
|
public class SubtitleParserTests
|
|
|
|
|
{
|
2020-04-19 09:57:03 +00:00
|
|
|
|
private readonly NamingOptions _namingOptions = new NamingOptions();
|
2019-12-06 19:40:06 +00:00
|
|
|
|
|
2020-04-19 09:57:03 +00:00
|
|
|
|
[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)]
|
2020-04-21 08:21:20 +00:00
|
|
|
|
public void SubtitleParser_ValidFileName_Parses(string input, string language, bool isDefault, bool isForced)
|
2019-12-06 19:40:06 +00:00
|
|
|
|
{
|
2020-04-19 09:57:03 +00:00
|
|
|
|
var parser = new SubtitleParser(_namingOptions);
|
2019-12-06 19:40:06 +00:00
|
|
|
|
|
|
|
|
|
var result = parser.ParseFile(input);
|
|
|
|
|
|
2020-05-13 22:59:19 +00:00
|
|
|
|
Assert.Equal(language, result?.Language, true);
|
|
|
|
|
Assert.Equal(isDefault, result?.IsDefault);
|
|
|
|
|
Assert.Equal(isForced, result?.IsForced);
|
2019-12-06 19:40:06 +00:00
|
|
|
|
}
|
2020-04-19 09:57:03 +00:00
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("The Skin I Live In (2011).mp4")]
|
2020-04-21 08:21:20 +00:00
|
|
|
|
public void SubtitleParser_InvalidFileName_ReturnsNull(string input)
|
2020-04-19 09:57:03 +00:00
|
|
|
|
{
|
|
|
|
|
var parser = new SubtitleParser(_namingOptions);
|
|
|
|
|
|
|
|
|
|
Assert.Null(parser.ParseFile(input));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2020-04-21 08:21:20 +00:00
|
|
|
|
public void SubtitleParser_EmptyFileName_ThrowsArgumentException()
|
2020-04-19 09:57:03 +00:00
|
|
|
|
{
|
|
|
|
|
Assert.Throws<ArgumentException>(() => new SubtitleParser(_namingOptions).ParseFile(string.Empty));
|
|
|
|
|
}
|
2019-12-06 19:40:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|