all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 18519eb69a76fc2807ed1372a3220f3dd7aa93b9 5092 bytes (raw)
name: test/lisp/textmodes/fill-tests.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
 
;;; fill-tests.el --- ERT tests for fill.el -*- lexical-binding: t -*-

;; Copyright (C) 2017-2023 Free Software Foundation, Inc.

;; Author:     Marcin Borkowski <mbork@mbork.pl>
;; Keywords:   text, wp

;; This file is part of GNU Emacs.

;; GNU Emacs 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.

;; GNU Emacs 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 GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; This package defines tests for the filling feature, specifically
;; the `fill-polish-nobreak-p' function.

;;; Code:

(require 'ert)

(ert-deftest fill-test-no-fill-polish-nobreak-p nil
  "Tests of the `fill-polish-nobreak-p' function."
  (with-temp-buffer
    (insert "Abc d efg (h ijk).")
    (setq fill-column 8)
    (setq-local fill-nobreak-predicate '())
    (fill-paragraph)
    (should (string= (buffer-string) "Abc d\nefg (h\nijk).")))
  (with-temp-buffer
    (insert "Abc d efg (h ijk).")
    (setq fill-column 8)
    (setq-local fill-nobreak-predicate '(fill-polish-nobreak-p))
    (fill-paragraph)
    (should (string= (buffer-string) "Abc\nd efg\n(h ijk)."))))

(ert-deftest fill-test-unbreakable-paragraph ()
  ;; See bug#45720 and bug#53537.
  :expected-result :failed
  (with-temp-buffer
    (let ((string "aaa =   baaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"))
      (insert string)
      (goto-char (point-min))
      (search-forward "b")
      (let* ((pos (point))
             (beg (pos-bol))
             (end (pos-eol))
             (fill-prefix (make-string (- pos beg) ?\s))
             ;; `fill-column' is too small to accommodate the current line
             (fill-column (- end beg 10)))
        (fill-region-as-paragraph beg end nil nil pos))
      (should (equal (buffer-string) string)))))

(ert-deftest fill-test-breakable-paragraph ()
  (with-temp-buffer
    (let ((string "aaa =   baaaaaaaa aaaaaaaaaa aaaaaaaaaa\n"))
      (insert string)
      (goto-char (point-min))
      (search-forward "b")
      (let* ((pos (point))
             (beg (pos-bol))
             (end (pos-eol))
             (fill-prefix (make-string (- pos beg) ?\s))
             ;; `fill-column' is too small to accommodate the current line
             (fill-column (- end beg 10)))
        (fill-region-as-paragraph beg end nil nil pos))
      (should (equal
               (buffer-string)
               "aaa =   baaaaaaaa aaaaaaaaaa\n         aaaaaaaaaa\n")))))

(ert-deftest test-fill-end-period ()
  (should
   (equal
    (with-temp-buffer
      (text-mode)
      (auto-fill-mode)
      (insert "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eius.")
      (self-insert-command 1 ?\s)
      (buffer-string))
    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eius. "))
  (should
   (equal
    (with-temp-buffer
      (text-mode)
      (auto-fill-mode)
      (insert "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eius.Foo")
      (forward-char -3)
      (self-insert-command 1 ?\s)
      (buffer-string))
    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eius. Foo")))

(ert-deftest test-fill-haskell ()
  (should
   (equal
    (with-temp-buffer
      (asm-mode)
      (dolist (line '("  ;; a b c"
                      "  ;; d e f"
                      "  ;; x y z"
                      "  ;; w"))
        (insert line "\n"))
      (goto-char (point-min))
      (end-of-line)
      (setf fill-column 10)
      (fill-paragraph nil)
      (buffer-string))
    "  ;; a b c
  ;; d e f
  ;; x y z
  ;; w
")))

(ert-deftest fill-test-balanced-fill-mode nil
  "Basic tests of the `balanced-fill-mode' option."
  (with-temp-buffer
    (insert "Ccc ccc a bb dddd bb bb a ccc a jjjjjjjjjj a eeeee a hhhhhhhh bb dddd.")
    (setq fill-column 15)
    (setq-local balanced-fill-mode nil)
    (fill-paragraph)
    (should (string= (buffer-string) "Ccc ccc a bb\ndddd bb bb a\nccc a\njjjjjjjjjj a\neeeee a\nhhhhhhhh bb\ndddd.")))
  (with-temp-buffer
    (insert "Ccc ccc a bb dddd bb bb a ccc a jjjjjjjjjj a eeeee a hhhhhhhh bb dddd.")
    (setq fill-column 15)
    (setq-local balanced-fill-mode t)
    (fill-paragraph)
    (should (string= (buffer-string) "Ccc ccc a\nbb dddd bb\nbb a ccc a\njjjjjjjjjj\na eeeee a\nhhhhhhhh\nbb dddd.")))
  (with-temp-buffer
    (insert "Ccc ccc a bb dddd bb bb a ccc a jjjjjjjjjj a eeeee a hhhhhhhh bb dddd.")
    (setq fill-column 15)
    (setq-local balanced-fill-mode t)
    (fill-paragraph 'full)
    (should (string= (buffer-string) "Ccc    ccc    a\nbb    dddd   bb\nbb   a  ccc   a\njjjjjjjjjj\na    eeeee    a\nhhhhhhhh\nbb dddd."))))

(provide 'fill-tests)

;;; fill-tests.el ends here

debug log:

solving 18519eb69a7 ...
found 18519eb69a7 in https://yhetil.org/emacs/c7a3fc7d-9df5-e509-e70d-bc41b98dc6f4@eastfarthing.com/
found ef822ba805b in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 ef822ba805b9672f4d8bee5db6e6e752f005c438	test/lisp/textmodes/fill-tests.el

applying [1/1] https://yhetil.org/emacs/c7a3fc7d-9df5-e509-e70d-bc41b98dc6f4@eastfarthing.com/
diff --git a/test/lisp/textmodes/fill-tests.el b/test/lisp/textmodes/fill-tests.el
index ef822ba805b..18519eb69a7 100644

Checking patch test/lisp/textmodes/fill-tests.el...
Applied patch test/lisp/textmodes/fill-tests.el cleanly.

index at:
100644 18519eb69a76fc2807ed1372a3220f3dd7aa93b9	test/lisp/textmodes/fill-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.