PageRenderTime 15ms CodeModel.GetById 3ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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