diff --git a/geesh/word.scm b/geesh/word.scm index e935a7d..c6b02d2 100644 --- a/geesh/word.scm +++ b/geesh/word.scm @@ -75,12 +75,13 @@ set @var{ifs}." (str (let ((str-parts (string-split str ifs))) (if (every string-null? str-parts) '(wedge) - (infix 'wedge (filter (compose not string-null?) - str-parts))))))) + (filter (lambda (x) + (or (eq? x 'wedge) (not (string-null? x)))) + (infix 'wedge str-parts))))))) (let ((wedged (append-map (cut wedge-apart <> ifs) (normalize-word qword)))) - (list-split wedged 'wedge))) + (filter pair? (list-split wedged 'wedge)))) (define (remove-quotes qword) "Remove quote forms from @var{qword} and concatenate the result into a diff --git a/tests/word.scm b/tests/word.scm index bdc4185..4f24535 100644 --- a/tests/word.scm +++ b/tests/word.scm @@ -60,6 +60,14 @@ the `set' built-in for details on these options.)" '("foo" "bar") (expand-word #f '("foo bar"))) +(test-equal "Splits a word on leading space" + '("foo" "bar") + (expand-word #f '("foo" " bar"))) + +(test-equal "Splits a word on trailing space" + '("foo" "bar") + (expand-word #f '("foo " "bar"))) + (test-equal "Ignores leading spaces" '("foo") (expand-word #f '(" foo")))