unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 4b2eeaf5099fd6480dede87468048f317cdd8a56 7686 bytes (raw)
name: test/src/casefiddle-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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
 
;;; casefiddle-tests.el --- tests for casefiddle.c functions -*- lexical-binding: t -*-

;; Copyright (C) 2015-2016 Free Software Foundation, Inc.

;; 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 <http://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)

(ert-deftest casefiddle-tests-char-properties ()
  "Sanity check of character Unicode properties."
  (should-not
   (let (errors)
     ;;            character  uppercase  lowercase  titlecase
     (dolist (test '((?A nil ?a nil)
                     (?a ?A nil ?A)
                     (?Ł nil ?ł nil)
                     (?ł ?Ł nil ?Ł)

                     (?DŽ nil ?dž ?Dž)
                     (?Dž ?DŽ ?dž ?Dž)
                     (?dž ?DŽ nil ?Dž)

                     (?Σ nil ?σ nil)
                     (?σ ?Σ nil ?Σ)
                     (?ς ?Σ nil ?Σ)

                     (?ⅷ ?Ⅷ nil ?Ⅷ)
                     (?Ⅷ nil ?ⅷ nil)))
       (let ((ch (car test))
             (expected (cdr test))
             (props '(uppercase lowercase titlecase)))
         (while props
           (let ((got (get-char-code-property ch (car props))))
             (unless (equal (car expected) got)
               (push (format "\n%c %s; expected: %s but got: %s"
                             ch (car props) (car expected) got)
                     errors)))
           (setq props (cdr props) expected (cdr expected)))))
     (when errors
       (mapconcat (lambda (line) line) (nreverse errors) "")))))


(defconst casefiddle-tests--characters
  ;; character  uppercase  lowercase  titlecase
  '((?A ?A ?a ?A)
    (?a ?A ?a ?A)
    (?Ł ?Ł ?ł ?Ł)
    (?ł ?Ł ?ł ?Ł)

    ;; FIXME: We should have:
    ;;(?DŽ ?DŽ ?dž ?Dž)
    ;; but instead we have:
    (?DŽ ?DŽ ?dž ?DŽ)
    ;; FIXME: Those two are broken at the moment:
    ;;(?Dž ?DŽ ?dž ?Dž)
    ;;(?dž ?DŽ ?dž ?Dž)

    (?Σ ?Σ ?σ ?Σ)
    (?σ ?Σ ?σ ?Σ)
    ;; FIXME: Another broken one:
    ;;(?ς ?Σ ?ς ?Σ)

    (?Ⅷ ?Ⅷ ?ⅷ ?Ⅷ)
    (?ⅷ ?Ⅷ ?ⅷ ?Ⅷ)))


