test-write.scm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. ;;; Commentary:
  15. ;;;
  16. ;;; String tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (test utils))
  21. (test-begin "test-write")
  22. (define-syntax test-write
  23. (syntax-rules ()
  24. ((_ datum) (test-write (object->string datum) datum))
  25. ((_ expected-output datum)
  26. (test-write expected-output expected-output datum)
  27. )
  28. ((_ scheme-repr reflect-repr datum)
  29. (let ((output (string-append scheme-repr reflect-repr)))
  30. (test-call output
  31. (lambda ()
  32. (write datum (current-output-port))
  33. (flush-output-port (current-output-port))
  34. datum))))))
  35. (test-write #f)
  36. (test-write #t)
  37. (test-write #nil)
  38. (test-write '())
  39. (test-write (if #f #f))
  40. (let ((eof-object (lambda () the-eof-object)))
  41. (test-write (eof-object)))
  42. (test-write 42)
  43. (test-write -42)
  44. (test-write 42.0)
  45. (test-write -42.0)
  46. (test-write #\a)
  47. (test-write '(1 . 2))
  48. (test-write '(1 2))
  49. (test-write "foo")
  50. (test-write 'foo)
  51. (test-write #vu8())
  52. (test-write #vu8(1 2 3))
  53. (test-write #())
  54. (test-write #(1 2 3))
  55. (test-write #*)
  56. (test-write #*110110)
  57. (test-write "#<procedure>" (lambda () 42))
  58. (test-write #:foo)
  59. ;; Not yet implemented:
  60. ;; Boxes
  61. ;; Atomic boxes
  62. ;; Weak tables
  63. ;; Fluids
  64. ;; Dynamic states
  65. ;; Syntax
  66. ;; Ports
  67. ;; Structs / records
  68. ;; Parameters
  69. (test-end* "test-write")