| 1 | import unittest |
| 2 | |
| 3 | from indexer.normalize import is_story_post, normalize_title, slug |
| 4 | |
| 5 | |
| 6 | class NormalizeTests(unittest.TestCase): |
| 7 | def test_strips_part_numbers_and_tags(self): |
| 8 | self.assertEqual(normalize_title("[OC] The Last Terran - Part 1"), "the last terran") |
| 9 | self.assertEqual(normalize_title("The Last Terran Chapter 3"), "the last terran") |
| 10 | self.assertEqual(normalize_title("The Last Terran - 12"), "the last terran") |
| 11 | self.assertEqual(normalize_title("OC: Feet First into Hell - Part 2"), "feet first into hell") |
| 12 | self.assertEqual( |
| 13 | normalize_title("Wearing Power Armor to a Magic School (194/?)"), |
| 14 | "wearing power armor to a magic school", |
| 15 | ) |
| 16 | self.assertEqual( |
| 17 | normalize_title("Wearing Power Armor to a Magic School (193/?)"), |
| 18 | "wearing power armor to a magic school", |
| 19 | ) |
| 20 | self.assertTrue(normalize_title("Cavort of the Gio-Cru - Chapter Twenty-Two: Aloof").startswith("cavort of the gio-cru")) |
| 21 | self.assertNotIn("chapter", normalize_title("Cavort of the Gio-Cru - Chapter Twenty-Two: Aloof")) |
| 22 | self.assertNotIn("twenty-two", normalize_title("Cavort of the Gio-Cru - Chapter Twenty-Two: Aloof")) |
| 23 | self.assertEqual(normalize_title("Some Tale 12/?"), "some tale") |
| 24 | |
| 25 | def test_keeps_meaningful_subtitle(self): |
| 26 | # Geen nummer, dus de ondertitel blijft (verschillende sleutel). |
| 27 | self.assertEqual(normalize_title("Feet First into Hell - Puppeteer"), "feet first into hell - puppeteer") |
| 28 | |
| 29 | def test_slug(self): |
| 30 | self.assertEqual(slug("[OC] The Last Terran - Part 1"), "the-last-terran") |
| 31 | |
| 32 | def test_story_filter(self): |
| 33 | self.assertTrue(is_story_post("OC-Series", True, "A tale")) |
| 34 | self.assertFalse(is_story_post("Meta", True, "Weekly thread")) |
| 35 | self.assertFalse(is_story_post("OC-Series", False, "Link post")) |
| 36 | |
| 37 | |
| 38 | if __name__ == "__main__": |
| 39 | unittest.main() |