Skip to content

Commit cc477df

Browse files
committed
Added note that there is still more to do on 5516.
Also added regression test for the byte vs codepoint issues that the previous commit fixes.
1 parent ae63a3e commit cc477df

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/libextra/getopts.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ pub mod groups {
690690
}
691691
}
692692

693-
// FIXME: #5516
693+
// FIXME: #5516 should be graphemes not codepoints
694694
// here we just need to indent the start of the description
695695
let rowlen = str::count_chars(row, 0, row.len());
696696
if rowlen < 24 {
@@ -708,14 +708,14 @@ pub mod groups {
708708
desc_normalized_whitespace.push_char(' ');
709709
}
710710

711-
// FIXME: #5516
711+
// FIXME: #5516 should be graphemes not codepoints
712712
let mut desc_rows = ~[];
713713
do each_split_within(desc_normalized_whitespace, 54) |substr| {
714714
desc_rows.push(substr.to_owned());
715715
true
716716
};
717717

718-
// FIXME: #5516
718+
// FIXME: #5516 should be graphemes not codepoints
719719
// wrapped description
720720
row.push_str(desc_rows.connect(desc_sep));
721721

@@ -1581,4 +1581,31 @@ Options:
15811581
debug!("generated: <<%s>>", usage);
15821582
assert!(usage == expected)
15831583
}
1584+
1585+
#[test]
1586+
fn test_groups_usage_description_multibyte_handling() {
1587+
let optgroups = ~[
1588+
groups::optflag("k", "k\u2013w\u2013",
1589+
"The word kiwi is normally spelled with two i's"),
1590+
groups::optflag("a", "apple",
1591+
"This \u201Cdescription\u201D has some characters that could \
1592+
confuse the line wrapping; an apple costs 0.51€ in some parts of Europe."),
1593+
];
1594+
1595+
let expected =
1596+
~"Usage: fruits
1597+
1598+
Options:
1599+
-k --k–w– The word kiwi is normally spelled with two i's
1600+
-a --apple This “description” has some characters that could
1601+
confuse the line wrapping; an apple costs 0.51in
1602+
some parts of Europe.
1603+
";
1604+
1605+
let usage = groups::usage("Usage: fruits", optgroups);
1606+
1607+
debug!("expected: <<%s>>", expected);
1608+
debug!("generated: <<%s>>", usage);
1609+
assert!(usage == expected)
1610+
}
15841611
}

0 commit comments

Comments
 (0)