# HG changeset patch # User Steve Losh # Date 1574033092 18000 # Node ID 3e34737c4a7e9659d64d5832e7739c00777d4826 # Parent a9ab8d792a4d004eadbd4bc24a0f902f4c807e01 Fix wrapping for indented lines of multiline strings inside lists diff -r a9ab8d792a4d -r 3e34737c4a7e bobbin.asd --- a/bobbin.asd Thu Mar 07 12:44:55 2019 -0500 +++ b/bobbin.asd Sun Nov 17 18:24:52 2019 -0500 @@ -4,7 +4,7 @@ :homepage "https://sjl.bitbucket.io/bobbin/" :license "MIT" - :version "1.0.0" + :version "1.0.1" :depends-on (:split-sequence) diff -r a9ab8d792a4d -r 3e34737c4a7e docs/03-changelog.markdown --- a/docs/03-changelog.markdown Thu Mar 07 12:44:55 2019 -0500 +++ b/docs/03-changelog.markdown Sun Nov 17 18:24:52 2019 -0500 @@ -5,6 +5,12 @@ [TOC] +v1.0.1 +------ + +Fixed a bug that caused indented lines inside of multiline strings to be +incorrectly wrapped. + v1.0.0 ------ diff -r a9ab8d792a4d -r 3e34737c4a7e src/main.lisp --- a/src/main.lisp Thu Mar 07 12:44:55 2019 -0500 +++ b/src/main.lisp Sun Nov 17 18:24:52 2019 -0500 @@ -50,9 +50,18 @@ (defun wrap-lines (strings width) "Wrap a list of `strings` to `width`, returning a list of strings." - (mapcan (lambda (string) - (split-sequence:split-sequence #\newline (wrap-line string width))) - strings)) + ;; This is mildly tricky because we want to correctly handle indented lines + ;; inside of multiline strings inside the list. + (let ((lines (mapcan + ;; Split and flatten any multiline strings in the list first. + (lambda (string) + (split-sequence:split-sequence #\newline string)) + strings))) + (mapcan + ;; Then wrap each string in the list and flatten the results. + (lambda (line) + (split-sequence:split-sequence #\newline (wrap-line line width))) + lines))) (defun wrap-string (string width) "Wrap a multi-line string, returning a multi-line string." diff -r a9ab8d792a4d -r 3e34737c4a7e test/tests.lisp --- a/test/tests.lisp Thu Mar 07 12:44:55 2019 -0500 +++ b/test/tests.lisp Sun Nov 17 18:24:52 2019 -0500 @@ -11,11 +11,14 @@ (defun run-tests () (1am:run)) +(defun f (&rest args) + (apply #'format nil args)) + (defmacro check (input width result) (if (stringp input) `(is (string= (format nil ,result) - (bobbin:wrap (format nil ,input) ,width))) - `(is (equal ',result (bobbin:wrap ',input ,width))))) + (bobbin:wrap (f ,input) ,width))) + `(is (equal ',result (bobbin:wrap (mapcar #'f ',input) ,width))))) ;;;; Tests -------------------------------------------------------------------- @@ -62,7 +65,9 @@ (define-test indentation (check " foo~% bar" 50 " foo~% bar") - (check " foo bar" 3 "foo~%bar")) + (check " foo bar" 3 "foo~%bar") + (check " foo~% bar" 5 " foo~% bar") + (check (" foo~% bar") 5 (" foo" " bar"))) (define-test lists (check ("foo bar baz")