matcher-check.scm 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Mike Sperber, Robert Ransom
  3. (define-test-suite matchers-tests)
  4. (define-test-case is matchers-tests
  5. (check (matches? (is number?) 5))
  6. (check (not (matches? (is number?) #t)))
  7. (check (matches? (is equal? 7) 7))
  8. (check (matches? (is 7) 7))
  9. (check (not (matches? (is equal? 7) 5))))
  10. (define-test-case anything matchers-tests
  11. (check (matches? (anything) 7))
  12. (check (matches? (anything) #f)))
  13. (define-test-case opposite matchers-tests
  14. (check (not (matches? (opposite (anything)) 7)))
  15. (check (not (matches? (opposite (anything)) #f))))
  16. (define-test-case is-true matchers-tests
  17. (check (matches? (is-true) #t))
  18. (check (matches? (is-true) 5)))
  19. (define-test-case is-false matchers-tests
  20. (check (matches? (is-false) #f))
  21. (check (not (matches? (is-false) #t)))
  22. (check (not (matches? (is-false) 5))))
  23. (define-test-case is-null matchers-tests
  24. (check (matches? (is-null) '()))
  25. (check (not (matches? (is-null) #f)))
  26. (check (not (matches? (is-null) #t)))
  27. (check (not (matches? (is-null) 5))))
  28. (define-test-case is-within matchers-tests
  29. (check (matches? (is-within 5 0.01) 5))
  30. (check (matches? (is-within 5 0.01) 5.0001))
  31. (check (not (matches? (is-within 5 0.01) 5.1))))
  32. (define-test-case all-of matchers-tests
  33. (check (matches? (all-of (is-true) (is 5)) 5))
  34. (check (not (matches? (all-of (is-true) (is-false)) #t))))
  35. (define-test-case any-of matchers-tests
  36. (check (matches? (any-of (is-false) (is 5)) 5))
  37. (check (matches? (any-of (is 5) (is-false)) 5))
  38. (check (not (matches? (any-of (is 5) (is-false)) #t))))
  39. (define-test-case list-where-all matchers-tests
  40. (check (matches? (list-where-all (is odd?)) '(1 3 5)))
  41. (check (not (matches? (list-where-all (is odd?)) '(1 2 5)))))
  42. (define-test-case list-where-any matchers-tests
  43. (check (matches? (list-where-any (is even?)) '(1 2 5)))
  44. (check (not (matches? (list-where-any (is even?)) '(1 3 5)))))