aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJakob L. Kreuze2026-06-04 06:47:43 -0400
committerJakob L. Kreuze2026-06-04 06:47:43 -0400
commitedc7760fd02664bda09d25f31b77b325dfe91d8a (patch)
tree65ad6b86ade5b59e0e384ab0d8dfd662e35c01f2 /tests
Implement struct macros/functions
Diffstat (limited to 'tests')
-rw-r--r--tests/struct.scm31
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")

© 2015 - 2026 Jakob L. Kreuze