54.sld 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. (define-library (srfi-tests 54)
  2. (export run-tests)
  3. (import
  4. (scheme base)
  5. (scheme char)
  6. (scheme write)
  7. (srfi 54)
  8. (srfi 64)
  9. (srfi-tests aux))
  10. (begin
  11. (define-syntax value-and-output
  12. (syntax-rules ()
  13. ((_ expr)
  14. (let ((port (open-output-string)))
  15. (parameterize ((current-output-port port))
  16. (let ((value expr))
  17. (list value (get-output-string port))))))))
  18. (define (string-reverse string)
  19. (list->string (reverse (string->list string))))
  20. (define-tests run-tests "SRFI-54"
  21. (test-equal "130.00 " (cat 129.995 -10 2.))
  22. (test-equal " 130.00" (cat 129.995 10 2.))
  23. (test-equal " 129.98" (cat 129.985 10 2.))
  24. (test-equal " 129.99" (cat 129.985001 10 2.))
  25. (test-equal "#e130.00" (cat 129.995 2. 'exact))
  26. (test-equal "129.00" (cat 129 -2.))
  27. (test-equal "#e129.00" (cat 129 2.))
  28. (test-equal "#e+0129.00" (cat 129 10 2. #\0 'sign))
  29. (test-equal "*#e+129.00" (cat 129 10 2. #\* 'sign))
  30. (test-equal "1/3" (cat 1/3))
  31. (test-equal " #e0.33" (cat 1/3 10 2.))
  32. (test-equal " 0.33" (cat 1/3 10 -2.))
  33. (test-equal " 1,29.99,5" (cat 129.995 10 '(#\, 2)))
  34. (test-equal " +129,995" (cat 129995 10 '(#\,) 'sign))
  35. (test-equal "130" (cat (cat 129.995 0.) '(0 -1)))
  36. (cond-expand (chibi (test-expect-fail 2)) (else))
  37. (test-equal "#i#o+307/2" (cat 99.5 10 'sign 'octal))
  38. (test-equal " #o+307/2" (cat 99.5 10 'sign 'octal 'exact))
  39. (test-equal "#o+443" (cat #x123 'octal 'sign))
  40. (test-equal "#e+291.00*" (cat #x123 -10 2. 'sign #\*))
  41. (test-equal "-1.234e+15+1.236e-15i" (cat -1.2345e+15+1.2355e-15i 3.))
  42. (test-equal "+1.234e+15" (cat 1.2345e+15 10 3. 'sign))
  43. (test-equal "string " (cat "string" -10))
  44. (test-equal " STRING" (cat "string" 10 (list string-upcase)))
  45. (test-equal " RING" (cat "string" 10 (list string-upcase) '(-2)))
  46. (test-equal " STING" (cat "string" 10 `(,string-upcase) '(2 3)))
  47. (test-equal "GNIRTS" (cat "string" `(,string-reverse ,string-upcase)))
  48. (test-equal " a" (cat #\a 10))
  49. (test-equal " symbol" (cat 'symbol 10))
  50. (test-equal "#(#\\a \"str\" s)" (cat '#(#\a "str" s)))
  51. (test-equal "(#\\a \"str\" s)" (cat '(#\a "str" s)))
  52. (test-equal '("(#\\a \"str\" s)" "(#\\a \"str\" s)")
  53. (value-and-output (cat '(#\a "str" s) #t)))
  54. (test-equal '("(#\\a \"str\" s)" "(#\\a \"str\" s)")
  55. (value-and-output (cat '(#\a "str" s) (current-output-port))))
  56. (test-equal "3s \"str\"" (cat 3 (cat 's) " " (cat "str" write)))
  57. (test-equal '("3s \"str\"" "3s \"str\"")
  58. (value-and-output (cat 3 #t (cat 's) " " (cat "str" write))))
  59. (test-equal '("3s \"str\"" "s3s \"str\"")
  60. (value-and-output (cat 3 #t (cat 's #t) " " (cat "str" write)))))
  61. ))