From 3e07100dc2725cb2d42050571232dd5d485b4de5 Mon Sep 17 00:00:00 2001 From: saud-97 <39028181+saud-97@users.noreply.github.com> Date: Tue, 24 May 2022 00:17:29 +0300 Subject: [PATCH] Fixes: incorrect sorting when chapter name contains hyphens '-' (#7161) * Fixes: incorrect sorting when chapter name contains hyphens '-' * Added a test case for hyphen in ChapterRecognitionTest.kt * Removed chapter range test case since it will be replaced by chapterContainingHyphensCase --- .../util/chapter/ChapterRecognition.kt | 4 +-- .../data/database/ChapterRecognitionTest.kt | 32 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterRecognition.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterRecognition.kt index dd44f42be8..f9dfb076e7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterRecognition.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterRecognition.kt @@ -46,8 +46,8 @@ object ChapterRecognition { // Get chapter title with lower case var name = chapter.name.lowercase() - // Remove comma's from chapter. - name = name.replace(',', '.') + // Remove comma's or hyphens. + name = name.replace(',', '.').replace('-', '.') // Remove unwanted white spaces. unwantedWhiteSpace.findAll(name).let { diff --git a/app/src/test/java/eu/kanade/tachiyomi/data/database/ChapterRecognitionTest.kt b/app/src/test/java/eu/kanade/tachiyomi/data/database/ChapterRecognitionTest.kt index 640c0a2437..391e685721 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/data/database/ChapterRecognitionTest.kt +++ b/app/src/test/java/eu/kanade/tachiyomi/data/database/ChapterRecognitionTest.kt @@ -276,16 +276,6 @@ class ChapterRecognitionTest { assertEquals(1f, chapter.chapter_number) } - /** - * Chapter containing range - */ - @Test - fun rangeInChapterCase() { - createChapter("Ch.191-200 Read Online") - ChapterRecognition.parseChapterNumber(chapter, manga) - assertEquals(191f, chapter.chapter_number) - } - /** * Chapter containing multiple zeros */ @@ -440,7 +430,27 @@ class ChapterRecognitionTest { assertEquals(24.005f, chapter.chapter_number) } - /** + /** + * Chapter title containing hyphen's + */ + @Test + fun chapterContainingHyphensCase() { + createManga("Solo Leveling") + + createChapter("ch 122-a") + ChapterRecognition.parseChapterNumber(chapter, manga) + assertEquals(122.1f, chapter.chapter_number) + + createChapter("Solo Leveling Ch.123-extra") + ChapterRecognition.parseChapterNumber(chapter, manga) + assertEquals(123.99f, chapter.chapter_number) + + createChapter("Solo Leveling, 024-005") + ChapterRecognition.parseChapterNumber(chapter, manga) + assertEquals(24.005f, chapter.chapter_number) + } + + /** * Test for chapters containing season */ @Test