diff options
| author | Vibhav Pant | 2023-06-06 19:30:27 +0530 |
|---|---|---|
| committer | Vibhav Pant | 2023-06-06 19:30:27 +0530 |
| commit | 49ffcbf86a32a8a217538d4df3736fe069ccf35d (patch) | |
| tree | a5f16157cc20fb19a844473a6fbd2b434f4c8260 /test/src | |
| parent | af569fa3d90a717983b743eb97adbf869c6d1736 (diff) | |
| parent | 7ca1d782f5910d0c3978c6798a45c6854ec668c7 (diff) | |
| download | emacs-49ffcbf86a32a8a217538d4df3736fe069ccf35d.tar.gz emacs-49ffcbf86a32a8a217538d4df3736fe069ccf35d.zip | |
Merge branch 'master' into scratch/comp-static-data
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/comp-resources/comp-test-funcs.el | 21 | ||||
| -rw-r--r-- | test/src/comp-tests.el | 57 | ||||
| -rw-r--r-- | test/src/eval-tests.el | 35 | ||||
| -rw-r--r-- | test/src/fns-tests.el | 43 | ||||
| -rw-r--r-- | test/src/keymap-tests.el | 18 | ||||
| -rw-r--r-- | test/src/lread-tests.el | 39 | ||||
| -rw-r--r-- | test/src/sqlite-tests.el | 23 | ||||
| -rw-r--r-- | test/src/treesit-tests.el | 123 | ||||
| -rw-r--r-- | test/src/xdisp-tests.el | 2 |
9 files changed, 293 insertions, 68 deletions
diff --git a/test/src/comp-resources/comp-test-funcs.el b/test/src/comp-resources/comp-test-funcs.el index f0783c1b86a..3c535fb1424 100644 --- a/test/src/comp-resources/comp-test-funcs.el +++ b/test/src/comp-resources/comp-test-funcs.el | |||
| @@ -23,6 +23,8 @@ | |||
| 23 | 23 | ||
| 24 | ;;; Code: | 24 | ;;; Code: |
| 25 | 25 | ||
| 26 | (require 'cl-lib) | ||
| 27 | |||
| 26 | (defvar comp-tests-var1 3) | 28 | (defvar comp-tests-var1 3) |
| 27 | 29 | ||
| 28 | (defun comp-tests-varref-f () | 30 | (defun comp-tests-varref-f () |
| @@ -518,6 +520,25 @@ | |||
| 518 | (defun comp-test-48029-nonascii-žžž-f (arg) | 520 | (defun comp-test-48029-nonascii-žžž-f (arg) |
| 519 | (when arg t)) | 521 | (when arg t)) |
| 520 | 522 | ||
| 523 | (defun comp-test-62537-1-f ()) | ||
| 524 | |||
| 525 | (defun comp-test-62537-2-f () | ||
| 526 | (when (let ((val (comp-test-62537-1-f))) | ||
| 527 | (cond | ||
| 528 | ((eq val 'x) | ||
| 529 | t) | ||
| 530 | ((eq val 'y) | ||
| 531 | 'y))) | ||
| 532 | (comp-test-62537-1-f)) | ||
| 533 | t) | ||
| 534 | |||
| 535 | (cl-defstruct comp-test-struct) | ||
| 536 | |||
| 537 | (defun comp-test-63674-1-f (x) | ||
| 538 | (or | ||
| 539 | (if (comp-test-struct-p pkg) x) | ||
| 540 | t)) | ||
| 541 | |||
| 521 | 542 | ||
| 522 | ;;;;;;;;;;;;;;;;;;;; | 543 | ;;;;;;;;;;;;;;;;;;;; |
| 523 | ;; Tromey's tests ;; | 544 | ;; Tromey's tests ;; |
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index a4942be107f..fe991f91ca7 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el | |||
| @@ -305,7 +305,8 @@ Check that the resulting binaries do not differ." | |||
| 305 | (lambda () (throw 'foo 3))) | 305 | (lambda () (throw 'foo 3))) |
| 306 | 3)) | 306 | 3)) |
| 307 | (should (= (catch 'foo | 307 | (should (= (catch 'foo |
| 308 | (comp-tests-throw-f 3))))) | 308 | (comp-tests-throw-f 3)) |
| 309 | 3))) | ||
| 309 | 310 | ||
| 310 | (comp-deftest gc () | 311 | (comp-deftest gc () |
| 311 | "Try to do some longer computation to let the GC kick in." | 312 | "Try to do some longer computation to let the GC kick in." |
| @@ -446,7 +447,7 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-03/msg00914.html." | |||
| 446 | (should (equal comp-test-primitive-advice '(3 4)))) | 447 | (should (equal comp-test-primitive-advice '(3 4)))) |
| 447 | (advice-remove #'+ f)))) | 448 | (advice-remove #'+ f)))) |
| 448 | 449 | ||
| 449 | (defvar comp-test-primitive-redefine-args) | 450 | (defvar comp-test-primitive-redefine-args nil) |
| 450 | (comp-deftest primitive-redefine () | 451 | (comp-deftest primitive-redefine () |
| 451 | "Test effectiveness of primitive redefinition." | 452 | "Test effectiveness of primitive redefinition." |
| 452 | (cl-letf ((comp-test-primitive-redefine-args nil) | 453 | (cl-letf ((comp-test-primitive-redefine-args nil) |
| @@ -532,6 +533,22 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-03/msg00914.html." | |||
| 532 | (should (subr-native-elisp-p | 533 | (should (subr-native-elisp-p |
| 533 | (symbol-function 'comp-test-48029-nonascii-žžž-f)))) | 534 | (symbol-function 'comp-test-48029-nonascii-žžž-f)))) |
| 534 | 535 | ||
| 536 | (comp-deftest 61917-1 () | ||
| 537 | "Verify we can compile calls to redefined primitives with | ||
| 538 | dedicated byte-op code." | ||
| 539 | (let (x | ||
| 540 | (f (lambda (_fn &rest args) | ||
| 541 | (setq comp-test-primitive-redefine-args args)))) | ||
| 542 | (advice-add #'delete-region :around f) | ||
| 543 | (unwind-protect | ||
| 544 | (setf x (native-compile | ||
| 545 | '(lambda () | ||
| 546 | (delete-region 1 2)))) | ||
| 547 | (should (subr-native-elisp-p x)) | ||
| 548 | (funcall x) | ||
| 549 | (advice-remove #'delete-region f) | ||
| 550 | (should (equal comp-test-primitive-redefine-args '(1 2)))))) | ||
| 551 | |||
| 535 | 552 | ||
| 536 | ;;;;;;;;;;;;;;;;;;;;; | 553 | ;;;;;;;;;;;;;;;;;;;;; |
| 537 | ;; Tromey's tests. ;; | 554 | ;; Tromey's tests. ;; |
| @@ -887,6 +904,8 @@ Return a list of results." | |||
| 887 | ret-type)))) | 904 | ret-type)))) |
| 888 | 905 | ||
| 889 | (cl-eval-when (compile eval load) | 906 | (cl-eval-when (compile eval load) |
| 907 | (cl-defstruct comp-foo a b) | ||
| 908 | (cl-defstruct (comp-bar (:include comp-foo)) c) | ||
| 890 | (defconst comp-tests-type-spec-tests | 909 | (defconst comp-tests-type-spec-tests |
| 891 | ;; Why we quote everything here, you ask? So that values of | 910 | ;; Why we quote everything here, you ask? So that values of |
| 892 | ;; `most-positive-fixnum' and `most-negative-fixnum', which can be | 911 | ;; `most-positive-fixnum' and `most-negative-fixnum', which can be |
| @@ -1416,7 +1435,39 @@ Return a list of results." | |||
| 1416 | (if (eq x 0) | 1435 | (if (eq x 0) |
| 1417 | (error "") | 1436 | (error "") |
| 1418 | (1+ x))) | 1437 | (1+ x))) |
| 1419 | 'number))) | 1438 | 'number) |
| 1439 | |||
| 1440 | ;; 75 | ||
| 1441 | ((defun comp-tests-ret-type-spec-f () | ||
| 1442 | (make-comp-foo)) | ||
| 1443 | 'comp-foo) | ||
| 1444 | |||
| 1445 | ;; 76 | ||
| 1446 | ((defun comp-tests-ret-type-spec-f () | ||
| 1447 | (make-comp-bar)) | ||
| 1448 | 'comp-bar) | ||
| 1449 | |||
| 1450 | ;; 77 | ||
| 1451 | ((defun comp-tests-ret-type-spec-f (x) | ||
| 1452 | (setf (comp-foo-a x) 2) | ||
| 1453 | x) | ||
| 1454 | 'comp-foo) | ||
| 1455 | |||
| 1456 | ;; 78 | ||
| 1457 | ((defun comp-tests-ret-type-spec-f (x) | ||
| 1458 | (if x | ||
| 1459 | (if (> x 11) | ||
| 1460 | x | ||
| 1461 | (make-comp-foo)) | ||
| 1462 | (make-comp-bar))) | ||
| 1463 | '(or comp-foo float (integer 12 *))) | ||
| 1464 | |||
| 1465 | ;; 79 | ||
| 1466 | ((defun comp-tests-ret-type-spec-f (x) | ||
| 1467 | (if (comp-foo-p x) | ||
| 1468 | x | ||
| 1469 | (error ""))) | ||
| 1470 | 'comp-foo))) | ||
| 1420 | 1471 | ||
| 1421 | (defun comp-tests-define-type-spec-test (number x) | 1472 | (defun comp-tests-define-type-spec-test (number x) |
| 1422 | `(comp-deftest ,(intern (format "ret-type-spec-%d" number)) () | 1473 | `(comp-deftest ,(intern (format "ret-type-spec-%d" number)) () |
diff --git a/test/src/eval-tests.el b/test/src/eval-tests.el index 1e7edca3bac..4589763b2f5 100644 --- a/test/src/eval-tests.el +++ b/test/src/eval-tests.el | |||
| @@ -247,4 +247,39 @@ expressions works for identifiers starting with period." | |||
| 247 | (should (equal (string-trim (buffer-string)) | 247 | (should (equal (string-trim (buffer-string)) |
| 248 | expected-messages)))))))) | 248 | expected-messages)))))))) |
| 249 | 249 | ||
| 250 | (defvar-local eval-test--local-var 'global) | ||
| 251 | |||
| 252 | (ert-deftest eval-test--bug62419 () | ||
| 253 | (with-temp-buffer | ||
| 254 | (setq eval-test--local-var 'first-local) | ||
| 255 | (let ((eval-test--local-var t)) | ||
| 256 | (kill-local-variable 'eval-test--local-var) | ||
| 257 | (setq eval-test--local-var 'second-local) | ||
| 258 | (should (eq eval-test--local-var 'second-local))) | ||
| 259 | ;; FIXME: It's not completely clear if exiting the above `let' | ||
| 260 | ;; should restore the buffer-local binding to `first-local' | ||
| 261 | ;; (i.e. reset the value of the second buffer-local binding to the | ||
| 262 | ;; first's initial value) or should do nothing (on the principle that | ||
| 263 | ;; the first buffer-local binding doesn't exists any more so there's | ||
| 264 | ;; nothing to restore). I think both semantics make sense. | ||
| 265 | ;;(should (eq eval-test--local-var 'first-local)) | ||
| 266 | ) | ||
| 267 | (should (eq eval-test--local-var 'global))) | ||
| 268 | |||
| 269 | (ert-deftest eval-tests-defvaralias () | ||
| 270 | (defvar eval-tests--my-var 'coo) | ||
| 271 | (defvaralias 'eval-tests--my-var1 'eval-tests--my-var) | ||
| 272 | (defvar eval-tests--my-var1) | ||
| 273 | (should (equal eval-tests--my-var 'coo)) | ||
| 274 | (should (equal eval-tests--my-var1 'coo)) | ||
| 275 | |||
| 276 | (defvaralias 'eval-tests--my-a 'eval-tests--my-b) | ||
| 277 | (defvaralias 'eval-tests--my-b 'eval-tests--my-c) | ||
| 278 | |||
| 279 | (should-error (defvaralias 'eval-tests--my-c 'eval-tests--my-c) | ||
| 280 | :type 'cyclic-variable-indirection) | ||
| 281 | (defvaralias 'eval-tests--my-d 'eval-tests--my-a) | ||
| 282 | (should-error (defvaralias 'eval-tests--my-c 'eval-tests--my-d) | ||
| 283 | :type 'cyclic-variable-indirection)) | ||
| 284 | |||
| 250 | ;;; eval-tests.el ends here | 285 | ;;; eval-tests.el ends here |
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 0321b92d0bc..79ae4393f40 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el | |||
| @@ -114,22 +114,24 @@ | |||
| 114 | (should-error (nreverse 1)) | 114 | (should-error (nreverse 1)) |
| 115 | (should-error (nreverse (make-char-table 'foo))) | 115 | (should-error (nreverse (make-char-table 'foo))) |
| 116 | (should (equal (nreverse (copy-sequence "xyzzy")) "yzzyx")) | 116 | (should (equal (nreverse (copy-sequence "xyzzy")) "yzzyx")) |
| 117 | (let ((A (vector))) | 117 | (let* ((A (vector)) |
| 118 | (nreverse A) | 118 | (B (nreverse A))) |
| 119 | (should (equal A []))) | 119 | (should (equal A [])) |
| 120 | (let ((A (vector 0))) | 120 | (should (eq B A))) |
| 121 | (nreverse A) | 121 | (let* ((A (vector 0)) |
| 122 | (should (equal A [0]))) | 122 | (B (nreverse A))) |
| 123 | (let ((A (vector 1 2 3 4))) | 123 | (should (equal A [0])) |
| 124 | (nreverse A) | 124 | (should (eq B A))) |
| 125 | (should (equal A [4 3 2 1]))) | ||
| 126 | (let ((A (vector 1 2 3 4))) | ||
| 127 | (nreverse A) | ||
| 128 | (nreverse A) | ||
| 129 | (should (equal A [1 2 3 4]))) | ||
| 130 | (let* ((A (vector 1 2 3 4)) | 125 | (let* ((A (vector 1 2 3 4)) |
| 131 | (B (nreverse (nreverse A)))) | 126 | (B (nreverse A))) |
| 132 | (should (equal A B)))) | 127 | (should (equal A [4 3 2 1])) |
| 128 | (should (eq B A))) | ||
| 129 | (let* ((A (vector 1 2 3 4)) | ||
| 130 | (B (nreverse A)) | ||
| 131 | (C (nreverse A))) | ||
| 132 | (should (equal A [1 2 3 4])) | ||
| 133 | (should (eq B A)) | ||
| 134 | (should (eq C A)))) | ||
| 133 | 135 | ||
| 134 | (ert-deftest fns-tests-reverse-bool-vector () | 136 | (ert-deftest fns-tests-reverse-bool-vector () |
| 135 | (let ((A (make-bool-vector 10 nil))) | 137 | (let ((A (make-bool-vector 10 nil))) |
| @@ -140,9 +142,10 @@ | |||
| 140 | (ert-deftest fns-tests-nreverse-bool-vector () | 142 | (ert-deftest fns-tests-nreverse-bool-vector () |
| 141 | (let ((A (make-bool-vector 10 nil))) | 143 | (let ((A (make-bool-vector 10 nil))) |
| 142 | (dotimes (i 5) (aset A i t)) | 144 | (dotimes (i 5) (aset A i t)) |
| 143 | (nreverse A) | 145 | (let ((B (nreverse A))) |
| 144 | (should (equal [nil nil nil nil nil t t t t t] (vconcat A))) | 146 | (should (eq B A)) |
| 145 | (should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A)))))) | 147 | (should (equal [nil nil nil nil nil t t t t t] (vconcat A))) |
| 148 | (should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A))))))) | ||
| 146 | 149 | ||
| 147 | (defconst fns-tests--string-lessp-cases | 150 | (defconst fns-tests--string-lessp-cases |
| 148 | `(("abc" < "abd") | 151 | `(("abc" < "abd") |
| @@ -254,7 +257,7 @@ | |||
| 254 | (should (string-collate-equalp "xyzzy" "XYZZY" nil t)) | 257 | (should (string-collate-equalp "xyzzy" "XYZZY" nil t)) |
| 255 | 258 | ||
| 256 | ;; Locale must be valid. | 259 | ;; Locale must be valid. |
| 257 | (should-error (string-collate-equalp "xyzzy" "xyzzy" "en_DE.UTF-8"))) | 260 | (should-error (string-collate-equalp "xyzzy" "xyzzy" "en_XY.UTF-8"))) |
| 258 | 261 | ||
| 259 | ;; There must be a check for valid codepoints. (Check not implemented yet) | 262 | ;; There must be a check for valid codepoints. (Check not implemented yet) |
| 260 | ; (should-error | 263 | ; (should-error |
| @@ -1098,7 +1101,7 @@ | |||
| 1098 | 1101 | ||
| 1099 | (ert-deftest test-vector-delete () | 1102 | (ert-deftest test-vector-delete () |
| 1100 | (let ((v1 (make-vector 1000 1))) | 1103 | (let ((v1 (make-vector 1000 1))) |
| 1101 | (should (equal (delete t [nil t]) [nil])) | 1104 | (should (equal (delete t (vector nil t)) [nil])) |
| 1102 | (should (equal (delete 1 v1) (vector))) | 1105 | (should (equal (delete 1 v1) (vector))) |
| 1103 | (should (equal (delete 2 v1) v1)))) | 1106 | (should (equal (delete 2 v1) v1)))) |
| 1104 | 1107 | ||
diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el index aa710519825..29220c95395 100644 --- a/test/src/keymap-tests.el +++ b/test/src/keymap-tests.el | |||
| @@ -475,6 +475,24 @@ g .. h foo | |||
| 475 | "a" #'next-line | 475 | "a" #'next-line |
| 476 | "a" #'previous-line))) | 476 | "a" #'previous-line))) |
| 477 | 477 | ||
| 478 | (ert-deftest keymap-unset-test-remove-and-inheritance () | ||
| 479 | "Check various behaviors of keymap-unset. (Bug#62207)" | ||
| 480 | (let ((map (make-sparse-keymap)) | ||
| 481 | (parent (make-sparse-keymap))) | ||
| 482 | (set-keymap-parent map parent) | ||
| 483 | ;; Removing an unset key should not add a key. | ||
| 484 | (keymap-set parent "u" #'undo) | ||
| 485 | (keymap-unset map "u" t) | ||
| 486 | (should (equal (keymap-lookup map "u") #'undo)) | ||
| 487 | ;; Non-removed child bindings should shadow parent | ||
| 488 | (keymap-set map "u" #'identity) | ||
| 489 | (keymap-unset map "u") | ||
| 490 | ;; From the child, but nil. | ||
| 491 | (should-not (keymap-lookup map "u")) | ||
| 492 | (keymap-unset map "u" t) | ||
| 493 | ;; From the parent this time/ | ||
| 494 | (should (equal (keymap-lookup map "u") #'undo)))) | ||
| 495 | |||
| 478 | (provide 'keymap-tests) | 496 | (provide 'keymap-tests) |
| 479 | 497 | ||
| 480 | ;;; keymap-tests.el ends here | 498 | ;;; keymap-tests.el ends here |
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index c0ea37d2c55..eae4893ee1b 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el | |||
| @@ -116,8 +116,27 @@ | |||
| 116 | (should-error (read "#") :type 'invalid-read-syntax)) | 116 | (should-error (read "#") :type 'invalid-read-syntax)) |
| 117 | 117 | ||
| 118 | (ert-deftest lread-char-modifiers () | 118 | (ert-deftest lread-char-modifiers () |
| 119 | (should (eq ?\C-\M-é (+ (- ?\M-a ?a) ?\C-é))) | 119 | (should (equal ?\C-\M-é (+ (- ?\M-a ?a) ?\C-é))) |
| 120 | (should (eq (- ?\C-ŗ ?ŗ) (- ?\C-é ?é)))) | 120 | (should (equal (- ?\C-ŗ ?ŗ) (- ?\C-é ?é))) |
| 121 | (should (equal ?\C-\C-c #x4000003)) | ||
| 122 | (should (equal ?\C-\M-\C-c #xc000003)) | ||
| 123 | (should (equal ?\M-\C-\C-c #xc000003)) | ||
| 124 | (should (equal ?\C-\C-\M-c #xc000003)) | ||
| 125 | (should (equal ?\M-\S-\H-\A-\C-\s-x #xbc00018)) | ||
| 126 | |||
| 127 | (should (equal "\s-x" " -x")) | ||
| 128 | (should (equal "\C-x" "\x18")) | ||
| 129 | (should (equal "\^x" "\x18")) | ||
| 130 | (should (equal "\M-x" "\xf8"))) | ||
| 131 | |||
| 132 | (ert-deftest lread-many-modifiers () | ||
| 133 | ;; The string literal "\M-\M-...\M-a" should be equivalent to "\M-a", | ||
| 134 | ;; and we should not run out of stack space parsing it. | ||
| 135 | (let* ((n 500000) | ||
| 136 | (s (concat "\"" | ||
| 137 | (apply #'concat (make-list n "\\M-")) | ||
| 138 | "a\""))) | ||
| 139 | (should (equal (read-from-string s) (cons "\M-a" (+ (* n 3) 3)))))) | ||
| 121 | 140 | ||
| 122 | (ert-deftest lread-record-1 () | 141 | (ert-deftest lread-record-1 () |
| 123 | (should (equal '(#s(foo) #s(foo)) | 142 | (should (equal '(#s(foo) #s(foo)) |
| @@ -341,4 +360,20 @@ literals (Bug#20852)." | |||
| 341 | (should (byte-code-function-p f)) | 360 | (should (byte-code-function-p f)) |
| 342 | (should (equal (aref f 4) "My little\ndoc string\nhere")))))) | 361 | (should (equal (aref f 4) "My little\ndoc string\nhere")))))) |
| 343 | 362 | ||
| 363 | (ert-deftest lread-skip-to-eof () | ||
| 364 | ;; Check the special #@00 syntax that, for compatibility, reads as | ||
| 365 | ;; nil while absorbing the remainder of the input. | ||
| 366 | (with-temp-buffer | ||
| 367 | (insert "#@00 and the rest\n" | ||
| 368 | "should be ignored) entirely\n") | ||
| 369 | (goto-char (point-min)) | ||
| 370 | (should (equal (read (current-buffer)) nil)) | ||
| 371 | (should (eobp)) | ||
| 372 | ;; Add an unbalanced bracket to the beginning and try again; | ||
| 373 | ;; we should get an error. | ||
| 374 | (goto-char (point-min)) | ||
| 375 | (insert "( ") | ||
| 376 | (goto-char (point-min)) | ||
| 377 | (should-error (read (current-buffer)) :type 'end-of-file))) | ||
| 378 | |||
| 344 | ;;; lread-tests.el ends here | 379 | ;;; lread-tests.el ends here |
diff --git a/test/src/sqlite-tests.el b/test/src/sqlite-tests.el index 460651def78..f7144c15887 100644 --- a/test/src/sqlite-tests.el +++ b/test/src/sqlite-tests.el | |||
| @@ -197,10 +197,13 @@ | |||
| 197 | (sqlite-load-extension db "/usr/lib/sqlite3/")) | 197 | (sqlite-load-extension db "/usr/lib/sqlite3/")) |
| 198 | (should-error | 198 | (should-error |
| 199 | (sqlite-load-extension db "/usr/lib/sqlite3")) | 199 | (sqlite-load-extension db "/usr/lib/sqlite3")) |
| 200 | (should | 200 | (if (eq system-type 'windows-nt) |
| 201 | (memq | 201 | (should |
| 202 | (sqlite-load-extension db "/usr/lib/sqlite3/pcre.so") | 202 | (eq (sqlite-load-extension db "/usr/lib/sqlite3/pcre.dll") |
| 203 | '(nil t))) | 203 | (file-readable-p "/usr/lib/sqlite3/pcre.dll"))) |
| 204 | (should | ||
| 205 | (eq (sqlite-load-extension db "/usr/lib/sqlite3/pcre.so") | ||
| 206 | (file-readable-p "/usr/lib/sqlite3/pcre.so")))) | ||
| 204 | 207 | ||
| 205 | (should-error | 208 | (should-error |
| 206 | (sqlite-load-extension | 209 | (sqlite-load-extension |
| @@ -211,11 +214,13 @@ | |||
| 211 | (should-error | 214 | (should-error |
| 212 | (sqlite-load-extension | 215 | (sqlite-load-extension |
| 213 | db "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable")) | 216 | db "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable")) |
| 214 | (should | 217 | (if (eq system-type 'windows-nt) |
| 215 | (memq | 218 | (should |
| 216 | (sqlite-load-extension | 219 | (eq (sqlite-load-extension db "/usr/lib/sqlite3/csvtable.dll") |
| 217 | db "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable.so") | 220 | (file-readable-p "/usr/lib/sqlite3/csvtable.dll"))) |
| 218 | '(nil t))))) | 221 | (should |
| 222 | (eq (sqlite-load-extension db "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable.so") | ||
| 223 | (file-readable-p "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable.so")))))) | ||
| 219 | 224 | ||
| 220 | (ert-deftest sqlite-blob () | 225 | (ert-deftest sqlite-blob () |
| 221 | (skip-unless (sqlite-available-p)) | 226 | (skip-unless (sqlite-available-p)) |
diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el index 468cd221ef9..7a8e53924eb 100644 --- a/test/src/treesit-tests.el +++ b/test/src/treesit-tests.el | |||
| @@ -54,6 +54,9 @@ | |||
| 54 | (declare-function treesit-node-descendant-for-range "treesit.c") | 54 | (declare-function treesit-node-descendant-for-range "treesit.c") |
| 55 | (declare-function treesit-node-eq "treesit.c") | 55 | (declare-function treesit-node-eq "treesit.c") |
| 56 | 56 | ||
| 57 | (declare-function treesit-search-forward "treesit.c") | ||
| 58 | (declare-function treesit-search-subtree "treesit.c") | ||
| 59 | |||
| 57 | ;;; Basic API | 60 | ;;; Basic API |
| 58 | 61 | ||
| 59 | (ert-deftest treesit-basic-parsing () | 62 | (ert-deftest treesit-basic-parsing () |
| @@ -66,7 +69,7 @@ | |||
| 66 | (should | 69 | (should |
| 67 | (equal (treesit-node-string | 70 | (equal (treesit-node-string |
| 68 | (treesit-parser-root-node parser)) | 71 | (treesit-parser-root-node parser)) |
| 69 | "(ERROR)")) | 72 | "(document)")) |
| 70 | 73 | ||
| 71 | (insert "[1,2,3]") | 74 | (insert "[1,2,3]") |
| 72 | (should | 75 | (should |
| @@ -257,6 +260,7 @@ | |||
| 257 | (defmacro treesit--ert-search-setup (&rest body) | 260 | (defmacro treesit--ert-search-setup (&rest body) |
| 258 | "Setup macro used by `treesit-search-forward' and friends. | 261 | "Setup macro used by `treesit-search-forward' and friends. |
| 259 | BODY is the test body." | 262 | BODY is the test body." |
| 263 | (declare (debug (&rest form))) | ||
| 260 | `(with-temp-buffer | 264 | `(with-temp-buffer |
| 261 | (let (parser root array) | 265 | (let (parser root array) |
| 262 | (progn | 266 | (progn |
| @@ -332,6 +336,59 @@ BODY is the test body." | |||
| 332 | do (should (equal (treesit-node-text cursor) | 336 | do (should (equal (treesit-node-text cursor) |
| 333 | text))))) | 337 | text))))) |
| 334 | 338 | ||
| 339 | (ert-deftest treesit-search-forward-predicate () | ||
| 340 | "Test various form of supported predicates in search functions." | ||
| 341 | (skip-unless (treesit-language-available-p 'json)) | ||
| 342 | (treesit--ert-search-setup | ||
| 343 | ;; The following tests are adapted from `treesit-search-forward'. | ||
| 344 | |||
| 345 | ;; Test `or' | ||
| 346 | (cl-loop for cursor = (treesit-node-child array 0) | ||
| 347 | then (treesit-search-forward cursor `(or "number" ,(rx "[")) | ||
| 348 | nil t) | ||
| 349 | for text in '("[" "[" "1" "2" "3" | ||
| 350 | "[" "4" "5" "6" | ||
| 351 | "[" "7" "8" "9") | ||
| 352 | while cursor | ||
| 353 | do (should (equal (treesit-node-text cursor) text))) | ||
| 354 | ;; Test `not' and `or' | ||
| 355 | (cl-loop for cursor = (treesit-node-child array 0) | ||
| 356 | then (treesit-search-forward cursor | ||
| 357 | `(not (or "number" ,(rx "["))) | ||
| 358 | nil t) | ||
| 359 | for text in '("[" "," "," "]" | ||
| 360 | "[1,2,3]" "," | ||
| 361 | "," "," "]" | ||
| 362 | "[4,5,6]" "," | ||
| 363 | "," "," "]" | ||
| 364 | "[7,8,9]" "]" | ||
| 365 | "[[1,2,3], [4,5,6], [7,8,9]]") | ||
| 366 | while cursor | ||
| 367 | do (should (equal (treesit-node-text cursor) text))) | ||
| 368 | ;; Test (regexp . function) | ||
| 369 | (let ((is-odd (lambda (node) | ||
| 370 | (let ((string (treesit-node-text node))) | ||
| 371 | (and (eq 1 (length string)) | ||
| 372 | (cl-oddp (string-to-number string))))))) | ||
| 373 | (cl-loop for cursor = (treesit-node-child array 0) | ||
| 374 | then (treesit-search-forward cursor `("number" . ,is-odd) | ||
| 375 | nil t) | ||
| 376 | for text in '("[" "1" "3" "5" "7" "9") | ||
| 377 | while cursor | ||
| 378 | do (should (equal (treesit-node-text cursor) text)))))) | ||
| 379 | |||
| 380 | (ert-deftest treesit-search-forward-predicate-invalid-predicate () | ||
| 381 | "Test tree-sitter's ability to detect invalid predicates." | ||
| 382 | (skip-unless (treesit-language-available-p 'json)) | ||
| 383 | (treesit--ert-search-setup | ||
| 384 | (dolist (pred '( 1 (not 1) (not "2" "3") (or) (or 1) 'a)) | ||
| 385 | (should-error (treesit-search-forward (treesit-node-child array 0) | ||
| 386 | pred) | ||
| 387 | :type 'treesit-invalid-predicate)) | ||
| 388 | (should-error (treesit-search-forward (treesit-node-child array 0) | ||
| 389 | (lambda (node) (car node))) | ||
| 390 | :type 'wrong-type-argument))) | ||
| 391 | |||
| 335 | (ert-deftest treesit-cursor-helper-with-missing-node () | 392 | (ert-deftest treesit-cursor-helper-with-missing-node () |
| 336 | "Test treesit_cursor_helper with a missing node." | 393 | "Test treesit_cursor_helper with a missing node." |
| 337 | (skip-unless (treesit-language-available-p 'json)) | 394 | (skip-unless (treesit-language-available-p 'json)) |
| @@ -831,7 +888,7 @@ the return value is ((1 3) (1 3))." | |||
| 831 | (funcall fn))))) | 888 | (funcall fn))))) |
| 832 | 889 | ||
| 833 | (defun treesit--ert-test-defun-navigation | 890 | (defun treesit--ert-test-defun-navigation |
| 834 | (init program master &optional opening closing) | 891 | (init program master tactic &optional opening closing) |
| 835 | "Run defun navigation tests on PROGRAM and MASTER. | 892 | "Run defun navigation tests on PROGRAM and MASTER. |
| 836 | 893 | ||
| 837 | INIT is a setup function that runs right after this function | 894 | INIT is a setup function that runs right after this function |
| @@ -843,6 +900,8 @@ starting marker position, and the rest are marker positions the | |||
| 843 | corresponding navigation should stop at (after running | 900 | corresponding navigation should stop at (after running |
| 844 | `treesit-defun-skipper'). | 901 | `treesit-defun-skipper'). |
| 845 | 902 | ||
| 903 | TACTIC is the same as in `treesit--navigate-thing'. | ||
| 904 | |||
| 846 | OPENING and CLOSING are the same as in | 905 | OPENING and CLOSING are the same as in |
| 847 | `treesit--ert-insert-and-parse-marker', by default they are \"[\" | 906 | `treesit--ert-insert-and-parse-marker', by default they are \"[\" |
| 848 | and \"]\"." | 907 | and \"]\"." |
| @@ -860,8 +919,6 @@ and \"]\"." | |||
| 860 | collect | 919 | collect |
| 861 | (cl-loop for pos in record | 920 | (cl-loop for pos in record |
| 862 | collect (alist-get pos marker-alist)))) | 921 | collect (alist-get pos marker-alist)))) |
| 863 | (`(,regexp . ,pred) (treesit--thing-unpack-pattern | ||
| 864 | treesit-defun-type-regexp)) | ||
| 865 | ;; Collect positions each function returns. | 922 | ;; Collect positions each function returns. |
| 866 | (positions | 923 | (positions |
| 867 | (treesit--ert-collect-positions | 924 | (treesit--ert-collect-positions |
| @@ -873,7 +930,7 @@ and \"]\"." | |||
| 873 | (if-let ((pos (funcall | 930 | (if-let ((pos (funcall |
| 874 | #'treesit--navigate-thing | 931 | #'treesit--navigate-thing |
| 875 | (point) (car conf) (cdr conf) | 932 | (point) (car conf) (cdr conf) |
| 876 | regexp pred))) | 933 | treesit-defun-type-regexp tactic))) |
| 877 | (save-excursion | 934 | (save-excursion |
| 878 | (goto-char pos) | 935 | (goto-char pos) |
| 879 | (funcall treesit-defun-skipper) | 936 | (funcall treesit-defun-skipper) |
| @@ -1025,43 +1082,42 @@ the prev-beg, now point should be at marker 103\", etc.") | |||
| 1025 | "Test defun navigation." | 1082 | "Test defun navigation." |
| 1026 | (skip-unless (treesit-language-available-p 'python)) | 1083 | (skip-unless (treesit-language-available-p 'python)) |
| 1027 | ;; Nested defun navigation | 1084 | ;; Nested defun navigation |
| 1028 | (let ((treesit-defun-tactic 'nested)) | 1085 | (require 'python) |
| 1029 | (require 'python) | 1086 | (treesit--ert-test-defun-navigation |
| 1030 | (treesit--ert-test-defun-navigation | 1087 | 'python-ts-mode |
| 1031 | 'python-ts-mode | 1088 | treesit--ert-defun-navigation-python-program |
| 1032 | treesit--ert-defun-navigation-python-program | 1089 | treesit--ert-defun-navigation-nested-master |
| 1033 | treesit--ert-defun-navigation-nested-master))) | 1090 | 'nested)) |
| 1034 | 1091 | ||
| 1035 | (ert-deftest treesit-defun-navigation-nested-2 () | 1092 | (ert-deftest treesit-defun-navigation-nested-2 () |
| 1036 | "Test defun navigation using `js-ts-mode'." | 1093 | "Test defun navigation using `js-ts-mode'." |
| 1037 | (skip-unless (treesit-language-available-p 'javascript)) | 1094 | (skip-unless (treesit-language-available-p 'javascript)) |
| 1038 | ;; Nested defun navigation | 1095 | ;; Nested defun navigation |
| 1039 | (let ((treesit-defun-tactic 'nested)) | 1096 | (require 'js) |
| 1040 | (require 'js) | 1097 | (treesit--ert-test-defun-navigation |
| 1041 | (treesit--ert-test-defun-navigation | 1098 | 'js-ts-mode |
| 1042 | 'js-ts-mode | 1099 | treesit--ert-defun-navigation-js-program |
| 1043 | treesit--ert-defun-navigation-js-program | 1100 | treesit--ert-defun-navigation-nested-master |
| 1044 | treesit--ert-defun-navigation-nested-master))) | 1101 | 'nested)) |
| 1045 | 1102 | ||
| 1046 | (ert-deftest treesit-defun-navigation-nested-3 () | 1103 | (ert-deftest treesit-defun-navigation-nested-3 () |
| 1047 | "Test defun navigation using `bash-ts-mode'." | 1104 | "Test defun navigation using `bash-ts-mode'." |
| 1048 | (skip-unless (treesit-language-available-p 'bash)) | 1105 | (skip-unless (treesit-language-available-p 'bash)) |
| 1049 | ;; Nested defun navigation | 1106 | ;; Nested defun navigation |
| 1050 | (let ((treesit-defun-tactic 'nested)) | 1107 | (treesit--ert-test-defun-navigation |
| 1051 | (treesit--ert-test-defun-navigation | 1108 | (lambda () |
| 1052 | (lambda () | 1109 | (treesit-parser-create 'bash) |
| 1053 | (treesit-parser-create 'bash) | 1110 | (setq-local treesit-defun-type-regexp "function_definition")) |
| 1054 | (setq-local treesit-defun-type-regexp "function_definition")) | 1111 | treesit--ert-defun-navigation-bash-program |
| 1055 | treesit--ert-defun-navigation-bash-program | 1112 | treesit--ert-defun-navigation-nested-master |
| 1056 | treesit--ert-defun-navigation-nested-master))) | 1113 | 'nested)) |
| 1057 | 1114 | ||
| 1058 | (ert-deftest treesit-defun-navigation-nested-4 () | 1115 | (ert-deftest treesit-defun-navigation-nested-4 () |
| 1059 | "Test defun navigation using Elixir. | 1116 | "Test defun navigation using Elixir. |
| 1060 | This tests bug#60355." | 1117 | This tests bug#60355." |
| 1061 | (skip-unless (treesit-language-available-p 'elixir)) | 1118 | (skip-unless (treesit-language-available-p 'elixir)) |
| 1062 | ;; Nested defun navigation | 1119 | ;; Nested defun navigation |
| 1063 | (let ((treesit-defun-tactic 'nested) | 1120 | (let ((pred (lambda (node) |
| 1064 | (pred (lambda (node) | ||
| 1065 | (member (treesit-node-text | 1121 | (member (treesit-node-text |
| 1066 | (treesit-node-child-by-field-name node "target")) | 1122 | (treesit-node-child-by-field-name node "target")) |
| 1067 | '("def" "defmodule"))))) | 1123 | '("def" "defmodule"))))) |
| @@ -1070,18 +1126,19 @@ This tests bug#60355." | |||
| 1070 | (treesit-parser-create 'elixir) | 1126 | (treesit-parser-create 'elixir) |
| 1071 | (setq-local treesit-defun-type-regexp `("call" . ,pred))) | 1127 | (setq-local treesit-defun-type-regexp `("call" . ,pred))) |
| 1072 | treesit--ert-defun-navigation-elixir-program | 1128 | treesit--ert-defun-navigation-elixir-program |
| 1073 | treesit--ert-defun-navigation-nested-master))) | 1129 | treesit--ert-defun-navigation-nested-master |
| 1130 | 'nested))) | ||
| 1074 | 1131 | ||
| 1075 | (ert-deftest treesit-defun-navigation-top-level () | 1132 | (ert-deftest treesit-defun-navigation-top-level () |
| 1076 | "Test top-level only defun navigation." | 1133 | "Test top-level only defun navigation." |
| 1077 | (skip-unless (treesit-language-available-p 'python)) | 1134 | (skip-unless (treesit-language-available-p 'python)) |
| 1078 | ;; Nested defun navigation | 1135 | ;; Nested defun navigation |
| 1079 | (let ((treesit-defun-tactic 'top-level)) | 1136 | (require 'python) |
| 1080 | (require 'python) | 1137 | (treesit--ert-test-defun-navigation |
| 1081 | (treesit--ert-test-defun-navigation | 1138 | 'python-ts-mode |
| 1082 | 'python-ts-mode | 1139 | treesit--ert-defun-navigation-python-program |
| 1083 | treesit--ert-defun-navigation-python-program | 1140 | treesit--ert-defun-navigation-top-level-master |
| 1084 | treesit--ert-defun-navigation-top-level-master))) | 1141 | 'top-level)) |
| 1085 | 1142 | ||
| 1086 | ;; TODO | 1143 | ;; TODO |
| 1087 | ;; - Functions in treesit.el | 1144 | ;; - Functions in treesit.el |
diff --git a/test/src/xdisp-tests.el b/test/src/xdisp-tests.el index 52ed79b0f20..dfd38a9d4c1 100644 --- a/test/src/xdisp-tests.el +++ b/test/src/xdisp-tests.el | |||
| @@ -40,7 +40,7 @@ | |||
| 40 | (insert "hello") | 40 | (insert "hello") |
| 41 | (let ((ol (make-overlay (point) (point))) | 41 | (let ((ol (make-overlay (point) (point))) |
| 42 | (max-mini-window-height 1) | 42 | (max-mini-window-height 1) |
| 43 | (text "askdjfhaklsjdfhlkasjdfhklasdhflkasdhflkajsdhflkashdfkljahsdlfkjahsdlfkjhasldkfhalskdjfhalskdfhlaksdhfklasdhflkasdhflkasdhflkajsdhklajsdgh")) | 43 | (text (copy-sequence "askdjfhaklsjdfhlkasjdfhklasdhflkasdhflkajsdhflkashdfkljahsdlfkjahsdlfkjhasldkfhalskdjfhalskdfhlaksdhfklasdhflkasdhflkasdhflkajsdhklajsdgh"))) |
| 44 | ;; (save-excursion (insert text)) | 44 | ;; (save-excursion (insert text)) |
| 45 | ;; (sit-for 2) | 45 | ;; (sit-for 2) |
| 46 | ;; (delete-region (point) (point-max)) | 46 | ;; (delete-region (point) (point-max)) |