test-read.scm 2.7 KB

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