obarray-tests.el 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ;;; obarray-tests.el --- Tests for obarray -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
  3. ;; Author: Przemysław Wojnowski <esperanto@cumego.com>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;; Code:
  17. (require 'obarray)
  18. (require 'ert)
  19. (ert-deftest obarrayp-test ()
  20. "Should assert that given object is an obarray."
  21. (should-not (obarrayp 42))
  22. (should-not (obarrayp "aoeu"))
  23. (should-not (obarrayp '()))
  24. (should-not (obarrayp []))
  25. (should (obarrayp (make-vector 7 0))))
  26. (ert-deftest obarrayp-unchecked-content-test ()
  27. "Should fail to check content of passed obarray."
  28. :expected-result :failed
  29. (should-not (obarrayp ["a" "b" "c"]))
  30. (should-not (obarrayp [1 2 3])))
  31. (ert-deftest obarray-make-default-test ()
  32. (let ((table (obarray-make)))
  33. (should (obarrayp table))
  34. (should (equal (make-vector 59 0) table))))
  35. (ert-deftest obarray-make-with-size-test ()
  36. (should-error (obarray-make -1) :type 'wrong-type-argument)
  37. (should-error (obarray-make 0) :type 'wrong-type-argument)
  38. (let ((table (obarray-make 1)))
  39. (should (obarrayp table))
  40. (should (equal (make-vector 1 0) table))))
  41. (ert-deftest obarray-get-test ()
  42. (let ((table (obarray-make 3)))
  43. (should-not (obarray-get table "aoeu"))
  44. (intern "aoeu" table)
  45. (should (string= "aoeu" (obarray-get table "aoeu")))))
  46. (ert-deftest obarray-put-test ()
  47. (let ((table (obarray-make 3)))
  48. (should-not (obarray-get table "aoeu"))
  49. (should (string= "aoeu" (obarray-put table "aoeu")))
  50. (should (string= "aoeu" (obarray-get table "aoeu")))))
  51. (ert-deftest obarray-remove-test ()
  52. (let ((table (obarray-make 3)))
  53. (should-not (obarray-get table "aoeu"))
  54. (should-not (obarray-remove table "aoeu"))
  55. (should (string= "aoeu" (obarray-put table "aoeu")))
  56. (should (string= "aoeu" (obarray-get table "aoeu")))
  57. (should (obarray-remove table "aoeu"))
  58. (should-not (obarray-get table "aoeu"))))
  59. (ert-deftest obarray-map-test ()
  60. "Should execute function on all elements of obarray."
  61. (let* ((table (obarray-make 3))
  62. (syms '())
  63. (collect-names (lambda (sym) (push (symbol-name sym) syms))))
  64. (obarray-map collect-names table)
  65. (should (null syms))
  66. (obarray-put table "a")
  67. (obarray-put table "b")
  68. (obarray-put table "c")
  69. (obarray-map collect-names table)
  70. (should (equal (sort syms #'string<) '("a" "b" "c")))))
  71. (provide 'obarray-tests)
  72. ;;; obarray-tests.el ends here