regexp-check.scm 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. (define-test-suite regexp-tests)
  2. (define-test-case any-match? regexp-tests
  3. (check (any-match? (text "abc") "abc"))
  4. (check (not (any-match? (text "abc") "abx")))
  5. (check (any-match? (text "abc") "xxabcxx")))
  6. (define-test-case exact-match regexp-tests
  7. (check (exact-match? (text "abc") "abc"))
  8. (check (not (exact-match? (text "abc") "abx")))
  9. (check (not (exact-match? (text "abc") "xxabcxx"))))
  10. (define (pair-match exp string)
  11. (let ((res (match exp string)))
  12. (and res
  13. (cons (list (match-start res)
  14. (match-end res))
  15. (map (lambda (p)
  16. (cons (car p)
  17. (list (match-start (cdr p))
  18. (match-end (cdr p)))))
  19. (match-submatches res))))))
  20. (define-test-case match regexp-tests
  21. (check (pair-match (text "abc") "abc")
  22. => '((0 3)))
  23. (check-that (pair-match (text "abc") "abx") (is-false))
  24. (check (pair-match (text "abc") "xxabcxx")
  25. => '((2 5)))
  26. (check (pair-match (sequence (text "ab")
  27. (submatch 'foo (text "cd"))
  28. (text "ef"))
  29. "xxxabcdefxx")
  30. => '((3 9) (foo 5 7)))
  31. (check (pair-match (sequence (set "a")
  32. (one-of (submatch 'foo (text "bc"))
  33. (submatch 'bar (text "BC"))))
  34. "xxxaBCd")
  35. => '((3 6) (bar 4 6))))