diff options
Diffstat (limited to 'tests/struct.scm')
| -rw-r--r-- | tests/struct.scm | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/struct.scm b/tests/struct.scm new file mode 100644 index 0000000..64f4137 --- /dev/null +++ b/tests/struct.scm @@ -0,0 +1,31 @@ +(use-modules (srfi srfi-64) + (weeb struct)) + +(test-begin "weeb-struct") + +(test-group "instantiation" + (define-struct <point> x y) + (let ((p (make-struct <point> 10 20))) + (test-eqv 10 ((record-accessor <point> 'x) p)) + (test-eqv 20 ((record-accessor <point> 'y) p)))) + +(test-group "with-accessors" + (define-struct <person> name age) + (let ((p (make-struct <person> "Alice" 30))) + (with-accessors (p name age) + (test-eqv "Alice" name) + (test-eqv 30 age)))) + +(test-group "call-with-slots" + (define-struct <coord> x y) + (let ((c (make-struct <coord> 5 15))) + (call-with-slots c + (lambda (x y) + (test-eqv 5 x) + (test-eqv 15 y))))) + +(test-group "error-handling" + (define-struct <empty>) + (test-error #t (make-struct <empty> 1))) + +(test-end "weeb-struct") |