diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/records.scm | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/tests/records.scm b/tests/records.scm index 5464892d3b5..9c071334d50 100644 --- a/tests/records.scm +++ b/tests/records.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2012-2016, 2018-2022 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2012-2016, 2018-2022, 2026 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; | 3 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 4 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 5 | ;;; |
| @@ -238,6 +238,70 @@ | |||
| 238 | (bar? first) | 238 | (bar? first) |
| 239 | (eq? first y))))))) | 239 | (eq? first y))))))) |
| 240 | 240 | ||
| 241 | (test-equal "define-record-type* & thunked & no inherited value" | ||
| 242 | '(baz) ;the unbound variable | ||
| 243 | (catch 'unbound-variable | ||
| 244 | (lambda () | ||
| 245 | (eval '(begin | ||
| 246 | (define-record-type* <foo> foo make-foo | ||
| 247 | foo? | ||
| 248 | (bar foo-bar) | ||
| 249 | (baz foo-baz (thunked))) | ||
| 250 | |||
| 251 | ;; There's no inheritance here so 'baz' is unbound in the field | ||
| 252 | ;; body. Call 'foo-baz' to trigger to unbound variable error. | ||
| 253 | (foo-baz (foo (bar 1) (baz baz)))) | ||
| 254 | (test-module))) | ||
| 255 | (lambda (key proc message arguments . rest) | ||
| 256 | arguments))) | ||
| 257 | |||
| 258 | (test-equal "define-record-type* & thunked & inherited value" | ||
| 259 | '(1 22) | ||
| 260 | (begin | ||
| 261 | (define-record-type* <foo> foo make-foo | ||
| 262 | foo? | ||
| 263 | (bar foo-bar) | ||
| 264 | (baz foo-baz (thunked))) | ||
| 265 | |||
| 266 | (let* ((parent (foo (bar 1) (baz 2))) | ||
| 267 | (child (foo (inherit parent) | ||
| 268 | (baz (* baz 11))))) | ||
| 269 | (list (foo-bar child) (foo-baz child))))) | ||
| 270 | |||
| 271 | (test-equal "define-record-type* & thunked & inherited value & this-record" | ||
| 272 | '((1 2) => (21 (inherited . 42))) | ||
| 273 | (begin | ||
| 274 | (define-record-type* <foo> foo make-foo | ||
| 275 | foo? | ||
| 276 | (bar foo-bar) | ||
| 277 | (baz foo-baz (thunked))) | ||
| 278 | |||
| 279 | (let* ((parent (foo (bar 1) | ||
| 280 | (baz (* 2 (foo-bar this-record))))) | ||
| 281 | (child (foo (inherit parent) | ||
| 282 | (bar 21) | ||
| 283 | (baz (cons 'inherited baz))))) | ||
| 284 | `((,(foo-bar parent) ,(foo-baz parent)) | ||
| 285 | => | ||
| 286 | (,(foo-bar child) ,(foo-baz child)))))) | ||
| 287 | |||
| 288 | (test-equal "define-record-type* & thunked & inherited value & sanitizer" | ||
| 289 | '((1 "2") => (4 "88")) | ||
| 290 | (begin | ||
| 291 | (define-record-type* <foo> foo make-foo | ||
| 292 | foo? | ||
| 293 | (bar foo-bar) | ||
| 294 | (baz foo-baz (thunked) (sanitize number->string))) | ||
| 295 | |||
| 296 | (let* ((parent (foo (bar 1) | ||
| 297 | (baz (* 2 (foo-bar this-record))))) | ||
| 298 | (child (foo (inherit parent) | ||
| 299 | (bar 4) | ||
| 300 | (baz (+ 80 (string->number baz)))))) | ||
| 301 | `((,(foo-bar parent) ,(foo-baz parent)) | ||
| 302 | => | ||
| 303 | (,(foo-bar child) ,(foo-baz child)))))) | ||
| 304 | |||
| 241 | (test-assert "define-record-type* & delayed" | 305 | (test-assert "define-record-type* & delayed" |
| 242 | (begin | 306 | (begin |
| 243 | (define-record-type* <foo> foo make-foo | 307 | (define-record-type* <foo> foo make-foo |
