test-weak-vectors.scm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ;;; Copyright (C) 2024 Vivianne Langdon
  2. ;;;
  3. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  4. ;;; you may not use this file except in compliance with the License.
  5. ;;; You may obtain a copy of the License at
  6. ;;;
  7. ;;; http://www.apache.org/licenses/LICENSE-2.0
  8. ;;;
  9. ;;; Unless required by applicable law or agreed to in writing, software
  10. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  11. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ;;; See the License for the specific language governing permissions and
  13. ;;; limitations under the License.
  14. ;;; Commentary:
  15. ;;;
  16. ;;; Weak vector tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (test utils))
  21. (test-begin "test-weak-vectors")
  22. (with-additional-imports
  23. ((hoot weak-vectors))
  24. (test-call "4" (lambda () (weak-vector-length (make-weak-vector 4))))
  25. (test-call "bar" (lambda () (weak-vector-ref (weak-vector 'foo 'bar 'baz) 1)))
  26. (test-call "#<unspecified>" (lambda () (weak-vector-ref (make-weak-vector 2) 0)))
  27. (test-call "42" (lambda () (weak-vector-ref (make-weak-vector 3 42) 2)))
  28. (test-call "baz"
  29. (lambda ()
  30. (let ((wv (make-weak-vector 3 'foo)))
  31. (weak-vector-set! wv 1 'baz)
  32. (weak-vector-ref wv 1))))
  33. (test-call "42"
  34. (lambda ()
  35. (let ((wv (list->weak-vector '(24 42 56))))
  36. (weak-vector-ref wv 1)))))
  37. (test-end* "test-weak-vectors")