(ert-deftest casefiddle-tests-case-table ()
  "Sanity check of down and up case tables."
  (should-not
   (let (errors
         (up (case-table-get-table (current-case-table) 'up))
         (down (case-table-get-table (current-case-table) 'down)))
     (dolist (test casefiddle-tests--characters)
       (let ((ch (car test))
             (expected (cdr test))
             (props '(uppercase lowercase))
             (tabs (list up down)))
         (while props
           (let ((got (aref (car tabs) ch)))
             (unless (equal (car expected) got)
               (push (format "\n%c %s; expected: %s but got: %s"
                             ch (car props) (car expected) got)
                     errors)))
           (setq props (cdr props) tabs (cdr tabs) expected (cdr expected)))))
     (when errors
       (mapconcat (lambda (line) line) (nreverse errors) "")))))


(ert-deftest casefiddle-tests-casing-character ()
  (should-not
   (let (errors)
     (dolist (test casefiddle-tests--characters)
       (let ((ch (car test))
             (expected (cdr test))
             (funcs '(upcase downcase capitalize)))
         (while funcs
           (let ((got (funcall (car funcs) ch)))
             (unless (equal (car expected) got)
               (push (format "\n%c %s; expected: %s but got: %s"
                             ch (car funcs) (car expected) got)
                     errors)))
           (setq funcs (cdr funcs) expected (cdr expected)))))
     (when errors
       (mapconcat (lambda (line) line) (nreverse errors) "")))))


(ert-deftest casefiddle-tests-casing-word ()
  (with-temp-buffer
    (dolist (test '((upcase-word     . "FOO Bar")
                    (downcase-word   . "foo Bar")
                    (capitalize-word . "Foo Bar")))
      (dolist (back '(nil t))
        (delete-region (point-min) (point-max))
        (insert "foO Bar")
        (goto-char (+ (if back 4 0) (point-min)))
        (funcall (car test) (if back -1 1))
        (should (string-equal (cdr test) (buffer-string)))
        (should (equal (+ (if back 4 3) (point-min)) (point)))))))


(ert-deftest casefiddle-tests-casing ()
  (should-not
   (let (errors)
     (with-temp-buffer
       (dolist
           (test
            ;; input  upcase  downcase  capitalize  upcase-initials
            '(("Foo baR" "FOO BAR" "foo bar" "Foo Bar" "Foo BaR")
              ("Ⅷ ⅷ" "Ⅷ Ⅷ" "ⅷ ⅷ" "Ⅷ Ⅷ" "Ⅷ Ⅷ")
              ;; FIXME: Everything below is broken at the moment.  Here’s what
              ;; should happen:
              ;;("DŽUNGLA" "DŽUNGLA" "džungla" "Džungla" "DžUNGLA")
              ;;("Džungla" "DŽUNGLA" "džungla" "Džungla" "Džungla")
              ;;("džungla" "DŽUNGLA" "džungla" "Džungla" "Džungla")
              ;;("define" "DEFINE" "define" "Define" "Define")
              ;;("fish" "FIsh" "fish" "Fish" "Fish")
              ;;("Straße" "STRASSE" "straße" "Straße" "Straße")
              ;;("ΌΣΟΣ" "ΌΣΟΣ" "όσος" "Όσος" "Όσος")
              ;;("όσος" "ΌΣΟΣ" "όσος" "Όσος" "Όσος")
              ;; And here’s what is actually happening:
              ("DŽUNGLA" "DŽUNGLA" "džungla" "DŽungla" "DŽUNGLA")
              ("Džungla" "DžUNGLA" "džungla" "Džungla" "Džungla")
              ("džungla" "DŽUNGLA" "džungla" "DŽungla" "DŽungla")
              ("define" "DEfiNE" "define" "Define" "Define")
              ("fish" "fiSH" "fish" "fish" "fish")
              ("Straße" "STRAßE" "straße" "Straße" "Straße")
              ("ΌΣΟΣ" "ΌΣΟΣ" "όσοσ" "Όσοσ" "ΌΣΟΣ")
              ("όσος" "ΌΣΟς" "όσος" "Όσος" "Όσος"))
            (nreverse errors))
         (let* ((input (car test))
                (expected (cdr test))
                (check (lambda (func got)
                         (unless (string-equal got (car expected))
                           (let ((fmt (length (symbol-name func))))
                             (setq fmt (format "\n%%%ds: %%s" (max fmt 8)))
                             (push (format (concat fmt fmt fmt)
                                           func input
                                           "expected" (car expected)
                                           "but got" got)
                                   errors))))))
           (dolist (func '((upcase . upcase-region)
                           (downcase . downcase-region)
                           (capitalize . capitalize-region)
                           (upcase-initials . upcase-initials-region)))
             (funcall check (car func) (funcall (car func) input))
             (funcall check (cdr func) (progn
                                         (delete-region (point-min) (point-max))
                                         (insert input)
                                         (funcall (cdr func)
                                                  (point-min) (point-max))
                                         (buffer-string)))
             (setq expected (cdr expected)))))))))


;;; casefiddle-tests.el ends here

debug log:

solving 4b2eeaf ...
found 4b2eeaf in https://yhetil.org/emacs-bugs/1475543441-10493-1-git-send-email-mina86@mina86.com/

applying [1/1] https://yhetil.org/emacs-bugs/1475543441-10493-1-git-send-email-mina86@mina86.com/
diff --git a/test/src/casefiddle-tests.el b/test/src/casefiddle-tests.el
new file mode 100644
index 0000000..4b2eeaf

Checking patch test/src/casefiddle-tests.el...
Applied patch test/src/casefiddle-tests.el cleanly.

index at:
100644 4b2eeaf5099fd6480dede87468048f317cdd8a56	test/src/casefiddle-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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).