/red-system/tests/source/compiler/cond-expr-test.r

http://github.com/dockimbel/Red · R · 137 lines · 110 code · 27 blank · 0 comment · 3 complexity · 0492ff56e08efa204490571ba9369bac MD5 · raw file

  1. REBOL [
  2. Title: "Red/System conditional expressions test script"
  3. Author: "Nenad Rakocevic"
  4. File: %cond-expr-test.r
  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. ~~~start-file~~~ "conditions-required-err"
  10. --test-- "IF takes a condition expression as first argument"
  11. --compile-this "if 123 []"
  12. --assert-msg? "*** Compilation Error: IF requires a conditional expression"
  13. --clean
  14. --compile-this "if as integer! true []"
  15. --assert-msg? "*** Compilation Error: IF requires a conditional expression"
  16. --clean
  17. --compile-this {
  18. foo: func [return: [integer!]][123]
  19. if foo []
  20. }
  21. --assert-msg? "*** Compilation Error: IF requires a conditional expression"
  22. --clean
  23. --compile-this {
  24. foo: func [][a: 1]
  25. if foo []
  26. }
  27. --assert-msg? "*** Compilation Error: return type missing in function: foo"
  28. --clean
  29. --compile-this "foo: func [][if exit []]"
  30. --assert-msg? "*** Compilation Error: IF requires a conditional expression"
  31. --clean
  32. --test-- "EITHER takes a condition expression as first argument"
  33. --compile-this "either 123 [][]"
  34. --assert-msg? "*** Compilation Error: EITHER requires a conditional expression"
  35. --clean
  36. --compile-this {
  37. foo: func [return: [integer!]][123]
  38. either foo [][]
  39. }
  40. --assert-msg? "*** Compilation Error: EITHER requires a conditional expression"
  41. --clean
  42. --compile-this "foo: func [][either exit [][]]"
  43. --assert-msg? "*** Compilation Error: EITHER requires a conditional expression"
  44. --clean
  45. --test-- "UNTIL takes a condition expression as first argument"
  46. --compile-this "until [123]"
  47. --assert-msg? "*** Compilation Error: UNTIL requires a conditional expression"
  48. --clean
  49. --compile-this {
  50. foo: func [return: [integer!]][123]
  51. until [foo]
  52. }
  53. --assert-msg? "*** Compilation Error: UNTIL requires a conditional expression"
  54. --clean
  55. --compile-this "foo: func [][until [exit]]"
  56. --assert-msg? "*** Compilation Error: UNTIL requires a conditional expression"
  57. --clean
  58. --test-- "WHILE takes a condition expression as first argument"
  59. --compile-this "while [123][a: 1]"
  60. --assert-msg? "*** Compilation Error: WHILE requires a conditional expression"
  61. --clean
  62. --compile-this {
  63. foo: func [return: [integer!]][123]
  64. while [foo][a: 1]
  65. }
  66. --assert-msg? "*** Compilation Error: WHILE requires a conditional expression"
  67. --clean
  68. --compile-this "foo: func [][while [exit][a: 1]]"
  69. --assert-msg? "*** Compilation Error: WHILE requires a conditional expression"
  70. --clean
  71. --test-- "ALL takes only condition expressions in argument block"
  72. --compile-this "all [123]"
  73. --assert-msg? "*** Compilation Error: ALL requires a conditional expression"
  74. --clean
  75. --compile-this {
  76. foo: func [return: [integer!]][123]
  77. all [foo]
  78. }
  79. --assert-msg? "*** Compilation Error: ALL requires a conditional expression"
  80. --clean
  81. --compile-this "foo: func [][all [exit]]"
  82. --assert-msg? "*** Compilation Error: ALL requires a conditional expression"
  83. --clean
  84. --compile-this "all [true 123]"
  85. --assert-msg? "*** Compilation Error: ALL requires a conditional expression"
  86. --clean
  87. --test-- "ANY takes only condition expressions in argument block"
  88. --compile-this "any [123]"
  89. --assert-msg? "*** Compilation Error: ANY requires a conditional expression"
  90. --clean
  91. --compile-this {
  92. foo: func [return: [integer!]][123]
  93. any [foo]
  94. }
  95. --assert-msg? "*** Compilation Error: ANY requires a conditional expression"
  96. --clean
  97. --compile-this "foo: func [][any [exit]]"
  98. --assert-msg? "*** Compilation Error: ANY requires a conditional expression"
  99. --clean
  100. --compile-this "any [true 123]"
  101. --assert-msg? "*** Compilation Error: ANY requires a conditional expression"
  102. --clean
  103. --test-- {Either followed by a block containg a call to a funtion which
  104. doesn't return a value should compile}
  105. --compile-this {
  106. x: does []
  107. either true [x] [x]
  108. }
  109. --assert qt/compile-ok?
  110. ~~~end-file~~~