update unidata-gen.el
[bpt/emacs.git] / test / automated / fns-tests.el
CommitLineData
92491099
DA
1;;; fns-tests.el --- tests for src/fns.c
2
3;; Copyright (C) 2014 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; This program is free software: you can redistribute it and/or
8;; modify it under the terms of the GNU General Public License as
9;; published by the Free Software Foundation, either version 3 of the
10;; License, or (at your option) any later version.
11;;
12;; This program is distributed in the hope that it will be useful, but
13;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15;; General Public License for more details.
16;;
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see `http://www.gnu.org/licenses/'.
19
20;;; Commentary:
21
22;;; Code:
23
24(require 'cl-lib)
25(eval-when-compile (require 'cl))
26
27(ert-deftest fns-tests-reverse ()
28 (should-error (reverse))
29 (should-error (reverse 1))
30 (should-error (reverse (make-char-table 'foo)))
ddc30c99
DA
31 (should (equal [] (reverse [])))
32 (should (equal [0] (reverse [0])))
92491099 33 (should (equal [1 2 3 4] (reverse (reverse [1 2 3 4]))))
ddc30c99 34 (should (equal '(a b c d) (reverse (reverse '(a b c d)))))
92491099
DA
35 (should (equal "xyzzy" (reverse (reverse "xyzzy"))))
36 (should (equal "こんにちは / コンニチハ" (reverse (reverse "こんにちは / コンニチハ")))))
37
ddc30c99
DA
38(ert-deftest fns-tests-nreverse ()
39 (should-error (nreverse))
40 (should-error (nreverse 1))
41 (should-error (nreverse (make-char-table 'foo)))
a7517f0f 42 (should (equal (nreverse "xyzzy") "yzzyx"))
ddc30c99
DA
43 (let ((A []))
44 (nreverse A)
45 (should (equal A [])))
46 (let ((A [0]))
47 (nreverse A)
48 (should (equal A [0])))
49 (let ((A [1 2 3 4]))
50 (nreverse A)
51 (should (equal A [4 3 2 1])))
52 (let ((A [1 2 3 4]))
53 (nreverse A)
54 (nreverse A)
55 (should (equal A [1 2 3 4])))
56 (let* ((A [1 2 3 4])
57 (B (nreverse (nreverse A))))
58 (should (equal A B))))
59
92491099
DA
60(ert-deftest fns-tests-reverse-bool-vector ()
61 (let ((A (make-bool-vector 10 nil)))
62 (dotimes (i 5) (aset A i t))
63 (should (equal [nil nil nil nil nil t t t t t] (vconcat (reverse A))))
64 (should (equal A (reverse (reverse A))))))
ddc30c99
DA
65
66(ert-deftest fns-tests-nreverse-bool-vector ()
67 (let ((A (make-bool-vector 10 nil)))
68 (dotimes (i 5) (aset A i t))
69 (nreverse A)
70 (should (equal [nil nil nil nil nil t t t t t] (vconcat A)))
71 (should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A))))))
5697ca55
DA
72
73(ert-deftest fns-tests-compare-strings ()
74 (should-error (compare-strings))
75 (should-error (compare-strings "xyzzy" "xyzzy"))
76 (should-error (compare-strings "xyzzy" 0 10 "zyxxy" 0 5))
77 (should-error (compare-strings "xyzzy" 0 5 "zyxxy" -1 2))
78 (should-error (compare-strings "xyzzy" 'foo nil "zyxxy" 0 1))
79 (should-error (compare-strings "xyzzy" 0 'foo "zyxxy" 2 3))
80 (should-error (compare-strings "xyzzy" 0 2 "zyxxy" 'foo 3))
81 (should-error (compare-strings "xyzzy" nil 3 "zyxxy" 4 'foo))
82 (should (compare-strings "" nil nil "" nil nil))
83 (should (compare-strings "" 0 0 "" 0 0))
84 (should (compare-strings "test" nil nil "test" nil nil))
85 (should (compare-strings "test" nil nil "test" nil nil t))
86 (should (compare-strings "test" nil nil "test" nil nil nil))
87 (should (compare-strings "Test" nil nil "test" nil nil t))
88 (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))
91 (should (= (compare-strings "foobaz" nil nil "barbaz" 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))
94 (should (= (compare-strings "farbaz" nil nil "foobar" nil nil) -2))
95 (should (compare-strings "abcxyz" 0 2 "abcprq" 0 2))
96 (should (compare-strings "abcxyz" 0 -3 "abcprq" 0 -3))
97 (should (= (compare-strings "abcxyz" 0 6 "abcprq" 0 6) 4))
98 (should (= (compare-strings "abcprq" 0 6 "abcxyz" 0 6) -4))
99 (should (compare-strings "xyzzy" -3 4 "azza" -3 3))
100 (should (compare-strings "こんにちはコンニチハ" nil nil "こんにちはコンニチハ" nil nil))
101 (should (= (compare-strings "んにちはコンニチハこ" nil nil "こんにちはコンニチハ" nil nil) 1))
102 (should (= (compare-strings "こんにちはコンニチハ" nil nil "んにちはコンニチハこ" nil nil) -1)))