@@ -265,12 +265,48 @@ def test_suffix_delimiter_comma_space_is_noop(self) -> None:
265265 hn = HumanName ("John Doe, MD, PhD" , suffix_delimiter = ", " )
266266 self .m (hn .suffix , "MD, PhD" , hn )
267267
268- def test_suffix_delimiter_inverted_format_known_limitation (self ) -> None :
269- # In inverted format, the first-name part is also split on the delimiter.
270- # "Mary - Kate" becomes two separate parts, causing a wrong parse.
271- # This is a documented limitation — do not "fix" it without a broader solution .
268+ def test_suffix_delimiter_inverted_format_not_misparsed (self ) -> None :
269+ # The delimiter only expands parts once they're identified as a
270+ # suffix group, so a hyphenated given name in inverted format isn't
271+ # mistaken for a suffix split .
272272 hn = HumanName ("Doe, Mary - Kate, RN" , suffix_delimiter = " - " )
273- self .assertNotEqual (hn .first , "Mary - Kate" )
273+ self .m (hn .first , "Mary" , hn )
274+ self .m (hn .last , "Doe" , hn )
275+ self .m (hn .suffix , "RN" , hn )
276+ # "Kate" stays in the given-name segment rather than being pulled
277+ # into the suffix, since it's separated from "RN" by its own comma.
278+ # The bare "-" landing in middle is a pre-existing, delimiter-
279+ # independent quirk of tokenizing a lone hyphen (reproducible with
280+ # suffix_delimiter unset), not something this fix is responsible for.
281+ self .m (hn .middle , "- Kate" , hn )
282+
283+ def test_suffix_delimiter_expands_each_comma_segment (self ) -> None :
284+ # parts[1:] holds two separate comma segments here ("MD - PhD" and
285+ # "FACS"); each must be expanded on its own, not just the first.
286+ hn = HumanName ("John Doe, MD - PhD, FACS" , suffix_delimiter = " - " )
287+ self .m (hn .first , "John" , hn )
288+ self .m (hn .last , "Doe" , hn )
289+ self .m (hn .suffix , "MD, PhD, FACS" , hn )
290+
291+ def test_suffix_delimiter_detection_with_multi_word_side (self ) -> None :
292+ # The suffix-comma detection check flattens on spaces after
293+ # expanding on the delimiter, so a multi-word token on one side of
294+ # the delimiter is still tokenized correctly.
295+ hn = HumanName ("Doe, John, MD PhD - FACS Fellow" , suffix_delimiter = " - " )
296+ self .m (hn .first , "John" , hn )
297+ self .m (hn .last , "Doe" , hn )
298+ self .m (hn .suffix , "MD PhD, FACS Fellow" , hn )
299+
300+ def test_suffix_delimiter_no_effect_when_not_suffix_comma (self ) -> None :
301+ # When the comma format isn't recognized as suffix-comma (here the
302+ # last-name part is a single word), the delimiter must not affect
303+ # parsing at all: output should match the no-delimiter baseline.
304+ with_delim = HumanName ("Smith, MD - PhD - FACS" , suffix_delimiter = " - " )
305+ without_delim = HumanName ("Smith, MD - PhD - FACS" )
306+ self .assertEqual (
307+ (with_delim .first , with_delim .middle , with_delim .last , with_delim .suffix ),
308+ (without_delim .first , without_delim .middle , without_delim .last , without_delim .suffix ),
309+ )
274310
275311 def test_suffix_acronyms_ambiguous_is_customizable (self ) -> None :
276312 from nameparser .config import Constants
0 commit comments