]> git.eshelyaron.com Git - emacs.git/commitdiff
Add tests for concat, vconcat and append
authorMattias Engdegård <mattiase@acm.org>
Wed, 26 Jan 2022 15:47:31 +0000 (16:47 +0100)
committerMattias Engdegård <mattiase@acm.org>
Wed, 26 Jan 2022 16:10:16 +0000 (17:10 +0100)
* test/src/fns-tests.el (fns-tests-concat)
(fns-concat, fns-vconcat, fns-append): New.

test/src/fns-tests.el

index f74e925d3b6e39d33c6b8f60233c15ffe38ebd41..723ef4c710f7b074c434266db2d35b84b9c3ab48 100644 (file)
     (should-error (line-number-at-pos -1))
     (should-error (line-number-at-pos 100))))
 
+(defun fns-tests-concat (&rest args)
+  ;; Dodge the byte-compiler's partial evaluation of `concat' with
+  ;; constant arguments.
+  (apply #'concat args))
+
+(ert-deftest fns-concat ()
+  (should (equal (fns-tests-concat) ""))
+  (should (equal (fns-tests-concat "") ""))
+  (should (equal (fns-tests-concat nil) ""))
+  (should (equal (fns-tests-concat []) ""))
+  (should (equal (fns-tests-concat [97 98]) "ab"))
+  (should (equal (fns-tests-concat '(97 98)) "ab"))
+  (should (equal (fns-tests-concat "ab" '(99 100) nil [101 102] "gh")
+                 "abcdefgh"))
+  (should (equal (fns-tests-concat "Ab" "\200" "cd") "Ab\200cd"))
+  (should (equal (fns-tests-concat "aB" "\200" "çd") "aB\200çd"))
+  (should (equal (fns-tests-concat "AB" (string-to-multibyte "\200") "cd")
+                 (string-to-multibyte "AB\200cd")))
+  (should (equal (fns-tests-concat "ab" '(#xe5) [255] "cd") "abåÿcd"))
+  (should (equal (fns-tests-concat '(#x3fffff) [#x3fff80] "xy") "\377\200xy"))
+  (should (equal (fns-tests-concat '(#x3fffff) [#x3fff80] "xy§") "\377\200xy§"))
+  (should (equal-including-properties
+           (fns-tests-concat #("abc" 0 3 (a 1)) #("de" 0 2 (a 1)))
+           #("abcde" 0 5 (a 1))))
+  (should (equal-including-properties
+           (fns-tests-concat #("abc" 0 3 (a 1)) "§ü" #("çå" 0 2 (b 2)))
+           #("abc§üçå" 0 3 (a 1) 5 7 (b 2))))
+  (should-error (fns-tests-concat "a" '(98 . 99))
+                :type 'wrong-type-argument)
+  (let ((loop (list 66 67)))
+    (setcdr (cdr loop) loop)
+    (should-error (fns-tests-concat "A" loop)
+                  :type 'circular-list)))
+
+(ert-deftest fns-vconcat ()
+  (should (equal (vconcat) []))
+  (should (equal (vconcat nil) []))
+  (should (equal (vconcat "") []))
+  (should (equal (vconcat [1 2 3]) [1 2 3]))
+  (should (equal (vconcat '(1 2 3)) [1 2 3]))
+  (should (equal (vconcat "ABC") [65 66 67]))
+  (should (equal (vconcat "ü§") [252 167]))
+  (should (equal (vconcat [1 2 3] nil '(4 5) "AB" "å"
+                          "\377" (string-to-multibyte "\377")
+                          (bool-vector t nil nil t nil))
+                 [1 2 3 4 5 65 66 #xe5 255 #x3fffff t nil nil t nil]))
+  (should-error (vconcat [1] '(2 . 3))
+                :type 'wrong-type-argument)
+  (let ((loop (list 1 2)))
+    (setcdr (cdr loop) loop)
+    (should-error (vconcat [1] loop)
+                  :type 'circular-list)))
+
+(ert-deftest fns-append ()
+  (should (equal (append) nil))
+  (should (equal (append 'tail) 'tail))
+  (should (equal (append [1 2 3] nil '(4 5) "AB" "å"
+                         "\377" (string-to-multibyte "\377")
+                          (bool-vector t nil nil t nil)
+                         '(9 10))
+                 '(1 2 3 4 5 65 66 #xe5 255 #x3fffff t nil nil t nil 9 10)))
+  (should (equal (append '(1 2) '(3 4) 'tail)
+                 '(1 2 3 4 . tail)))
+  (should-error (append '(1 . 2) '(3))
+                :type 'wrong-type-argument)
+  (let ((loop (list 1 2)))
+    (setcdr (cdr loop) loop)
+    (should-error (append loop '(end))
+                  :type 'circular-list)))
+
 ;;; fns-tests.el ends here