mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-02 21:24:18 -04:00
* Some performance refactoring around getting Library and avoid a byte[] copy for getting cover images for epubs. * Initial commit. Rewrote the main series scan loop to use chunks of data at a time. Not fully shaken out. * Hooked in the ability for the UI to react to series being added or removed from the DB. * Cleaned up the messaging in the scan loop to be more clear. * Metadata scan and scan work as expected and populate data to the UI. There is a slow down in speed for overall operation. Scan series and refresh series metadata does not work fully. * Fixed a bug where MangaFiles were not having LastModified Updated correctly, meaning they were opening archives every scan. * Modified the code to be more realistic to the underlying file * Updated ScanService to properly handle deleted files and not result in a higher-level scan. * Shuffled around volume related repo apis to the volume repo rather than being in series. * Rewrote scan series to be much cleaner and more concise on the flow. Fixed an issue in UpdateVolumes such that the debug code to log out removed volumes could throw an exception and actually break updating volumes. * Refactored the code to set MangaFile last modified timestamp into the MangaFile entity. * Added Series Name to ScanSeries event * Added additional checks in ScanSeries to ensure we never go outside the library folder. Added extra debug messages for when a metadata refresh doesn't actually make changes and for when we regen cover images. * More logging statements saying where they originate from. Fixed a critical bug which caused only 1 chunk to ever be processed. * Fixed a concurrency issue with natural sorter which could cause issues in ArchiveService.cs. * Log cleanups * Fixed an issue with logging out total time of a scan. * Only show added toastrs for admins. When kicking off a refresh metadata for series, make sure we regenerate all cover images. * Code smells on benchmark despite it being ignored
206 lines
8.4 KiB
C#
206 lines
8.4 KiB
C#
using Xunit;
|
|
using static API.Parser.Parser;
|
|
|
|
namespace API.Tests.Parser
|
|
{
|
|
public class ParserTests
|
|
{
|
|
|
|
[Theory]
|
|
[InlineData("Beastars - SP01", true)]
|
|
[InlineData("Beastars SP01", true)]
|
|
[InlineData("Beastars Special 01", false)]
|
|
[InlineData("Beastars Extra 01", false)]
|
|
public void HasSpecialTest(string input, bool expected)
|
|
{
|
|
Assert.Equal(expected, HasSpecialMarker(input));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("0001", "1")]
|
|
[InlineData("1", "1")]
|
|
[InlineData("0013", "13")]
|
|
public void RemoveLeadingZeroesTest(string input, string expected)
|
|
{
|
|
Assert.Equal(expected, RemoveLeadingZeroes(input));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("1", "001")]
|
|
[InlineData("10", "010")]
|
|
[InlineData("100", "100")]
|
|
public void PadZerosTest(string input, string expected)
|
|
{
|
|
Assert.Equal(expected, PadZeros(input));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Hello_I_am_here", "Hello I am here")]
|
|
[InlineData("Hello_I_am_here ", "Hello I am here")]
|
|
[InlineData("[ReleaseGroup] The Title", "The Title")]
|
|
[InlineData("[ReleaseGroup]_The_Title", "The Title")]
|
|
[InlineData("[Suihei Kiki]_Kasumi_Otoko_no_Ko_[Taruby]_v1.1", "Kasumi Otoko no Ko v1.1")]
|
|
public void CleanTitleTest(string input, string expected)
|
|
{
|
|
Assert.Equal(expected, CleanTitle(input));
|
|
}
|
|
|
|
|
|
// [Theory]
|
|
// //[InlineData("@font-face{font-family:\"PaytoneOne\";src:url(\"..\\/Fonts\\/PaytoneOne.ttf\")}", "@font-face{font-family:\"PaytoneOne\";src:url(\"PaytoneOne.ttf\")}")]
|
|
// [InlineData("@font-face{font-family:\"PaytoneOne\";src:url(\"..\\/Fonts\\/PaytoneOne.ttf\")}", "..\\/Fonts\\/PaytoneOne.ttf")]
|
|
// //[InlineData("@font-face{font-family:'PaytoneOne';src:url('..\\/Fonts\\/PaytoneOne.ttf')}", "@font-face{font-family:'PaytoneOne';src:url('PaytoneOne.ttf')}")]
|
|
// //[InlineData("@font-face{\r\nfont-family:'PaytoneOne';\r\nsrc:url('..\\/Fonts\\/PaytoneOne.ttf')\r\n}", "@font-face{font-family:'PaytoneOne';src:url('PaytoneOne.ttf')}")]
|
|
// public void ReplaceStyleUrlTest(string input, string expected)
|
|
// {
|
|
// var replacementStr = "PaytoneOne.ttf";
|
|
// // Use Match to validate since replace is weird
|
|
// //Assert.Equal(expected, FontSrcUrlRegex.Replace(input, "$1" + replacementStr + "$2" + "$3"));
|
|
// var match = FontSrcUrlRegex.Match(input);
|
|
// Assert.Equal(!string.IsNullOrEmpty(expected), FontSrcUrlRegex.Match(input).Success);
|
|
// }
|
|
|
|
|
|
[Theory]
|
|
[InlineData("test.cbz", true)]
|
|
[InlineData("test.cbr", true)]
|
|
[InlineData("test.zip", true)]
|
|
[InlineData("test.rar", true)]
|
|
[InlineData("test.rar.!qb", false)]
|
|
[InlineData("[shf-ma-khs-aqs]negi_pa_vol15007.jpg", false)]
|
|
public void IsArchiveTest(string input, bool expected)
|
|
{
|
|
Assert.Equal(expected, IsArchive(input));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("test.epub", true)]
|
|
[InlineData("test.pdf", true)]
|
|
[InlineData("test.mobi", false)]
|
|
[InlineData("test.djvu", false)]
|
|
[InlineData("test.zip", false)]
|
|
[InlineData("test.rar", false)]
|
|
[InlineData("test.epub.!qb", false)]
|
|
[InlineData("[shf-ma-khs-aqs]negi_pa_vol15007.ebub", false)]
|
|
public void IsBookTest(string input, bool expected)
|
|
{
|
|
Assert.Equal(expected, IsBook(input));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("test.epub", true)]
|
|
[InlineData("test.EPUB", true)]
|
|
[InlineData("test.mobi", false)]
|
|
[InlineData("test.epub.!qb", false)]
|
|
[InlineData("[shf-ma-khs-aqs]negi_pa_vol15007.ebub", false)]
|
|
public void IsEpubTest(string input, bool expected)
|
|
{
|
|
Assert.Equal(expected, IsEpub(input));
|
|
}
|
|
|
|
// [Theory]
|
|
// [InlineData("Tenjou Tenge Omnibus", "Omnibus")]
|
|
// [InlineData("Tenjou Tenge {Full Contact Edition}", "Full Contact Edition")]
|
|
// [InlineData("Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz", "Full Contact Edition")]
|
|
// [InlineData("Wotakoi - Love is Hard for Otaku Omnibus v01 (2018) (Digital) (danke-Empire)", "Omnibus")]
|
|
// [InlineData("To Love Ru v01 Uncensored (Ch.001-007)", "Uncensored")]
|
|
// [InlineData("Chobits Omnibus Edition v01 [Dark Horse]", "Omnibus Edition")]
|
|
// [InlineData("[dmntsf.net] One Piece - Digital Colored Comics Vol. 20 Ch. 177 - 30 Million vs 81 Million.cbz", "Digital Colored Comics")]
|
|
// [InlineData("AKIRA - c003 (v01) [Full Color] [Darkhorse].cbz", "Full Color")]
|
|
// public void ParseEditionTest(string input, string expected)
|
|
// {
|
|
// Assert.Equal(expected, ParseEdition(input));
|
|
// }
|
|
|
|
// [Theory]
|
|
// [InlineData("Beelzebub Special OneShot - Minna no Kochikame x Beelzebub (2016) [Mangastream].cbz", true)]
|
|
// [InlineData("Beelzebub_Omake_June_2012_RHS", true)]
|
|
// [InlineData("Beelzebub_Side_Story_02_RHS.zip", false)]
|
|
// [InlineData("Darker than Black Shikkoku no Hana Special [Simple Scans].zip", true)]
|
|
// [InlineData("Darker than Black Shikkoku no Hana Fanbook Extra [Simple Scans].zip", true)]
|
|
// [InlineData("Corpse Party -The Anthology- Sachikos game of love Hysteric Birthday 2U Extra Chapter", true)]
|
|
// [InlineData("Ani-Hina Art Collection.cbz", true)]
|
|
// public void ParseMangaSpecialTest(string input, bool expected)
|
|
// {
|
|
// Assert.Equal(expected, ParseMangaSpecial(input) != "");
|
|
// }
|
|
|
|
[Theory]
|
|
[InlineData("12-14", 12)]
|
|
[InlineData("24", 24)]
|
|
[InlineData("18-04", 4)]
|
|
[InlineData("18-04.5", 4.5)]
|
|
[InlineData("40", 40)]
|
|
[InlineData("40a-040b", 0)]
|
|
[InlineData("40.1_a", 0)]
|
|
public void MinimumNumberFromRangeTest(string input, float expected)
|
|
{
|
|
Assert.Equal(expected, MinimumNumberFromRange(input));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Darker Than Black", "darkerthanblack")]
|
|
[InlineData("Darker Than Black - Something", "darkerthanblacksomething")]
|
|
[InlineData("Darker Than_Black", "darkerthanblack")]
|
|
[InlineData("", "")]
|
|
public void NormalizeTest(string input, string expected)
|
|
{
|
|
Assert.Equal(expected, Normalize(input));
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
[InlineData("test.jpg", true)]
|
|
[InlineData("test.jpeg", true)]
|
|
[InlineData("test.png", true)]
|
|
[InlineData(".test.jpg", false)]
|
|
[InlineData("!test.jpg", false)]
|
|
[InlineData("test.webp", true)]
|
|
public void IsImageTest(string filename, bool expected)
|
|
{
|
|
Assert.Equal(expected, IsImage(filename));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("C:/", "C:/Love Hina/Love Hina - Special.cbz", "Love Hina")]
|
|
[InlineData("C:/", "C:/Love Hina/Specials/Ani-Hina Art Collection.cbz", "Love Hina")]
|
|
[InlineData("C:/", "C:/Mujaki no Rakuen Something/Mujaki no Rakuen Vol12 ch76.cbz", "Mujaki no Rakuen")]
|
|
public void FallbackTest(string rootDir, string inputPath, string expectedSeries)
|
|
{
|
|
var actual = Parse(inputPath, rootDir);
|
|
if (actual == null)
|
|
{
|
|
Assert.NotNull(actual);
|
|
return;
|
|
}
|
|
|
|
Assert.Equal(expectedSeries, actual.Series);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Love Hina - Special.jpg", false)]
|
|
[InlineData("folder.jpg", true)]
|
|
[InlineData("DearS_v01_cover.jpg", true)]
|
|
[InlineData("DearS_v01_covers.jpg", false)]
|
|
[InlineData("!cover.jpg", true)]
|
|
[InlineData("cover.jpg", true)]
|
|
[InlineData("cover.png", true)]
|
|
[InlineData("ch1/cover.png", true)]
|
|
public void IsCoverImageTest(string inputPath, bool expected)
|
|
{
|
|
Assert.Equal(expected, IsCoverImage(inputPath));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("__MACOSX/Love Hina - Special.jpg", true)]
|
|
[InlineData("TEST/Love Hina - Special.jpg", false)]
|
|
[InlineData("__macosx/Love Hina/", false)]
|
|
[InlineData("MACOSX/Love Hina/", false)]
|
|
public void HasBlacklistedFolderInPathTest(string inputPath, bool expected)
|
|
{
|
|
Assert.Equal(expected, HasBlacklistedFolderInPath(inputPath));
|
|
}
|
|
}
|
|
}
|