1(cond-expand2 (chicken-53 (import (r7rs) (test) (posix-regex)))4 (chicken-65 (import (scheme base) test posix-regex)))67(define (test-match pattern string . options)8 (regex-match?9 (apply make-regex (append (list pattern) options))10 string))1112(define (test-exec pattern string)13 (regex-exec14 (make-regex pattern)15 (string->utf8 string)))1617;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1819(test-group "make-regex"20 (test-assert "literal string" (regex? (make-regex "foo")))21 (test-assert "ignorecase" (regex? (make-regex "foobar" #t)))22 (test-assert "extended regular expression" (regex? (make-regex "[0-9]+" #f #t)))23 (test-assert "newline option" (regex? (make-regex "foo" #f #f #t)))2425 (test-error "invalid interval expression" (make-regex "\\{foo,foo\\}")) ;; REG_BADAR26 (test-error "parentheses imbalance" (make-regex "\\(foo")) ;; REG_EBRACE27 (test-error "bracket imbalance" (make-regex "[")) ;; REG_EBRACK28 (test-error "trailing backslash" (make-regex "\\"))) ;; REG_EESCAPE2930(test-group "regex-match?"31 (test "match literal string" #t (test-match "foo" "foo"))32 (test "don't match literal string" #f (test-match "foo" "bar"))33 (test "partially match literal string" #t (test-match "foo" "foobar"))34 (test "match bracket expression" #t (test-match "f[a-z][a-z]b" "foobar"))35 (test "match repeated expression" #t (test-match "a*b" "aaaaab"))36 (test "match start and end" #f (test-match "^foo$" "|foo|"))37 (test "multiline mode" #t (test-match "^foo" "bar\nfoo\n" #f #f #t))38 (test "non-multiline mode" #f (test-match "^foo" "bar\nfoo\n")))3940(test-group "regex-exec"41 (test "match literal string"42 #((0 . 3))43 (test-exec "foo" "foo"))4445 (test "not matching"46 #f47 (test-exec "foo" "bar"))4849 (test "match single submatch"50 #((0 . 13) (5 . 8))51 (test-exec "foo |\\(..*\\)| baz" "foo |bar| baz"))5253 (test "match zero-length string"54 #((0 . 10) (5 . 5))55 (test-exec "foo '\\(.*\\)' baz" "foo '' baz"))5657 (test "non-participating submatch"58 #((0 . 8) #f (5 . 8))59 (test-exec "foo \\(..*\\)* \\(..*\\)" "foo baz")))6061;; Exit with non-zero exit status if some test failed.62(test-exit)