We were doing this extremely incorrectly: the correct algorithm does multiple overlaid reversals, similar to what we do below in visual_runs (though visual_runs has the benefit of operating on LevelRuns).
The test case this fixes is \u{202D}abc\u{202E}DEF\u{202D}ghi\u{202E}JKL\u{202D}mno, which ought to get reordered as abcghimnoLKJFED, but instead does something different. There's also a simpler testcase in the doctest that already exists (so I didn't add this rather complicated case).
We were doing this extremely incorrectly: the correct algorithm does multiple overlaid reversals, similar to what we do below in
visual_runs
(thoughvisual_runs
has the benefit of operating on LevelRuns).The test case this fixes is
\u{202D}abc\u{202E}DEF\u{202D}ghi\u{202E}JKL\u{202D}mno
, which ought to get reordered as abcghimnoLKJFED, but instead does something different. There's also a simpler testcase in the doctest that already exists (so I didn't add this rather complicated case).