/
test-modtest.el
100 lines (81 loc) · 3.56 KB
/
test-modtest.el
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
;;; test-modtest.el --- test modtest.nim -*- lexical-binding: t; -*-
;; Author: Kaushal Modi <kaushal.modi@gmail.com>
;;; License:
;; This program 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.
;;
;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'ert)
(add-to-list 'load-path
(file-name-directory (or #$ (expand-file-name (buffer-file-name)))))
(require 'modtest)
(ert-deftest modtest-get-type ()
(should (eq 'string (modtest-get-type "abc")))
(should (eq 'integer (modtest-get-type 42)))
(should (eq 'float (modtest-get-type 42.0)))
(should (eq 'symbol (modtest-get-type nil)))
(should (eq 'symbol (modtest-get-type t)))
(should (eq 'symbol (modtest-get-type '())))
(should (eq 'cons (modtest-get-type (cons 1 2))))
(should (eq 'cons (modtest-get-type '(1 . 2))))
(should (eq 'cons (modtest-get-type '(1 2 3)))) ;Interestingly, this is a "cons" too.
(should (eq 'cons (modtest-get-type (list 1 2 3))))) ;.. and this too!
(ert-deftest modtest-is-true ()
(should (eq nil (modtest-is-true nil)))
(should (eq nil (modtest-is-true '())))
(should (eq nil (modtest-is-true ())))
(should (eq nil (modtest-is-true (not t))))
(should (eq t (modtest-is-true "abc")))
(should (eq t (modtest-is-true "")))
(should (eq t (modtest-is-true 42)))
(should (eq t (modtest-is-true 42.0)))
(should (eq t (modtest-is-true t)))
(should (eq t (modtest-is-true (cons 1 2))))
(should (eq t (modtest-is-true '(1 . 2))))
(should (eq t (modtest-is-true '(1 2 3))))
(should (eq t (modtest-is-true (list 1 2 3)))))
(ert-deftest modtest-non-local-exit-signal-test ()
(should-error (modtest-signal)))
(ert-deftest modtest-non-local-exit-throw-test ()
(should (equal
(catch 'tag
(modtest-throw)
(ert-fail "expected throw"))
42)))
(ert-deftest modtest-return-t ()
(should (eq t (modtest-return-t 0)))
(should (eq t (modtest-return-t "abc")))
(should (eq t (modtest-return-t t)))
(should (eq t (modtest-return-t nil)))
(should (eq t (modtest-return-t ?a))))
(ert-deftest modtest-sum ()
(should (eq 10 (modtest-sum 3 7)))
(should-error (modtest-sum "1" 2) :type 'wrong-type-argument)
(should-error (modtest-sum 2 "1") :type 'wrong-type-argument))
(ert-deftest modtest-string ()
(should (string= "The quick brown fox jumped over the lazy dog." (modtest-lazy)))
(should (string= "Hello World" (modtest-hello "World"))))
(ert-deftest modtest-uname ()
(let ((ref-uname-a-output (progn
(require 'subr-x)
(string-trim (shell-command-to-string "uname -a")))))
(should (string= ref-uname-a-output (modtest-uname "-a")))))
(ert-deftest modtest-vector-test ()
(dolist (s '(2 10 100 1000))
(dolist (e '(42 foo "foo" 3.14))
(let* ((v-ref (make-vector 2 e))
(eq-ref (eq (aref v-ref 0) (aref v-ref 1)))
(v-test (make-vector s nil)))
(should (eq (modtest-vector-fill v-test e) t))
(should (eq (modtest-vector-eq v-test e) eq-ref))))))
;;; test-modtest.el ends here