aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/src')
-rw-r--r--test/src/decompress-tests.el20
-rw-r--r--test/src/fns-tests.el58
-rw-r--r--test/src/lread-tests.el6
-rw-r--r--test/src/minibuf-tests.el15
-rw-r--r--test/src/process-tests.el26
-rw-r--r--test/src/xdisp-tests.el30
-rw-r--r--test/src/xml-tests.el14
7 files changed, 147 insertions, 22 deletions
diff --git a/test/src/decompress-tests.el b/test/src/decompress-tests.el
index 67a7fefb05e..520445cca5a 100644
--- a/test/src/decompress-tests.el
+++ b/test/src/decompress-tests.el
@@ -29,16 +29,16 @@
29 29
30(ert-deftest zlib--decompress () 30(ert-deftest zlib--decompress ()
31 "Test decompressing a gzipped file." 31 "Test decompressing a gzipped file."
32 (when (and (fboundp 'zlib-available-p) 32 (skip-unless (and (fboundp 'zlib-available-p)
33 (zlib-available-p)) 33 (zlib-available-p)))
34 (should (string= 34 (should (string=
35 (with-temp-buffer 35 (with-temp-buffer
36 (set-buffer-multibyte nil) 36 (set-buffer-multibyte nil)
37 (insert-file-contents-literally 37 (insert-file-contents-literally
38 (expand-file-name "foo.gz" zlib-tests-data-directory)) 38 (expand-file-name "foo.gz" zlib-tests-data-directory))
39 (zlib-decompress-region (point-min) (point-max)) 39 (zlib-decompress-region (point-min) (point-max))
40 (buffer-string)) 40 (buffer-string))
41 "foo\n")))) 41 "foo\n")))
42 42
43(provide 'decompress-tests) 43(provide 'decompress-tests)
44 44
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index a9daf878b81..e0aed2a71b6 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -1040,3 +1040,61 @@
1040 (let ((list (list 1))) 1040 (let ((list (list 1)))
1041 (setcdr list list) 1041 (setcdr list list)
1042 (length< list #x1fffe)))) 1042 (length< list #x1fffe))))
1043
1044(defun approx-equal (list1 list2)
1045 (and (equal (length list1) (length list2))
1046 (cl-loop for v1 in list1
1047 for v2 in list2
1048 when (not (or (= v1 v2)
1049 (< (abs (- v1 v2)) 0.1)))
1050 return nil
1051 finally return t)))
1052
1053(ert-deftest test-buffer-line-stats-nogap ()
1054 (with-temp-buffer
1055 (insert "")
1056 (should (approx-equal (buffer-line-statistics) '(0 0 0))))
1057 (with-temp-buffer
1058 (insert "123\n")
1059 (should (approx-equal (buffer-line-statistics) '(1 3 3))))
1060 (with-temp-buffer
1061 (insert "123\n12345\n123\n")
1062 (should (approx-equal (buffer-line-statistics) '(3 5 3.66))))
1063 (with-temp-buffer
1064 (insert "123\n12345\n123")
1065 (should (approx-equal (buffer-line-statistics) '(3 5 3.66))))
1066 (with-temp-buffer
1067 (insert "123\n12345")
1068 (should (approx-equal (buffer-line-statistics) '(2 5 4))))
1069
1070 (with-temp-buffer
1071 (insert "123\n12é45\n123\n")
1072 (should (approx-equal (buffer-line-statistics) '(3 6 4))))
1073
1074 (with-temp-buffer
1075 (insert "\n\n\n")
1076 (should (approx-equal (buffer-line-statistics) '(3 0 0)))))
1077
1078(ert-deftest test-buffer-line-stats-gap ()
1079 (with-temp-buffer
1080 (dotimes (_ 1000)
1081 (insert "12345678901234567890123456789012345678901234567890\n"))
1082 (goto-char (point-min))
1083 ;; This should make a gap appear.
1084 (insert "123\n")
1085 (delete-region (point-min) (point))
1086 (should (approx-equal (buffer-line-statistics) '(1000 50 50.0))))
1087 (with-temp-buffer
1088 (dotimes (_ 1000)
1089 (insert "12345678901234567890123456789012345678901234567890\n"))
1090 (goto-char (point-min))
1091 (insert "123\n")
1092 (should (approx-equal (buffer-line-statistics) '(1001 50 49.9))))
1093 (with-temp-buffer
1094 (dotimes (_ 1000)
1095 (insert "12345678901234567890123456789012345678901234567890\n"))
1096 (goto-char (point-min))
1097 (insert "123\n")
1098 (goto-char (point-max))
1099 (insert "fóo")
1100 (should (approx-equal (buffer-line-statistics) '(1002 50 49.9)))))
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index edf88214f97..f2a60bcf327 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -190,4 +190,10 @@ literals (Bug#20852)."
190(ert-deftest lread-circular-hash () 190(ert-deftest lread-circular-hash ()
191 (should-error (read "#s(hash-table data #0=(#0# . #0#))"))) 191 (should-error (read "#s(hash-table data #0=(#0# . #0#))")))
192 192
193(ert-deftest test-inhibit-interaction ()
194 (let ((inhibit-interaction t))
195 (should-error (read-char "foo: "))
196 (should-error (read-event "foo: "))
197 (should-error (read-char-exclusive "foo: "))))
198
193;;; lread-tests.el ends here 199;;; lread-tests.el ends here
diff --git a/test/src/minibuf-tests.el b/test/src/minibuf-tests.el
index b9cd255462d..28119fc999e 100644
--- a/test/src/minibuf-tests.el
+++ b/test/src/minibuf-tests.el
@@ -410,5 +410,20 @@
410 (should (equal (try-completion "baz" '("bAz" "baz")) 410 (should (equal (try-completion "baz" '("bAz" "baz"))
411 (try-completion "baz" '("baz" "bAz")))))) 411 (try-completion "baz" '("baz" "bAz"))))))
412 412
413(ert-deftest test-inhibit-interaction ()
414 (let ((inhibit-interaction t))
415 (should-error (read-from-minibuffer "foo: "))
416
417 (should-error (y-or-n-p "foo: "))
418 (should-error (yes-or-no-p "foo: "))
419 (should-error (read-blanks-no-input "foo: "))
420
421 ;; See that we get the expected error.
422 (should (eq (condition-case nil
423 (read-from-minibuffer "foo: ")
424 (inhibited-interaction 'inhibit)
425 (error nil))
426 'inhibit))))
427
413 428
414;;; minibuf-tests.el ends here 429;;; minibuf-tests.el ends here
diff --git a/test/src/process-tests.el b/test/src/process-tests.el
index ca98f54bdb1..57097cfa052 100644
--- a/test/src/process-tests.el
+++ b/test/src/process-tests.el
@@ -28,6 +28,7 @@
28(require 'puny) 28(require 'puny)
29(require 'rx) 29(require 'rx)
30(require 'subr-x) 30(require 'subr-x)
31(require 'dns)
31 32
32;; Timeout in seconds; the test fails if the timeout is reached. 33;; Timeout in seconds; the test fails if the timeout is reached.
33(defvar process-test-sentinel-wait-timeout 2.0) 34(defvar process-test-sentinel-wait-timeout 2.0)
@@ -350,14 +351,23 @@ See Bug#30460."
350;; All the following tests require working DNS, which appears not to 351;; All the following tests require working DNS, which appears not to
351;; be the case for hydra.nixos.org, so disable them there for now. 352;; be the case for hydra.nixos.org, so disable them there for now.
352 353
354;; This will need updating when IANA assign more IPv6 global ranges.
355(defun ipv6-is-available ()
356 (and (featurep 'make-network-process '(:family ipv6))
357 (cl-rassoc-if
358 (lambda (elt)
359 (and (eq 9 (length elt))
360 (= (logand (aref elt 0) #xe000) #x2000)))
361 (network-interface-list))))
362
353(ert-deftest lookup-family-specification () 363(ert-deftest lookup-family-specification ()
354 "`network-lookup-address-info' should only accept valid family symbols." 364 "`network-lookup-address-info' should only accept valid family symbols."
355 (skip-unless (not (getenv "EMACS_HYDRA_CI"))) 365 (skip-unless (not (getenv "EMACS_HYDRA_CI")))
356 (with-timeout (60 (ert-fail "Test timed out")) 366 (with-timeout (60 (ert-fail "Test timed out"))
357 (should-error (network-lookup-address-info "google.com" 'both)) 367 (should-error (network-lookup-address-info "localhost" 'both))
358 (should (network-lookup-address-info "google.com" 'ipv4)) 368 (should (network-lookup-address-info "localhost" 'ipv4))
359 (when (featurep 'make-network-process '(:family ipv6)) 369 (when (ipv6-is-available)
360 (should (network-lookup-address-info "google.com" 'ipv6))))) 370 (should (network-lookup-address-info "localhost" 'ipv6)))))
361 371
362(ert-deftest lookup-unicode-domains () 372(ert-deftest lookup-unicode-domains ()
363 "Unicode domains should fail." 373 "Unicode domains should fail."
@@ -380,7 +390,8 @@ See Bug#30460."
380 (addresses-v4 (network-lookup-address-info "google.com" 'ipv4))) 390 (addresses-v4 (network-lookup-address-info "google.com" 'ipv4)))
381 (should addresses-both) 391 (should addresses-both)
382 (should addresses-v4)) 392 (should addresses-v4))
383 (when (featurep 'make-network-process '(:family ipv6)) 393 (when (and (ipv6-is-available)
394 (dns-query "google.com" 'AAAA))
384 (should (network-lookup-address-info "google.com" 'ipv6))))) 395 (should (network-lookup-address-info "google.com" 'ipv6)))))
385 396
386(ert-deftest non-existent-lookup-failure () 397(ert-deftest non-existent-lookup-failure ()
@@ -565,6 +576,11 @@ FD_SETSIZE file descriptors (Bug#24325)."
565 (should (memq (process-status process) '(run exit))) 576 (should (memq (process-status process) '(run exit)))
566 (when (process-live-p process) 577 (when (process-live-p process)
567 (process-send-eof process)) 578 (process-send-eof process))
579 ;; FIXME: This `sleep-for' shouldn't be needed. It
580 ;; indicates a bug in Emacs; perhaps SIGCHLD is
581 ;; received in parallel with `accept-process-output',
582 ;; causing the latter to hang.
583 (sleep-for 0.1)
568 (while (accept-process-output process)) 584 (while (accept-process-output process))
569 (should (eq (process-status process) 'exit)) 585 (should (eq (process-status process) 'exit))
570 ;; If there's an error between fork and exec, Emacs 586 ;; If there's an error between fork and exec, Emacs
diff --git a/test/src/xdisp-tests.el b/test/src/xdisp-tests.el
index d13ce77a997..ec96d777ffb 100644
--- a/test/src/xdisp-tests.el
+++ b/test/src/xdisp-tests.el
@@ -72,4 +72,34 @@
72 (should (equal (nth 0 posns) (nth 1 posns))) 72 (should (equal (nth 0 posns) (nth 1 posns)))
73 (should (equal (nth 1 posns) (nth 2 posns))))) 73 (should (equal (nth 1 posns) (nth 2 posns)))))
74 74
75(ert-deftest xdisp-tests--window-text-pixel-size () ;; bug#45748
76 (with-temp-buffer
77 (insert "xxx")
78 (let* ((window
79 (display-buffer (current-buffer) '(display-buffer-in-child-frame . nil)))
80 (char-width (frame-char-width))
81 (size (window-text-pixel-size nil t t)))
82 (delete-frame (window-frame window))
83 (should (equal (/ (car size) char-width) 3)))))
84
85(ert-deftest xdisp-tests--window-text-pixel-size-leading-space () ;; bug#45748
86 (with-temp-buffer
87 (insert " xx")
88 (let* ((window
89 (display-buffer (current-buffer) '(display-buffer-in-child-frame . nil)))
90 (char-width (frame-char-width))
91 (size (window-text-pixel-size nil t t)))
92 (delete-frame (window-frame window))
93 (should (equal (/ (car size) char-width) 3)))))
94
95(ert-deftest xdisp-tests--window-text-pixel-size-trailing-space () ;; bug#45748
96 (with-temp-buffer
97 (insert "xx ")
98 (let* ((window
99 (display-buffer (current-buffer) '(display-buffer-in-child-frame . nil)))
100 (char-width (frame-char-width))
101 (size (window-text-pixel-size nil t t)))
102 (delete-frame (window-frame window))
103 (should (equal (/ (car size) char-width) 3)))))
104
75;;; xdisp-tests.el ends here 105;;; xdisp-tests.el ends here
diff --git a/test/src/xml-tests.el b/test/src/xml-tests.el
index 632cf965fa2..a35b4d2ccc8 100644
--- a/test/src/xml-tests.el
+++ b/test/src/xml-tests.el
@@ -44,12 +44,12 @@
44 44
45(ert-deftest libxml-tests () 45(ert-deftest libxml-tests ()
46 "Test libxml." 46 "Test libxml."
47 (when (fboundp 'libxml-parse-xml-region) 47 (skip-unless (fboundp 'libxml-parse-xml-region))
48 (with-temp-buffer 48 (with-temp-buffer
49 (dolist (test libxml-tests--data-comments-preserved) 49 (dolist (test libxml-tests--data-comments-preserved)
50 (erase-buffer) 50 (erase-buffer)
51 (insert (car test)) 51 (insert (car test))
52 (should (equal (cdr test) 52 (should (equal (cdr test)
53 (libxml-parse-xml-region (point-min) (point-max)))))))) 53 (libxml-parse-xml-region (point-min) (point-max)))))))
54 54
55;;; libxml-tests.el ends here 55;;; libxml-tests.el ends here