Browse Source

Add a new test case for chapter recognition

inorichi 9 years ago
parent
commit
0a7f8711ad

+ 3 - 3
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<Float> 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);

+ 8 - 0
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));
+    }
+
 }