summaryrefslogtreecommitdiffstats
path: root/tests/011
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-04 21:36:07 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-04 21:36:07 -0700
commitcd157595ffd58ad1eadb52c9adf2671a94794f07 (patch)
tree9a186441049963a92ff01c89b00133079b8fedec /tests/011
parent5be89bc80f7f235805ec706f1ff13e6952f0d34e (diff)
downloadtxr-cd157595ffd58ad1eadb52c9adf2671a94794f07.tar.gz
txr-cd157595ffd58ad1eadb52c9adf2671a94794f07.tar.bz2
txr-cd157595ffd58ad1eadb52c9adf2671a94794f07.zip
matcher: new "each-match family" of macros.
* lisplib.c (match_set_entries): New autoload symbols: each-match, append-matches, keep-matches, each-match-product, append-match-products, keep-match-products. * share/txr/stdlib/doc-syms.tl: Updated. * share/txr/stdlib/match.tl (each-match-expander): New function. (each-match, append-matches, keep-matches, each-match-product, append-match-products, keep-match-products): New macros. * tests/011/patmatch.tl: New tests covering each macro, far from exhaustively. * txr.1: Documented.
Diffstat (limited to 'tests/011')
-rw-r--r--tests/011/patmatch.tl53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl
index f7055602..85adb352 100644
--- a/tests/011/patmatch.tl
+++ b/tests/011/patmatch.tl
@@ -412,6 +412,59 @@
(let ((a "$"))
(test (when-match `@a-@b` "$-@" b) "@"))
+(test
+ (build
+ (each-match (`(@a) @b-@c` '("x"
+ ""
+ "(311) 555-5353"
+ "(604) 923-2323"
+ "133"
+ "4-5-6-7")
+ @x 1)
+ (add (list x a b c))))
+ ((3 "311" "555" "5353") (4 "604" "923" "2323")))
+
+(test
+ (append-matches ((:foo @y) '((:foo a) (:bar b) (:foo c) (:foo d))
+ (@x :bar) '((1 :bar) (2 :bar) (3 :bar) (4 :foo)))
+ (list x y))
+ (1 a 3 c))
+
+(test
+ (append-matches (@x '((1) (2) (3) 4)) x)
+ (1 2 3 . 4))
+
+(test
+ (keep-matches ((:foo @y) '((:foo a) (:bar b) (:foo c) (:foo d))
+ (@x :bar) '((1 :bar) (2 :bar) (3 :bar) (4 :foo)))
+ (list x y))
+ ((1 a) (3 c)))
+
+(test
+ (build
+ (each-match-product (`(@a) @b-@c` '("x"
+ ""
+ "(311) 555-5353"
+ "(604) 923-2323"
+ "133"
+ "4-5-6-7")
+ @(oddp @x) '(1 2 3))
+ (add (list x a b c))))
+ ((1 "311" "555" "5353") (3 "311" "555" "5353")
+ (1 "604" "923" "2323") (3 "604" "923" "2323")))
+
+(test
+ (append-match-products (@(oddp @x) (range 1 5)
+ @(evenp @y) (range 1 5))
+ (list x y))
+ (1 2 1 4 3 2 3 4 5 2 5 4))
+
+(test
+ (keep-match-products (@(oddp @x) (range 1 5)
+ @(evenp @y) (range 1 5))
+ (list x y))
+ ((1 2) (1 4) (3 2) (3 4) (5 2) (5 4)))
+
(compile-only
(eval-only
(compile-file (base-name *load-path*) "temp.tlo")