regexp-check.scm 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber
  3. (define-test-suite regexp-tests)
  4. (define-test-case any-match? regexp-tests
  5. (check (any-match? (text "abc") "abc"))
  6. (check (not (any-match? (text "abc") "abx")))
  7. (check (any-match? (text "abc") "xxabcxx")))
  8. (define-test-case exact-match regexp-tests
  9. (check (exact-match? (text "abc") "abc"))
  10. (check (not (exact-match? (text "abc") "abx")))
  11. (check (not (exact-match? (text "abc") "xxabcxx"))))
  12. (define (pair-match exp string)
  13. (let ((res (match exp string)))
  14. (and res
  15. (cons (list (match-start res)
  16. (match-end res))
  17. (map (lambda (p)
  18. (cons (car p)
  19. (list (match-start (cdr p))
  20. (match-end (cdr p)))))
  21. (match-submatches res))))))
  22. (define-test-case match regexp-tests
  23. (check (pair-match (text "abc") "abc")
  24. => '((0 3)))
  25. (check-that (pair-match (text "abc") "abx") (is-false))
  26. (check (pair-match (text "abc") "xxabcxx")
  27. => '((2 5)))
  28. (check (pair-match (sequence (text "ab")
  29. (submatch 'foo (text "cd"))
  30. (text "ef"))
  31. "xxxabcdefxx")
  32. => '((3 9) (foo 5 7)))
  33. (check (pair-match (sequence (set "a")
  34. (one-of (submatch 'foo (text "bc"))
  35. (submatch 'bar (text "BC"))))
  36. "xxxaBCd")
  37. => '((3 6) (bar 4 6))))