test-write.scm 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ;;; Copyright (C) 2023, 2025 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. (with-additional-imports ((scheme write))
  31. (test-call output
  32. (lambda (x)
  33. (write x (current-output-port))
  34. (flush-output-port (current-output-port))
  35. x)
  36. datum))))))
  37. (test-write #f)
  38. (test-write #t)
  39. (test-write #nil)
  40. (test-write '())
  41. (test-write (if #f #f))
  42. (let ((eof-object (lambda () the-eof-object)))
  43. (test-write (eof-object)))
  44. (test-write 42)
  45. (test-write -42)
  46. (test-write 42.0)
  47. (test-write -42.0)
  48. (test-write #\a)
  49. (test-write '(1 . 2))
  50. (test-write '(1 2))
  51. (test-write "foo")
  52. (test-write 'foo)
  53. (test-write #vu8())
  54. (test-write #vu8(1 2 3))
  55. (test-write #())
  56. (test-write #(1 2 3))
  57. (test-write #*)
  58. (test-write #*110110)
  59. (test-write "#<procedure>" (lambda () 42))
  60. (test-write #:foo)
  61. (test-write "#<port>" (open-input-string "foo"))
  62. ;; Not yet implemented:
  63. ;; Boxes
  64. ;; Atomic boxes
  65. ;; Weak tables
  66. ;; Fluids
  67. ;; Dynamic states
  68. ;; Syntax
  69. ;; Structs / records
  70. ;; Parameters
  71. (test-end* "test-write")