test-read.scm 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. ;;; 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. (test-end* "test-read")