Simplified regex a bit.

This commit is contained in:
Taloth Saldono 2021-08-03 21:59:30 +02:00
parent 59409a7e72
commit f107ea5678
2 changed files with 17 additions and 14 deletions

View File

@ -50,37 +50,40 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
.Build(); .Build();
_episodeFile = new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p), ReleaseGroup = "SonarrTest" }; _episodeFile = new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p), ReleaseGroup = "SonarrTest" };
Mocker.GetMock<IQualityDefinitionService>() Mocker.GetMock<IQualityDefinitionService>()
.Setup(v => v.Get(Moq.It.IsAny<Quality>())) .Setup(v => v.Get(Moq.It.IsAny<Quality>()))
.Returns<Quality>(v => Quality.DefaultQualityDefinitions.First(c => c.Quality == v)); .Returns<Quality>(v => Quality.DefaultQualityDefinitions.First(c => c.Quality == v));
} }
[Test] [TestCase("Con Game", "Con_Game")]
public void should_replace_reserved_device_name_in_series_folder() [TestCase("Com1 Sat", "Com1_Sat")]
public void should_replace_reserved_device_name_in_series_folder(string title, string expected)
{ {
_series.Title = "Con Man"; _series.Title = title;
_namingConfig.SeriesFolderFormat = "{Series.Title}"; _namingConfig.SeriesFolderFormat = "{Series.Title}";
Subject.GetSeriesFolder(_series).Should().Be("Con_Man"); Subject.GetSeriesFolder(_series).Should().Be($"{expected}");
} }
[Test] [TestCase("Con Game", "Con_Game")]
public void should_replace_reserved_device_name_in_season_folder() [TestCase("Com1 Sat", "Com1_Sat")]
public void should_replace_reserved_device_name_in_season_folder(string title, string expected)
{ {
_series.Title = "Con Man"; _series.Title = title;
_namingConfig.SeasonFolderFormat = "{Series.Title} - Season {Season:00}"; _namingConfig.SeasonFolderFormat = "{Series.Title} - Season {Season:00}";
Subject.GetSeasonFolder(_series, 1).Should().Be("Con_Man - Season 01"); Subject.GetSeasonFolder(_series, 1).Should().Be($"{expected} - Season 01");
} }
[Test] [TestCase("Con Game", "Con_Game")]
public void should_replace_reserved_device_name_in_file_name() [TestCase("Com1 Sat", "Com1_Sat")]
public void should_replace_reserved_device_name_in_file_name(string title, string expected)
{ {
_series.Title = "Con Man"; _series.Title = title;
_namingConfig.StandardEpisodeFormat = "{Series.Title} - S{Season:00}E{Episode:00}"; _namingConfig.StandardEpisodeFormat = "{Series.Title} - S{Season:00}E{Episode:00}";
Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile).Should().Be("Con_Man - S15E06"); Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile).Should().Be($"{expected} - S15E06");
} }
} }
} }

View File

@ -80,7 +80,7 @@ namespace NzbDrone.Core.Organizer
private static readonly Regex YearRegex = new Regex(@"\(\d{4}\)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex YearRegex = new Regex(@"\(\d{4}\)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ReservedDeviceNamesRegex = new Regex(@"^(?:aux|com1|com2|com3|com4|com5|com6|com7|com8|com9|con|lpt1|lpt2|lpt3|lpt4|lpt5|lpt6|lpt7|lpt8|lpt9|nul|prn)\.", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex ReservedDeviceNamesRegex = new Regex(@"^(?:aux|com[1-9]|con|lpt[1-9]|nul|prn)\.", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public FileNameBuilder(INamingConfigService namingConfigService, public FileNameBuilder(INamingConfigService namingConfigService,
IQualityDefinitionService qualityDefinitionService, IQualityDefinitionService qualityDefinitionService,