/red-system/tests/source/compiler/inference-test.r

http://github.com/dockimbel/Red · R · 58 lines · 41 code · 17 blank · 0 comment · 0 complexity · d7a4aeb6b269f8b5f02d7eaeec9fd848 MD5 · raw file

  1. REBOL [
  2. Title: "Red/System type inference test script"
  3. Author: "Nenad Rakocevic"
  4. File: %inference-test.reds
  5. Rights: "Copyright (C) 2011 Nenad Rakocevic. All rights reserved."
  6. License: "BSD-3 - https://github.com/dockimbel/Red/blob/origin/BSD-3-License.txt"
  7. ]
  8. change-dir %../
  9. ;=== Helper functions ===
  10. --assert-compiles?: func [src [string!] /local exe][
  11. exe: --compile-this src
  12. either exe [
  13. --run exe
  14. --assert qt/output = ""
  15. ][
  16. qt/compile-error src
  17. ]
  18. --clean
  19. ]
  20. ;=== end of helper functions ===
  21. ~~~start-file~~~ "inference-compile"
  22. --test-- "simple inference 1"
  23. --assert-compiles? "foo: func [/local a][a: 1]"
  24. --test-- "simple inference 2"
  25. --assert-compiles? {foo: func [/local a b][a: true b: #"A"]}
  26. --test-- "simple inference 3"
  27. --assert-compiles? {foo: func [/local a][a: either true ["A"]["B"]]}
  28. --test-- "simple inference 4"
  29. --assert-compiles? "foo: func [/local a][while [true][a: 1]]"
  30. --test-- "simple inference 5"
  31. --assert-compiles? {
  32. foo: func [return: [integer!] /local a][a: 123]
  33. bar: func [/local b][b: foo]
  34. }
  35. ~~~end-file~~~
  36. ~~~start-file~~~ "inference-err"
  37. --test-- "inference error"
  38. --compile-this "foo: func [/local a][a]"
  39. --assert-msg? "*** Compilation Error: local variable a used before being initialized!"
  40. --clean
  41. ~~~end-file~~~