srfi-16-test.scm 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ;; Submitted by Andrea Girotto <andrea.girotto@gmail.com> 15 Nov 2009
  2. ;; as part of Savannah 15 Nov 2009 bug report #28022:
  3. ;; "case-lambda (srfi 16) not working with strings".
  4. ;; Converted to SRFI-64-style, and a couple of bugs fixed, by Per Bothner.
  5. (test-begin "srfi-16-test" 12)
  6. (define add-proc
  7. (case-lambda
  8. (() 0)
  9. ((x) x)
  10. ((x y) (+ x y))
  11. ((x y z) (+ (+ x y) z))
  12. (args (apply + args)) ) )
  13. (test-equal 0 (add-proc))
  14. (test-equal 1 (add-proc 1))
  15. (test-equal 5 (add-proc 2 3))
  16. (test-equal 15 (add-proc 4 5 6))
  17. (test-equal 34 (add-proc 7 8 9 10))
  18. (define list-proc
  19. (case-lambda
  20. (() '())
  21. ((x l) (cons x l))
  22. ((x l1 l2) (cons x (list-proc l1 l2)))
  23. (x x) ) )
  24. (test-equal '() (list-proc))
  25. (test-equal '(a) (list-proc 'a))
  26. (test-equal '(a . b) (list-proc 'a 'b))
  27. (test-equal '(a b . c) (list-proc 'a 'b 'c))
  28. (define string-proc
  29. (case-lambda
  30. (() "null-string")
  31. ((x) (string-append "to-string:" x))
  32. (l (apply string-append (cons "append:" l))) ) )
  33. (test-equal "null-string" (string-proc))
  34. (test-equal "to-string:this" (string-proc "this"))
  35. (test-equal "append:thisthatthose" (string-proc "this" "that" "those"))
  36. (test-end)