File: regexp-check.scm

package info (click to toggle)
scheme48 1.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,232 kB
  • sloc: lisp: 88,907; ansic: 87,519; sh: 3,224; makefile: 771
file content (43 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
; Part of Scheme 48 1.9.  See file COPYING for notices and license.

; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber

(define-test-suite regexp-tests)

(define-test-case any-match? regexp-tests
  (check (any-match? (text "abc") "abc"))
  (check (not (any-match? (text "abc") "abx")))
  (check (any-match? (text "abc") "xxabcxx")))
       
(define-test-case exact-match regexp-tests
  (check (exact-match? (text "abc") "abc"))
  (check (not (exact-match? (text "abc") "abx")))
  (check (not (exact-match? (text "abc") "xxabcxx"))))

(define (pair-match exp string)
  (let ((res (match exp string))) 
    (and res
	 (cons (list (match-start res)
		     (match-end res))
	       (map (lambda (p)
		      (cons (car p)
			    (list (match-start (cdr p))
				  (match-end (cdr p)))))
		    (match-submatches res))))))

(define-test-case match regexp-tests
  (check (pair-match (text "abc") "abc")
	 => '((0 3)))
  (check-that (pair-match (text "abc") "abx") (is-false))
  (check (pair-match (text "abc") "xxabcxx")
	 => '((2 5)))
  (check (pair-match (sequence (text "ab")
			       (submatch 'foo (text "cd"))
			       (text "ef"))
		     "xxxabcdefxx")
	 => '((3 9) (foo 5 7)))
  (check (pair-match (sequence (set "a")
			       (one-of (submatch 'foo (text "bc"))
				       (submatch 'bar (text "BC"))))
		     "xxxaBCd")
	 => '((3 6) (bar 4 6))))