]> code.delx.au - gnu-emacs/blob - test/automated/fns-tests.el
Merge from emacs-24; up to 2014-07-04T02:28:54Z!dmantipov@yandex.ru
[gnu-emacs] / test / automated / fns-tests.el
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)))
31 (should (equal [] (reverse [])))
32 (should (equal [0] (reverse [0])))
33 (should (equal [1 2 3 4] (reverse (reverse [1 2 3 4]))))
34 (should (equal '(a b c d) (reverse (reverse '(a b c d)))))
35 (should (equal "xyzzy" (reverse (reverse "xyzzy"))))
36 (should (equal "こんにちは / コンニチハ" (reverse (reverse "こんにちは / コンニチハ")))))
37
38 (ert-deftest fns-tests-nreverse ()
39 (should-error (nreverse))
40 (should-error (nreverse 1))
41 (should-error (nreverse (make-char-table 'foo)))
42 (should (equal (nreverse "xyzzy") "yzzyx"))
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
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))))))
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))))))
72
73 (ert-deftest fns-tests-compare-strings ()
74 (should-error (compare-strings))
75 (should-error (compare-strings "xyzzy" "xyzzy"))
76 (should (= (compare-strings "xyzzy" 0 10 "zyxxy" 0 5) -1))
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)))
103
104 (ert-deftest fns-tests-sort ()
105 (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)))
107 (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)))
109 (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]))
111 (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]))
113 (should (equal
114 (sort
115 (vector
116 '(8 . "xxx") '(9 . "aaa") '(8 . "bbb") '(9 . "zzz")
117 '(9 . "ppp") '(8 . "ttt") '(8 . "eee") '(9 . "fff"))
118 (lambda (x y) (< (car x) (car y))))
119 [(8 . "xxx") (8 . "bbb") (8 . "ttt") (8 . "eee")
120 (9 . "aaa") (9 . "zzz") (9 . "ppp") (9 . "fff")])))