blob: 7662fed49bbda5e8340ddef0453d8be3d094eaf6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
(use-modules (srfi srfi-64)
(weeb struct))
(test-runner-current (test-runner-simple))
(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 "instance-of?"
(define-struct <animal> species)
(define-struct <dog> breed)
(let ((my-dog (make-struct <dog> "Labrador")))
(test-assert (instance-of? <dog> my-dog))
(test-assert (not (instance-of? <animal> my-dog)))))
(test-group "error-handling"
(define-struct <empty>)
(test-error #t (make-struct <empty> 1)))
(test-end "weeb-struct")
|
© 2015 - 2026 Jakob L. Kreuze