r6rs-records-inspection.test 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ;;; r6rs-control.test --- Test suite for R6RS (rnrs control)
  2. ;; Copyright (C) 2010 Free Software Foundation, Inc.
  3. ;;
  4. ;; This library is free software; you can redistribute it and/or
  5. ;; modify it under the terms of the GNU Lesser General Public
  6. ;; License as published by the Free Software Foundation; either
  7. ;; version 3 of the License, or (at your option) any later version.
  8. ;;
  9. ;; This library 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 GNU
  12. ;; Lesser General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU Lesser General Public
  15. ;; License along with this library; if not, write to the Free Software
  16. ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. (define-module (test-suite test-rnrs-records-procedural)
  18. :use-module ((rnrs conditions) :version (6))
  19. :use-module ((rnrs exceptions) :version (6))
  20. :use-module ((rnrs records inspection) :version (6))
  21. :use-module ((rnrs records procedural) :version (6))
  22. :use-module (test-suite lib))
  23. (with-test-prefix "record?"
  24. (pass-if "record? recognizes non-opaque records"
  25. (let* ((rec (make-record-type-descriptor 'rec #f #f #f #f '#()))
  26. (make-rec (record-constructor
  27. (make-record-constructor-descriptor rec #f #f))))
  28. (record? (make-rec))))
  29. (pass-if "record? doesn't recognize opaque records"
  30. (let* ((rec (make-record-type-descriptor 'rec #f #f #f #t '#()))
  31. (make-rec (record-constructor
  32. (make-record-constructor-descriptor rec #f #f))))
  33. (not (record? (make-rec)))))
  34. (pass-if "record? doesn't recognize non-records" (not (record? 'foo))))
  35. (with-test-prefix "record-rtd"
  36. (pass-if "simple"
  37. (let* ((rtd (make-record-type-descriptor 'rec #f #f #f #f '#()))
  38. (make-rec (record-constructor
  39. (make-record-constructor-descriptor rtd #f #f))))
  40. (eq? (record-rtd (make-rec)) rtd)))
  41. (pass-if "&assertion on opaque record"
  42. (let* ((rtd (make-record-type-descriptor 'rec #f #f #f #t '#()))
  43. (make-rec (record-constructor
  44. (make-record-constructor-descriptor rtd #f #f)))
  45. (success #f))
  46. (call/cc
  47. (lambda (continuation)
  48. (with-exception-handler
  49. (lambda (condition)
  50. (set! success (assertion-violation? condition))
  51. (continuation))
  52. (lambda () (record-rtd (make-rec))))))
  53. success)))
  54. (with-test-prefix "record-type-name"
  55. (pass-if "simple"
  56. (let* ((rtd (make-record-type-descriptor 'foo #f #f #f #f '#())))
  57. (eq? (record-type-name rtd) 'foo))))
  58. (with-test-prefix "record-type-parent"
  59. (pass-if "eq? to parent"
  60. (let* ((rtd-parent (make-record-type-descriptor 'foo #f #f #f #f '#()))
  61. (rtd (make-record-type-descriptor 'bar rtd-parent #f #f #f '#())))
  62. (eq? (record-type-parent rtd) rtd-parent)))
  63. (pass-if "#f when parent not present"
  64. (let* ((rtd (make-record-type-descriptor 'foo #f #f #f #f '#())))
  65. (not (record-type-parent rtd)))))
  66. (with-test-prefix "record-type-uid"
  67. (pass-if "eq? to uid"
  68. (let* ((uid (gensym))
  69. (rtd (make-record-type-descriptor uid #f uid #f #f '#())))
  70. (eq? (record-type-uid rtd) uid)))
  71. (pass-if "#f when uid not present"
  72. (let* ((rtd (make-record-type-descriptor 'foo #f #f #f #f '#())))
  73. (not (record-type-uid rtd)))))
  74. (with-test-prefix "record-type-generative?"
  75. (pass-if "#f when uid is not #f"
  76. (let* ((uid (gensym))
  77. (rtd (make-record-type-descriptor uid #f uid #f #f '#())))
  78. (not (record-type-generative? rtd))))
  79. (pass-if "#t when uid is #f"
  80. (let* ((rtd (make-record-type-descriptor 'foo #f #f #f #f '#())))
  81. (record-type-generative? rtd))))
  82. (with-test-prefix "record-type-sealed?"
  83. (pass-if "#t when sealed? is #t"
  84. (let* ((rtd (make-record-type-descriptor 'foo #f #f #t #f '#())))
  85. (record-type-sealed? rtd)))
  86. (pass-if "#f when sealed? is #f"
  87. (let* ((rtd (make-record-type-descriptor 'foo #f #f #f #f '#())))
  88. (not (record-type-sealed? rtd)))))
  89. (with-test-prefix "record-type-opaque?"
  90. (pass-if "#t when opaque? is #t"
  91. (let* ((rtd (make-record-type-descriptor 'foo #f #f #f #t '#())))
  92. (record-type-opaque? rtd)))
  93. (pass-if "#f when opaque? is #f"
  94. (let* ((rtd (make-record-type-descriptor 'foo #f #f #f #f '#())))
  95. (not (record-type-opaque? rtd))))
  96. (pass-if "#t when parent is opaque"
  97. (let* ((parent-rtd (make-record-type-descriptor 'foo #f #f #f #t '#()))
  98. (rtd (make-record-type-descriptor 'bar parent-rtd #f #f #f '#())))
  99. (record-type-opaque? rtd))))
  100. (with-test-prefix "record-type-field-names"
  101. (pass-if "simple"
  102. (let* ((rtd (make-record-type-descriptor 'foobar #f #f #f #f
  103. '#((immutable foo)
  104. (mutable bar)))))
  105. (equal? (record-type-field-names rtd) '#(foo bar))))
  106. (pass-if "parent fields not included"
  107. (let* ((parent-rtd (make-record-type-descriptor 'foo #f #f #f #f
  108. '#((mutable foo))))
  109. (rtd (make-record-type-descriptor 'bar parent-rtd #f #f #f
  110. '#((immutable bar)))))
  111. (equal? (record-type-field-names rtd) '#(bar))))
  112. (pass-if "subtype fields not included"
  113. (let* ((parent-rtd (make-record-type-descriptor 'foo #f #f #f #f
  114. '#((mutable foo))))
  115. (rtd (make-record-type-descriptor 'bar parent-rtd #f #f #f
  116. '#((immutable bar)))))
  117. (equal? (record-type-field-names parent-rtd) '#(foo)))))
  118. (with-test-prefix "record-field-mutable?"
  119. (pass-if "simple"
  120. (let* ((rtd (make-record-type-descriptor 'foobar #f #f #f #f
  121. '#((mutable foo)
  122. (immutable bar)))))
  123. (and (record-field-mutable? rtd 0)
  124. (not (record-field-mutable? rtd 1))))))