]> gitweb.factorcode.org Git - factor.git/commitdiff
Making basis/wrap not try to align the last line
authorDaniel Ehrenberg <littledan@Macintosh-103.local>
Tue, 10 Feb 2009 07:46:02 +0000 (01:46 -0600)
committerDaniel Ehrenberg <littledan@Macintosh-103.local>
Tue, 10 Feb 2009 07:46:02 +0000 (01:46 -0600)
basis/wrap/strings/strings-tests.factor
basis/wrap/wrap.factor

index 0bea9b5d326d36704f36728d9d82c1789d6011d2..e66572dc1b21c5bf1a20e0bafdc2364bd5e815ce 100644 (file)
@@ -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
index 6e5bf310750eb8990da65ae4b72d94675d99517d..0b7f869141a47dd61d64e3d3e04570297880434f 100644 (file)
@@ -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 ;