test-constants.scm 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. ;;; Constant value tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (test utils))
  21. (test-begin "test-constants")
  22. (test-compilation 42 "42")
  23. (test-compilation 100 "100")
  24. (test-compilation -1 "-1")
  25. (test-compilation -42 "-42")
  26. (test-compilation 1.0 "1.0")
  27. (test-compilation 1.5 "1.5")
  28. (test-compilation 1/4 "1/4")
  29. (test-compilation 4.0+2.0i "4.0+2.0i")
  30. (test-compilation #f "#f")
  31. (test-compilation '#nil "#nil")
  32. (test-compilation '() "()")
  33. (test-compilation #t "#t")
  34. (test-compilation #\a "#\\a")
  35. (test-compilation (if #f #f) "#<unspecified>")
  36. ;(test-compilation the-eof-object "#<eof>")
  37. (test-compilation '(1 . 2) "(1 . 2)")
  38. (test-compilation '(1 2 3 4) "(1 2 3 4)")
  39. (test-compilation #() "#()")
  40. (test-compilation #(3 10 (42)) "#(3 10 (42))")
  41. (test-compilation #vu8() "#vu8()")
  42. (test-compilation #vu8(3 10 42) "#vu8(3 10 42)")
  43. (test-compilation #* "#*")
  44. (test-compilation #*101 "#*101")
  45. (test-compilation #*100000 "#*100000")
  46. (test-compilation #*000000000000000000000000000000001 "#*000000000000000000000000000000001")
  47. (test-compilation "foo" "\"foo\"")
  48. (test-compilation (lambda () 42) "#<procedure>")
  49. (test-compilation #:foo "#:foo")
  50. (test-compilation 'TZAG "TZAG")
  51. (test-call "42" (lambda () 42))
  52. (test-call "69" (lambda (x) x) 69)
  53. (test-call "hey" (lambda (x) (if x 'hey 'ho)) #t)
  54. (test-call "hey2" (lambda (x) (if x 'hey2 'ho)) 42)
  55. (test-call "ho" (lambda (x) (if x 'hey3 'ho)) #f)
  56. (test-call "10" (lambda (x y) (+ x y)) 6 4)
  57. (test-call "rerro" (lambda () 'rerro))
  58. (test-call "1337" (lambda (f) (f)) (lambda () 1337))
  59. (test-call "43" (lambda (f) (+ (f) 1)) (lambda () 42))
  60. ;; This is how you would debug outside the test suite...
  61. ;; (call-with-compiled-wasm-file
  62. ;; (compile '(lambda (n)
  63. ;; (let fib ((n n))
  64. ;; (if (<= n 1)
  65. ;; 1
  66. ;; (+ (fib (- n 1)) (fib (- n 2))))))
  67. ;; #:import-abi? #f #:export-abi? #t #:dump-cps? #t #:dump-wasm? #t)
  68. ;; (lambda (proc)
  69. ;; (call-with-compiled-wasm-file
  70. ;; (compile 40 #:import-abi? #t #:export-abi? #f)
  71. ;; (lambda (arg)
  72. ;; (copy-file proc "/tmp/proc.wasm")
  73. ;; (copy-file arg "/tmp/arg.wasm")
  74. ;; (pk (run-d8 "test-call.js" "--" proc arg))))))
  75. (test-end* "test-constants")