diff --git a/scripts/exporter/retropie_exporter.py b/scripts/exporter/retropie_exporter.py index de622019..1f2bc27a 100644 --- a/scripts/exporter/retropie_exporter.py +++ b/scripts/exporter/retropie_exporter.py @@ -250,11 +250,13 @@ class Exporter(BaseExporter): return core in required_by @staticmethod - def _join(names: list[str]) -> str: - """RetroPie's own idiom: a, b and c.""" + def _join(names: list[str], serial: bool = False) -> str: + """RetroPie's own idiom: a, b and c, or a, b, and c where the + sentence already writes the comma before its final and.""" if len(names) == 1: return names[0] - return ", ".join(names[:-1]) + " and " + names[-1] + last = ", and " if serial and len(names) > 2 else " and " + return ", ".join(names[:-1]) + last + names[-1] @classmethod def _extended( @@ -269,7 +271,8 @@ class Exporter(BaseExporter): name: appending ", c and d" after "a and b" read "a and b, c and d". """ start, end, written = enumeration - return help_text[:start] + cls._join([*written, *missing]) + help_text[end:] + serial = ", and " in help_text[start:end] + return help_text[:start] + cls._join([*written, *missing], serial) + help_text[end:] def modules(self, originals: dict[str, str]) -> dict[str, tuple[str, str]]: """Module id and help string of every script that mentions BIOS.""" diff --git a/tests/test_export_counts.py b/tests/test_export_counts.py index 03f9880e..740f9778 100644 --- a/tests/test_export_counts.py +++ b/tests/test_export_counts.py @@ -700,6 +700,16 @@ class RetroPieProposals(unittest.TestCase): self.assertIn("gexpress.pce", text) self.assertNotIn("pac-n1.bin", text) + def test_an_extended_list_keeps_its_own_final_comma(self): + """quasi88 writes "N88KNJ2.ROM, and N88SUB.ROM": the list came back + without its comma before the final and.""" + help_text = "Copy bios files A.ROM, B.ROM, and C.ROM to $biosdir/pc88" + enumeration = RetroPie._enumeration(help_text) + self.assertEqual( + RetroPie._extended(help_text, enumeration, ["D.ROM"]), + "Copy bios files A.ROM, B.ROM, C.ROM, and D.ROM to $biosdir/pc88", + ) + def test_a_list_of_alternatives_is_not_extended(self): alternatives = "Copy the required BIOS file a.rom or b.rom to $biosdir" enumeration = "Copy the required BIOS files a.rom and b.rom to $biosdir"