bf6 bunch of tests for pm

This commit is contained in:
voidlizard 2025-06-08 12:12:35 +03:00
parent a7dd973732
commit 9a90884d46
8 changed files with 247 additions and 0 deletions

View File

@ -0,0 +1,9 @@
(println
(match '[1 2 3]
( _ ok )
)
)

View File

@ -0,0 +1,9 @@
(println
(match '[1 2 3]
( [list?] ok )
)
)

View File

@ -0,0 +1,7 @@
(println test1)
(match 123
( [? foo [? k [int? _]] ] (println okay space k space foo))
( _ (println not-okay))
)

View File

@ -0,0 +1,156 @@
(println
(match 10
( n n )
)
)
(println
(match 10
( _ ok )
)
)
(println
(match '[]
( [list?] ok-nil )
)
)
(println
(match 11
( [int?] ok-int )
)
)
(println "atom/int")
(println
(match :wtf
( [int?] ok-int )
( _ ok-not-matched )
)
)
(println "atom/atom")
(println
(match :wtf
( [sym?] ok-matched )
( _ fail-not-matched )
)
)
(println "int/predicate")
(println
(match 9000
( [int? 9000] ok-matched-9000 )
( _ fail-not-matched )
)
)
(println "int/predicate-2")
(println
(match 9000
( [int? 5000] fail-matched-5000 )
( _ ok-not-matched )
)
)
(println "int/predicate-3")
(println
(match 9000
( [int? [fn x . gt? x 1000]] ok-predicate-matched-gt-1000 )
( _ fail-not-matched )
)
)
(println "int/predicate-4")
(println
(match 9000
( [int? [fn x . le? x 1000]] fail-predicate-matched-le-1000 )
( _ ok-not-matched )
)
)
(println "list/1")
(println
(match '[1 2 3 4]
( [list? ...] [display ok ...])
( _ fail-not-matched)
)
)
(println "list/2")
(println
(match '[1 2]
( [list? a b] `[ok ,a ,b])
( _ fail-not-matched)
)
)
(println "list/3")
(println
(match '[1 2]
( [list? ...] [display ...])
( _ fail-not-matched)
)
)
(println "list/3.1")
(println
(match '[]
( [list? ...] (display ok ...) )
( _ fail-not-matched)
)
)
(println "list/4")
(define (l4 s)
(match s
( [list? a ...] (begin (println :l4 space a) (l4 ...)) )
( [list?] :done)
)
)
(l4 '[1 2 3 4 5])
(println :here-is-a space a)
(define bebebe 134)
(define (fuu) (define bebebe :jopa))
(fuu)
(println bebebe)

View File

@ -0,0 +1,20 @@
(println Test1)
(match 100
( [int? 100] (println okay))
( _ (println not-okay))
)
(println Test2)
(match 100
( [int?] (println okay))
( _ (println not-okay))
)
(println Test3)
(match 100
( [int? _] (println okay))
( _ (println not-okay))
)

View File

@ -0,0 +1,18 @@
(println "list/1")
(println
(match '[1 2 3 4]
( [list? ...] [display ok ...])
( _ fail-not-matched)
)
)
(println "list/1.1")
(println
(match [list 1 [list 2 3 4]]
( [list? a [list? b c ...] ...] [println a space c])
( _ fail-not-matched)
)
)

View File

@ -0,0 +1,11 @@
(println "list/4")
(define (l4 s)
(match s
( [list? a ...] (begin (println :l4 space a) (l4 ...)) )
( [list?] (println :l4 space :done))
)
)
(l4 '[1 2 3 4 5 6])

View File

@ -0,0 +1,17 @@
(local l1 [list 1 2 3 4 5 6 7 8])
(define (q x) (begin (println x) (f x)))
(define (f x)
(match x
( [list? n ...] (q ...) )
( [list?] '() )
))
(f l1)