record-procedural-check.scm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Mike Sperber
  3. (define-test-suite r6rs-records-procedural-tests)
  4. (define :point
  5. (make-record-type-descriptor
  6. 'point #f
  7. #f #f #f
  8. '#((mutable x) (mutable y))))
  9. (define :point-cd
  10. (make-record-constructor-descriptor :point #f #f))
  11. (define make-point (record-constructor :point-cd))
  12. (define point? (record-predicate :point))
  13. (define point-x (record-accessor :point 0))
  14. (define point-y (record-accessor :point 1))
  15. (define point-x-set! (record-mutator :point 0))
  16. (define point-y-set! (record-mutator :point 1))
  17. (define-test-case point r6rs-records-procedural-tests
  18. (let ((p1 (make-point 1 2)))
  19. (check (point? p1))
  20. (check (point-x p1) => 1)
  21. (check (point-y p1) => 2)
  22. (point-x-set! p1 5)
  23. (check (point-x p1) => 5)))
  24. (define :point2
  25. (make-record-type-descriptor
  26. 'point2 :point
  27. #f #f #f '#((mutable x) (mutable y))))
  28. (define make-point2
  29. (record-constructor
  30. (make-record-constructor-descriptor :point2
  31. #f #f)))
  32. (define point2? (record-predicate :point2))
  33. (define point2-xx (record-accessor :point2 0))
  34. (define point2-yy (record-accessor :point2 1))
  35. (define-test-case point2 r6rs-records-procedural-tests
  36. (let ((p2 (make-point2 1 2 3 4)))
  37. (check (point? p2) => #t)
  38. (check (point-x p2) => 1)
  39. (check (point-y p2) => 2)
  40. (check (point2-xx p2) => 3)
  41. (check (point2-yy p2) => 4)))
  42. (define :point-cd/abs
  43. (make-record-constructor-descriptor
  44. :point #f
  45. (lambda (new)
  46. (lambda (x y)
  47. (new (abs x) (abs y))))))
  48. (define make-point/abs
  49. (record-constructor :point-cd/abs))
  50. (define-test-case point/abs r6rs-records-procedural-tests
  51. (check (point-x (make-point/abs -1 -2))
  52. => 1)
  53. (check (point-y (make-point/abs -1 -2))
  54. => 2))
  55. (define :cpoint
  56. (make-record-type-descriptor
  57. 'cpoint :point
  58. #f #f #f
  59. '#((mutable rgb))))
  60. (define make-cpoint
  61. (record-constructor
  62. (make-record-constructor-descriptor
  63. :cpoint :point-cd
  64. (lambda (p)
  65. (lambda (x y c)
  66. ((p x y) (color->rgb c)))))))
  67. (define make-cpoint/abs
  68. (record-constructor
  69. (make-record-constructor-descriptor
  70. :cpoint :point-cd/abs
  71. (lambda (p)
  72. (lambda (x y c)
  73. ((p x y) (color->rgb c)))))))
  74. (define cpoint-rgb
  75. (record-accessor :cpoint 0))
  76. (define (color->rgb c)
  77. (cons 'rgb c))
  78. (define-test-case cpoint r6rs-records-procedural-tests
  79. (check (cpoint-rgb (make-cpoint -1 -3 'red))
  80. => '(rgb . red))
  81. (check (point-x (make-cpoint -1 -3 'red))
  82. => -1)
  83. (check (point-x (make-cpoint/abs -1 -3 'red))
  84. => 1))