test-read.scm 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ;;; Copyright (C) 2023, 2024, 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. ;;; Exception tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (test utils))
  21. (test-begin "test-read")
  22. (define-syntax test-read
  23. (lambda (stx)
  24. (syntax-case stx ()
  25. ((_ input)
  26. (let ((repr
  27. (call-with-output-string
  28. (lambda (p)
  29. (write (call-with-input-string
  30. (string-append "#!r6rs " (syntax->datum #'input))
  31. read)
  32. p)))))
  33. #`(with-additional-imports ((scheme read))
  34. (test-call #,repr
  35. (lambda (str) (read (open-input-string str)))
  36. input)))))))
  37. (define-syntax test-read-datum
  38. (lambda (stx)
  39. (syntax-case stx ()
  40. ((_ expr)
  41. (let ((repr (call-with-output-string
  42. (lambda (p) (write (syntax->datum #'expr) p)))))
  43. #`(test-read #,repr))))))
  44. (test-read-datum 1)
  45. (test-read-datum 12)
  46. (test-read-datum (1 2 3))
  47. (test-read-datum "foo")
  48. (test-read-datum "foo\nbar")
  49. (test-read-datum #(1 2 3))
  50. (test-read-datum #vu8(1 2 3))
  51. (test-read-datum #*11001)
  52. (test-read-datum #t)
  53. (test-read-datum #f)
  54. (test-read-datum #:foo)
  55. (test-read-datum #nil)
  56. (test-read "; foo\n1")
  57. (test-read "(#!r6rs 10)")
  58. (test-read "(#!fold-case HEY)")
  59. (test-read "(#!no-fold-case HEY)")
  60. (test-read "(x y . z)")
  61. (test-read "[x y . z]")
  62. (test-read "#xff")
  63. (test-read "10.5")
  64. (test-read "#;42 69")
  65. (test-read "#;42 69")
  66. (test-read "\"\\x61;\"")
  67. (test-read "#true")
  68. (test-read "#false")
  69. (with-additional-imports ((only (hoot read) read-syntax)
  70. (scheme write)
  71. (only (guile)
  72. call-with-input-string
  73. call-with-output-string))
  74. (test-call "\"#<syntax:unknown file:1:0 42>\\n#<syntax:unknown file:1:3 69>\""
  75. (lambda (str)
  76. (call-with-output-string
  77. (lambda (out)
  78. (call-with-input-string
  79. str
  80. (lambda (in)
  81. (display (read-syntax in) out)
  82. (newline out)
  83. (display (read-syntax in) out))))))
  84. "42 69"))
  85. (test-end* "test-read")