aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2014-09-05 15:32:55 +0200
committerMichael Albinus2014-09-05 15:32:55 +0200
commit40ae83c7c62bc0e424d828fcac852f1ca8dc3d24 (patch)
tree0c07dd1d56f1886366ee831716378116ac532f68
parent510a4a4e93a06557c62dcb622f8f8e9c3d533f53 (diff)
downloademacs-40ae83c7c62bc0e424d828fcac852f1ca8dc3d24.tar.gz
emacs-40ae83c7c62bc0e424d828fcac852f1ca8dc3d24.zip
New string collation tests.
* automated/fns-tests.el (fns-tests-compare-strings): In case `compare-strings' shall return t, check for this. (fns-tests-collate-strings, fns-tests-collate-sort): New tests.
-rw-r--r--test/ChangeLog6
-rw-r--r--test/automated/fns-tests.el80
2 files changed, 75 insertions, 11 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 5b7142845e7..28f6a918676 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,9 @@
12014-09-05 Michael Albinus <michael.albinus@gmx.de>
2
3 * automated/fns-tests.el (fns-tests-compare-strings): In case
4 `compare-strings' shall return t, check for this.
5 (fns-tests-collate-strings, fns-tests-collate-sort): New tests.
6
12014-09-03 Fabián Ezequiel Gallina <fgallina@gnu.org> 72014-09-03 Fabián Ezequiel Gallina <fgallina@gnu.org>
2 8
3 * automated/python-tests.el (python-indent-electric-colon-1): 9 * automated/python-tests.el (python-indent-electric-colon-1):
diff --git a/test/automated/fns-tests.el b/test/automated/fns-tests.el
index 9f55a873ea4..aa9f35f338e 100644
--- a/test/automated/fns-tests.el
+++ b/test/automated/fns-tests.el
@@ -79,12 +79,12 @@
79 (should-error (compare-strings "xyzzy" 0 'foo "zyxxy" 2 3)) 79 (should-error (compare-strings "xyzzy" 0 'foo "zyxxy" 2 3))
80 (should-error (compare-strings "xyzzy" 0 2 "zyxxy" 'foo 3)) 80 (should-error (compare-strings "xyzzy" 0 2 "zyxxy" 'foo 3))
81 (should-error (compare-strings "xyzzy" nil 3 "zyxxy" 4 'foo)) 81 (should-error (compare-strings "xyzzy" nil 3 "zyxxy" 4 'foo))
82 (should (compare-strings "" nil nil "" nil nil)) 82 (should (eq (compare-strings "" nil nil "" nil nil) t))
83 (should (compare-strings "" 0 0 "" 0 0)) 83 (should (eq (compare-strings "" 0 0 "" 0 0) t))
84 (should (compare-strings "test" nil nil "test" nil nil)) 84 (should (eq (compare-strings "test" nil nil "test" nil nil) t))
85 (should (compare-strings "test" nil nil "test" nil nil t)) 85 (should (eq (compare-strings "test" nil nil "test" nil nil t) t))
86 (should (compare-strings "test" nil nil "test" nil nil nil)) 86 (should (eq (compare-strings "test" nil nil "test" nil nil nil) t))
87 (should (compare-strings "Test" nil nil "test" nil nil t)) 87 (should (eq (compare-strings "Test" nil nil "test" nil nil t) t))
88 (should (= (compare-strings "Test" nil nil "test" nil nil) -1)) 88 (should (= (compare-strings "Test" nil nil "test" nil nil) -1))
89 (should (= (compare-strings "Test" nil nil "test" nil nil) -1)) 89 (should (= (compare-strings "Test" nil nil "test" nil nil) -1))
90 (should (= (compare-strings "test" nil nil "Test" nil nil) 1)) 90 (should (= (compare-strings "test" nil nil "Test" nil nil) 1))
@@ -92,22 +92,48 @@
92 (should (= (compare-strings "barbaz" nil nil "foobar" nil nil) -1)) 92 (should (= (compare-strings "barbaz" nil nil "foobar" nil nil) -1))
93 (should (= (compare-strings "foobaz" nil nil "farbaz" nil nil) 2)) 93 (should (= (compare-strings "foobaz" nil nil "farbaz" nil nil) 2))
94 (should (= (compare-strings "farbaz" nil nil "foobar" nil nil) -2)) 94 (should (= (compare-strings "farbaz" nil nil "foobar" nil nil) -2))
95 (should (compare-strings "abcxyz" 0 2 "abcprq" 0 2)) 95 (should (eq (compare-strings "abcxyz" 0 2 "abcprq" 0 2) t))
96 (should (compare-strings "abcxyz" 0 -3 "abcprq" 0 -3)) 96 (should (eq (compare-strings "abcxyz" 0 -3 "abcprq" 0 -3) t))
97 (should (= (compare-strings "abcxyz" 0 6 "abcprq" 0 6) 4)) 97 (should (= (compare-strings "abcxyz" 0 6 "abcprq" 0 6) 4))
98 (should (= (compare-strings "abcprq" 0 6 "abcxyz" 0 6) -4)) 98 (should (= (compare-strings "abcprq" 0 6 "abcxyz" 0 6) -4))
99 (should (compare-strings "xyzzy" -3 4 "azza" -3 3)) 99 (should (eq (compare-strings "xyzzy" -3 4 "azza" -3 3) t))
100 (should (compare-strings "こんにちはコンニチハ" nil nil "こんにちはコンニチハ" nil nil)) 100 (should (eq (compare-strings "こんにちはコンニチハ" nil nil "こんにちはコンニチハ" nil nil) t))
101 (should (= (compare-strings "んにちはコンニチハこ" nil nil "こんにちはコンニチハ" nil nil) 1)) 101 (should (= (compare-strings "んにちはコンニチハこ" nil nil "こんにちはコンニチハ" nil nil) 1))
102 (should (= (compare-strings "こんにちはコンニチハ" nil nil "んにちはコンニチハこ" nil nil) -1))) 102 (should (= (compare-strings "こんにちはコンニチハ" nil nil "んにちはコンニチハこ" nil nil) -1)))
103 103
104(ert-deftest fns-tests-collate-strings ()
105 ;; When there is no collation library, collation functions fall back
106 ;; to their lexicographic counterparts. We don't need to test then.
107 (skip-unless (not (ignore-errors (string-collate-equalp "" "" t))))
108
109 (should (string-collate-equalp "xyzzy" "xyzzy"))
110 (should-not (string-collate-equalp "xyzzy" "XYZZY"))
111
112 ;; In POSIX or C locales, collation order is lexicographic.
113 (should (string-collate-lessp "XYZZY" "xyzzy" "POSIX"))
114 ;; In a language specific locale, collation order is different.
115 (should (string-collate-lessp
116 "xyzzy" "XYZZY"
117 (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8")))
118
119 ;; Ignore case.
120 (should (string-collate-equalp "xyzzy" "XYZZY" nil t))
121
122 ;; Locale must be valid.
123 (should-error (string-collate-equalp "xyzzy" "xyzzy" "en_DE.UTF-8")))
124
125;; There must be a check for valid codepoints. (Check not implemented yet)
126; (should-error
127; (string-collate-equalp (string ?\x00110000) (string ?\x00110000)))
128;; Invalid UTF-8 sequences shall be indicated. How to create such strings?
129
104(ert-deftest fns-tests-sort () 130(ert-deftest fns-tests-sort ()
105 (should (equal (sort '(9 5 2 -1 5 3 8 7 4) (lambda (x y) (< x y))) 131 (should (equal (sort '(9 5 2 -1 5 3 8 7 4) (lambda (x y) (< x y)))
106 '(-1 2 3 4 5 5 7 8 9))) 132 '(-1 2 3 4 5 5 7 8 9)))
107 (should (equal (sort '(9 5 2 -1 5 3 8 7 4) (lambda (x y) (> x y))) 133 (should (equal (sort '(9 5 2 -1 5 3 8 7 4) (lambda (x y) (> x y)))
108 '(9 8 7 5 5 4 3 2 -1))) 134 '(9 8 7 5 5 4 3 2 -1)))
109 (should (equal (sort '[9 5 2 -1 5 3 8 7 4] (lambda (x y) (< x y))) 135 (should (equal (sort '[9 5 2 -1 5 3 8 7 4] (lambda (x y) (< x y)))
110 [-1 2 3 4 5 5 7 8 9])) 136 [-1 2 3 4 5 5 7 8 9]))
111 (should (equal (sort '[9 5 2 -1 5 3 8 7 4] (lambda (x y) (> x y))) 137 (should (equal (sort '[9 5 2 -1 5 3 8 7 4] (lambda (x y) (> x y)))
112 [9 8 7 5 5 4 3 2 -1])) 138 [9 8 7 5 5 4 3 2 -1]))
113 (should (equal 139 (should (equal
@@ -118,3 +144,35 @@
118 (lambda (x y) (< (car x) (car y)))) 144 (lambda (x y) (< (car x) (car y))))
119 [(8 . "xxx") (8 . "bbb") (8 . "ttt") (8 . "eee") 145 [(8 . "xxx") (8 . "bbb") (8 . "ttt") (8 . "eee")
120 (9 . "aaa") (9 . "zzz") (9 . "ppp") (9 . "fff")]))) 146 (9 . "aaa") (9 . "zzz") (9 . "ppp") (9 . "fff")])))
147
148(ert-deftest fns-tests-collate-sort ()
149 ;; Punctuation and whitespace characters are relevant for POSIX.
150 (should
151 (equal
152 (sort '("11" "12" "1 1" "1 2" "1.1" "1.2")
153 (lambda (a b) (string-collate-lessp a b "POSIX")))
154 '("1 1" "1 2" "1.1" "1.2" "11" "12")))
155 ;; Punctuation and whitespace characters are not taken into account
156 ;; for collation in other locales.
157 (should
158 (equal
159 (sort '("11" "12" "1 1" "1 2" "1.1" "1.2")
160 (lambda (a b)
161 (string-collate-lessp
162 a b (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8"))))
163 '("11" "1 1" "1.1" "12" "1 2" "1.2")))
164
165 ;; Diacritics are different letters for POSIX, they sort lexicographical.
166 (should
167 (equal
168 (sort '("Ævar" "Agustín" "Adrian" "Eli")
169 (lambda (a b) (string-collate-lessp a b "POSIX")))
170 '("Adrian" "Agustín" "Eli" "Ævar")))
171 ;; Diacritics are sorted between similar letters for other locales.
172 (should
173 (equal
174 (sort '("Ævar" "Agustín" "Adrian" "Eli")
175 (lambda (a b)
176 (string-collate-lessp
177 a b (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8"))))
178 '("Adrian" "Ævar" "Agustín" "Eli"))))