test-number-to-string.scm 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ;;; Copyright (C) 2023 Igalia, S.L.
  2. ;;;
  3. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  4. ;;; you may not use this file except in compliance with the License.
  5. ;;; You may obtain a copy of the License at
  6. ;;;
  7. ;;; http://www.apache.org/licenses/LICENSE-2.0
  8. ;;;
  9. ;;; Unless required by applicable law or agreed to in writing, software
  10. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  11. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ;;; See the License for the specific language governing permissions and
  13. ;;; limitations under the License.
  14. (use-modules (srfi srfi-64)
  15. (test utils))
  16. (test-begin "test-number-to-string")
  17. (define radix (make-parameter 10))
  18. (define-syntax test-number->string
  19. (syntax-rules ()
  20. ((_ n) (test-number->string (number->string n (radix)) n))
  21. ((_ expected-output n)
  22. (test-number->string expected-output expected-output n))
  23. ((_ scheme-repr reflect-repr n)
  24. (let ((output (string-append scheme-repr reflect-repr)))
  25. (test-call output
  26. (lambda ()
  27. (write-string (number->string n ,(radix)) (current-output-port))
  28. (flush-output-port (current-output-port))
  29. n))))))
  30. (test-number->string 42)
  31. (parameterize ((radix 16))
  32. (test-number->string "123abc" "1194684" #x123abc))
  33. (test-end* "test-number-to-string")