blob: 01c984d379b5acdcf419eba6af2ab2e3d7ef63fe (
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
;;; Weeb --- Web microframework for GNU Guile
;;; Copyright © 2026 Jakob Kreuze <zerodaysfordays@sdf.org>
;;;
;;; This file is part of Weeb.
;;;
;;; Weeb is free software: you can redistribute it and/or modify it
;;; under the terms of the GNU Affero General Public License as
;;; published by the Free Software Foundation, either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; Weeb is distributed in the hope that it will be useful, but WITHOUT
;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
;;; Public License for more details.
;;;
;;; You should have received a copy of the GNU Affero General Public
;;; License along with Weeb. If not, see <https://www.gnu.org/licenses/>.
(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