From 0a7f8711adc97e4baefcf5bb6ade0b7a2311a3a4 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 19 Dec 2015 16:22:57 +0100 Subject: [PATCH] Add a new test case for chapter recognition --- .../java/eu/kanade/mangafeed/util/ChapterRecognition.java | 6 +++--- .../java/eu/kanade/mangafeed/ChapterRecognitionTest.java | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/util/ChapterRecognition.java b/app/src/main/java/eu/kanade/mangafeed/util/ChapterRecognition.java index c0552e6b26..862b6e2e15 100644 --- a/app/src/main/java/eu/kanade/mangafeed/util/ChapterRecognition.java +++ b/app/src/main/java/eu/kanade/mangafeed/util/ChapterRecognition.java @@ -12,7 +12,7 @@ public class ChapterRecognition { private static Pattern p1 = Pattern.compile("Ch[^0-9]?\\s*(\\d+[\\.,]?\\d*)"); private static Pattern p2 = Pattern.compile("(\\d+[\\.,]?\\d*)"); - private static Pattern p3 = Pattern.compile("(\\d+[\\.,]?\\d*:)"); + private static Pattern p3 = Pattern.compile("(\\d+[\\.,]?\\d*\\s*:)"); public static void parseChapterNumber(Chapter chapter, Manga manga) { if (chapter.chapter_number != -1) @@ -29,8 +29,6 @@ public class ChapterRecognition { return; } - name = replaceIrrelevantCharacters(name); - List occurences; // If there's only one number, use it @@ -49,6 +47,8 @@ public class ChapterRecognition { return; } + name = replaceIrrelevantCharacters(name); + // Try to remove the manga name from the chapter, and try again String mangaName = replaceIrrelevantCharacters(manga.title); String nameWithoutManga = difference(mangaName, name); diff --git a/app/src/test/java/eu/kanade/mangafeed/ChapterRecognitionTest.java b/app/src/test/java/eu/kanade/mangafeed/ChapterRecognitionTest.java index e415ff5f7e..d6b0fe1e35 100644 --- a/app/src/test/java/eu/kanade/mangafeed/ChapterRecognitionTest.java +++ b/app/src/test/java/eu/kanade/mangafeed/ChapterRecognitionTest.java @@ -113,4 +113,12 @@ public class ChapterRecognitionTest { assertThat(c.chapter_number, is(567f)); } + @Test + public void testWithVersionBefore() { + // It should be 84, not 2084) + Chapter c = createChapter("Onepunch-Man Punch Ver002 084 : Creeping Darkness"); + ChapterRecognition.parseChapterNumber(c, randomManga); + assertThat(c.chapter_number, is(84f)); + } + }