diff --git a/src/options_description.cpp b/src/options_description.cpp index b66ef1f..be08c5f 100644 --- a/src/options_description.cpp +++ b/src/options_description.cpp @@ -410,8 +410,8 @@ namespace boost { namespace program_options { { // is last_space within the second half ot the // current line - if ((unsigned)distance(last_space, line_end) < - (line_length - indent) / 2) + if (static_cast(distance(last_space, line_end)) < + (line_length / 2)) { line_end = last_space; } diff --git a/test/options_description_test.cpp b/test/options_description_test.cpp index f8627a9..3470fd4 100644 --- a/test/options_description_test.cpp +++ b/test/options_description_test.cpp @@ -128,11 +128,39 @@ void test_long_default_value() ); } +void test_word_wrapping() +{ + options_description desc("Supported options"); + desc.add_options() + ("help", "this is a sufficiently long text to require word-wrapping") + ("prefix", value()->default_value("/h/proj/tmp/dispatch"), "root path of the dispatch installation") + ("opt1", "this_is_a_sufficiently_long_text_to_require_word-wrapping_but_cannot_be_wrapped") + ("opt2", "this_is_a_sufficiently long_text_to_require_word-wrapping") + ("opt3", "this_is_a sufficiently_long_text_to_require_word-wrapping_but_will_not_be_wrapped") + ; + stringstream ss; + ss << desc; + BOOST_CHECK_EQUAL(ss.str(), +"Supported options:\n" +" --help this is a sufficiently long text to \n" +" require word-wrapping\n" +" --prefix arg (=/h/proj/tmp/dispatch) root path of the dispatch installation\n" +" --opt1 this_is_a_sufficiently_long_text_to_requ\n" +" ire_word-wrapping_but_cannot_be_wrapped\n" +" --opt2 this_is_a_sufficiently \n" +" long_text_to_require_word-wrapping\n" +" --opt3 this_is_a sufficiently_long_text_to_requ\n" +" ire_word-wrapping_but_will_not_be_wrappe\n" +" d\n" + ); +} + int main(int, char* []) { test_type(); test_approximation(); test_formatting(); test_long_default_value(); + test_word_wrapping(); return 0; }