diff --git a/basis/wrap/strings/strings-tests.factor b/basis/wrap/strings/strings-tests.factor index 0bea9b5d32..e66572dc1b 100644 --- a/basis/wrap/strings/strings-tests.factor +++ b/basis/wrap/strings/strings-tests.factor @@ -27,7 +27,7 @@ word wrap."> " " wrap-indented-string ] unit-test -[ "this text\nhas lots\nof spaces" ] +[ "this text\nhas lots of\nspaces" ] [ "this text has lots of spaces" 12 wrap-string ] unit-test [ "hello\nhow\nare\nyou\ntoday?" ] @@ -39,3 +39,5 @@ word wrap."> [ "aaa bb\nccccccc\nddddddd" ] [ "aaa bb ccccccc ddddddd" 6 wrap-string ] unit-test \ wrap-string must-infer + +[ "a b c d e f\ng h" ] [ "a b c d e f g h" 11 wrap-string ] unit-test diff --git a/basis/wrap/wrap.factor b/basis/wrap/wrap.factor index 6e5bf31075..0b7f869141 100644 --- a/basis/wrap/wrap.factor +++ b/basis/wrap/wrap.factor @@ -36,8 +36,10 @@ SYMBOL: line-ideal ] each drop ; inline : paragraph-cost ( paragraph -- cost ) - [ head-width>> deviation ] - [ tail-cost>> ] bi + ; + dup lines>> 1list? [ drop 0 ] [ + [ head-width>> deviation ] + [ tail-cost>> ] bi + + ] if ; : min-cost ( paragraphs -- paragraph ) [ paragraph-cost ] min-by ;