diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2022-11-19 17:23:04 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2022-12-02 00:02:12 +0100 |
| commit | 7c1161dba4c8930d3a500a72ccaaaf50df73f466 (patch) | |
| tree | c524b49ebde713b660443cf588a0858a9c58e166 /tests/records.scm | |
| parent | 594f5ef35107d5641c44dac5cd7e9fb3737b674b (diff) | |
records: 'match-record' checks fields at macro-expansion time.
This allows 'match-record' to be more efficient (field offsets are
computed at compilation time) and to report unknown fields at
macro-expansion time.
* guix/records.scm (map-fields): New macro.
(define-record-type*)[rtd-identifier]: New procedure.
Define TYPE as a macro and use a separate identifier for the RTD.
(lookup-field, match-record-inner): New macros.
(match-record): Rewrite in terms of 'match-error-inner'.
* tests/records.scm ("match-record, simple")
("match-record, unknown field"): New tests.
* gnu/services/cuirass.scm (cuirass-shepherd-service): Rename 'log-file'
local variable to 'main-log-file'.
* gnu/services/getmail.scm (serialize-getmail-configuration-file): Move
after <getmail-configuration-file> definition.
Diffstat (limited to 'tests/records.scm')
| -rw-r--r-- | tests/records.scm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/records.scm b/tests/records.scm index 00c58b07364..8504c8d5a54 100644 --- a/tests/records.scm +++ b/tests/records.scm | |||
| @@ -528,4 +528,37 @@ Description: 1st line, | |||
| 528 | '("a" "b" "c") | 528 | '("a" "b" "c") |
| 529 | '("a"))) | 529 | '("a"))) |
| 530 | 530 | ||
| 531 | (test-equal "match-record, simple" | ||
| 532 | '((1 2) (a b)) | ||
| 533 | (let () | ||
| 534 | (define-record-type* <foo> foo make-foo | ||
| 535 | foo? | ||
| 536 | (first foo-first (default 1)) | ||
| 537 | (second foo-second)) | ||
| 538 | |||
| 539 | (list (match-record (foo (second 2)) <foo> | ||
| 540 | (first second) | ||
| 541 | (list first second)) | ||
| 542 | (match-record (foo (first 'a) (second 'b)) <foo> | ||
| 543 | (second first) | ||
| 544 | (list first second))))) | ||
| 545 | |||
| 546 | (test-equal "match-record, unknown field" | ||
| 547 | 'syntax-error | ||
| 548 | (catch 'syntax-error | ||
| 549 | (lambda () | ||
| 550 | (eval '(begin | ||
| 551 | (use-modules (guix records)) | ||
| 552 | |||
| 553 | (define-record-type* <foo> foo make-foo | ||
| 554 | foo? | ||
| 555 | (first foo-first (default 1)) | ||
| 556 | (second foo-second)) | ||
| 557 | |||
| 558 | (match-record (foo (second 2)) <foo> | ||
| 559 | (one two) | ||
| 560 | #f)) | ||
| 561 | (make-fresh-user-module))) | ||
| 562 | (lambda (key . args) key))) | ||
| 563 | |||
| 531 | (test-end) | 564 | (test-end) |
