mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-29 19:30:36 +02:00
* module/texinfo/string-utils.scm (end-of-sentence?): New procedure. (make-text-wrapper): Append an extra space after LINE when it matches `end-of-sentence?' and COLLAPSE-WHITESPACE? is false. * test-suite/tests/texinfo.serialize.test ("test-serialize"): Adjust accordingly. * test-suite/tests/texinfo.string-utils.test ("text wrapping")["two spaces after end of sentence"]: New test prefix.
125 lines
5.3 KiB
Scheme
125 lines
5.3 KiB
Scheme
;;;; texinfo.string-utils.test -*- scheme -*-
|
|
;;;;
|
|
;;;; Copyright (C) 2003, 2009, 2010, 2013 Free Software Foundation, Inc.
|
|
;;;;
|
|
;;;; This program is free software; you can redistribute it and/or
|
|
;;;; modify it under the terms of the GNU General Public License as
|
|
;;;; published by the Free Software Foundation; either version 3 of the
|
|
;;;; License, or (at your option) any later version.
|
|
;;;;
|
|
;;;; This program is distributed in the hope that it will be useful,
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
;;;; General Public License for more details.
|
|
;;;;
|
|
;;;; You should have received a copy of the GNU General Public License
|
|
;;;; along with this library; if not, write to the Free Software
|
|
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
;;;; 02110-1301 USA
|
|
|
|
(define-module (test-suite test-string-utils)
|
|
#:use-module (test-suite lib)
|
|
#:use-module (texinfo string-utils))
|
|
|
|
|
|
;; **********************************************************************
|
|
;; Test for expand-tabs
|
|
;; **********************************************************************
|
|
(with-test-prefix "test-beginning-expansion"
|
|
(pass-if (equal? " Hello"
|
|
(expand-tabs "\tHello")))
|
|
(pass-if (equal? " Hello"
|
|
(expand-tabs "\t\tHello"))))
|
|
|
|
(with-test-prefix "test-ending-expansion"
|
|
(pass-if (equal? "Hello "
|
|
(expand-tabs "Hello\t")))
|
|
(pass-if (equal? "Hello "
|
|
(expand-tabs "Hello\t\t"))))
|
|
|
|
(with-test-prefix "test-middle-expansion"
|
|
(pass-if (equal? "Hello there" (expand-tabs "Hello\tthere")))
|
|
(pass-if (equal? "Hello there" (expand-tabs "Hello\t\tthere"))))
|
|
|
|
(with-test-prefix "test-alternate-tab-size"
|
|
(pass-if (equal? "Hello there"
|
|
(expand-tabs "Hello\tthere" 3)))
|
|
(pass-if (equal? "Hello there"
|
|
(expand-tabs "Hello\tthere" 4)))
|
|
(pass-if (equal? "Hello there"
|
|
(expand-tabs "Hello\tthere" 5))))
|
|
|
|
;; **********************************************************************
|
|
;; tests for escape-special-chars
|
|
;; **********************************************************************
|
|
(with-test-prefix "test-single-escape-char"
|
|
(pass-if (equal? "HeElElo"
|
|
(escape-special-chars "Hello" #\l #\E))))
|
|
|
|
(with-test-prefix "test-multiple-escape-chars"
|
|
(pass-if (equal? "HEeElElo"
|
|
(escape-special-chars "Hello" "el" #\E))))
|
|
|
|
|
|
;; **********************************************************************
|
|
;; tests for collapsing-multiple-chars
|
|
;; **********************************************************************
|
|
(with-test-prefix "collapse-repeated-chars"
|
|
(define test-string
|
|
"H e l l o t h e r e")
|
|
|
|
(with-test-prefix "test-basic-collapse"
|
|
(pass-if (equal? "H e l l o t h e r e"
|
|
(collapse-repeated-chars test-string))))
|
|
|
|
(with-test-prefix "test-choose-other-char"
|
|
(pass-if (equal? "H-e-l-l-o-t-h-e-r-e"
|
|
(collapse-repeated-chars (transform-string test-string #\space #\-)
|
|
#\-))))
|
|
|
|
(with-test-prefix "test-choose-maximum-repeats"
|
|
(pass-if (equal? "H e l l o t h e r e"
|
|
(collapse-repeated-chars test-string #\space 2)))
|
|
(pass-if (equal? "H e l l o t h e r e"
|
|
(collapse-repeated-chars test-string #\space 3)))))
|
|
|
|
;; **********************************************************************
|
|
;; Test of the object itself...
|
|
;; **********************************************************************
|
|
(with-test-prefix "text wrapping"
|
|
(define test-string "
|
|
The last language environment specified with
|
|
`set-language-environment'. This variable should be
|
|
set only with M-x customize, which is equivalent
|
|
to using the function `set-language-environment'.
|
|
")
|
|
|
|
(with-test-prefix "runs-without-exception"
|
|
(pass-if (->bool (fill-string test-string)))
|
|
(pass-if (->bool (fill-string test-string #:line-width 20)))
|
|
(pass-if (->bool (fill-string test-string #:initial-indent " * " #:tab-width 3))))
|
|
|
|
(with-test-prefix "test-fill-equivalent-to-joined-lines"
|
|
(pass-if (equal? (fill-string test-string)
|
|
(string-join (string->wrapped-lines test-string) "\n" 'infix))))
|
|
|
|
(with-test-prefix "test-no-collapse-ws"
|
|
(pass-if (equal? (fill-string test-string #:collapse-whitespace? #f)
|
|
"The last language environment specified with `set-language-environment'. This
|
|
variable should be set only with M-x customize, which is equivalent to using
|
|
the function `set-language-environment'.")))
|
|
|
|
(with-test-prefix "two spaces after end of sentence"
|
|
(pass-if-equal "This is a sentence. There should be two spaces before."
|
|
(fill-string "This is a sentence. There should be two spaces before."))
|
|
|
|
(pass-if-equal "This is version 2.0..."
|
|
(fill-string "This is version 2.0...")))
|
|
|
|
(with-test-prefix "test-no-word-break"
|
|
(pass-if (equal? "thisisalongword
|
|
blah
|
|
blah"
|
|
(fill-string "thisisalongword blah blah"
|
|
#:line-width 8
|
|
#:break-long-words? #f)))))
|