12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- (define-module (test-records)
- #:use-module (ice-9 format)
- #:use-module (test-suite lib))
- (define rtd-foo (make-record-type "foo" '(x y)
- (lambda (s p)
- (display "#<it is a foo>" p))))
- (define make-foo (record-constructor rtd-foo))
- (define foo? (record-predicate rtd-foo))
- (define get-foo-x (record-accessor rtd-foo 'x))
- (define get-foo-y (record-accessor rtd-foo 'y))
- (define set-foo-x! (record-modifier rtd-foo 'x))
- (define set-foo-y! (record-modifier rtd-foo 'y))
- (define rtd-fŏŏ (make-record-type "fŏŏ" '(x ȳ)))
- (define make-fŏŏ (record-constructor rtd-fŏŏ))
- (define fŏŏ? (record-predicate rtd-fŏŏ))
- (define get-fŏŏ-x (record-accessor rtd-fŏŏ 'x))
- (define get-fŏŏ-ȳ (record-accessor rtd-fŏŏ 'ȳ))
- (define set-fŏŏ-x! (record-modifier rtd-fŏŏ 'x))
- (define set-fŏŏ-ȳ! (record-modifier rtd-fŏŏ 'ȳ))
- (with-test-prefix "records"
-
- (with-test-prefix "constructor"
- (pass-if-exception "0 args (2 required)" exception:wrong-num-args
- (make-foo))
- (pass-if-exception "1 arg (2 required)" exception:wrong-num-args
- (make-foo 1))
- (pass-if "2 args (2 required)" exception:wrong-num-args
- (foo? (make-foo 1 2)))
- (pass-if "non-latin-1" exception:wrong-num-args
- (fŏŏ? (make-fŏŏ 1 2))))
- (with-test-prefix "modifier and getter"
- (pass-if "set"
- (let ((r (make-foo 1 2)))
- (set-foo-x! r 3)
- (eqv? (get-foo-x r) 3)))
- (pass-if "set 2"
- (let ((r (make-fŏŏ 1 2)))
- (set-fŏŏ-ȳ! r 3)
- (eqv? (get-fŏŏ-ȳ r) 3))))
- (with-test-prefix "record type name"
-
- (pass-if "foo"
- (string=? "foo" (record-type-name rtd-foo)))
- (pass-if "fŏŏ"
- (string=? "fŏŏ" (record-type-name rtd-fŏŏ))))
- (with-test-prefix "printer"
- (pass-if "foo"
- (string=? "#<it is a foo>"
- (with-output-to-string
- (lambda () (display (make-foo 1 2))))))
- (pass-if "fŏŏ"
- (with-locale "en_US.utf8"
- (string-prefix? "#<fŏŏ"
- (with-output-to-string
- (lambda () (display (make-fŏŏ 1 2)))))))))
|