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

/red-system/tests/source/units/return-test.reds

http://github.com/dockimbel/Red
Unknown | 168 lines | 150 code | 18 blank | 0 comment | 0 complexity | 46a5c04c66ce881243a1bb7fb8e81906 MD5 | raw file
  1Red/System [
  2	Title:   "Red/System RETURN keyword test script"
  3	Author:  "Nenad Rakocevic"
  4	File: 	 %test-return.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
  9#include %../../../../quick-test/quick-test.reds
 10
 11~~~start-file~~~ "return"
 12  
 13  --test-- "return-1"
 14    ret-test: func [return: [integer!]][return 1]
 15  --assert ret-test = 1
 16  	ret-test1-1: func [s [c-string!] return: [c-string!]][return s]
 17  --assert 5 = length? ret-test1-1 "hello"
 18
 19  --test-- "return-2"
 20    i: 0
 21    ret-test98: func [return: [logic!]][
 22      return true
 23      i: 1
 24      false
 25    ]
 26  --assert ret-test98
 27  --assert i = 0
 28
 29  --test-- "return-3"
 30    i: 0
 31    ret-test99: func [return: [logic!]][
 32      return false
 33      i: 1
 34      true
 35    ]
 36  --assert not ret-test99
 37  --assert i = 0
 38
 39  --test-- "return-4"
 40    i: 0
 41    ret-test2: func [return: [logic!]][
 42      i: 1
 43      return true
 44      i: 2
 45      false
 46    ]
 47  --assert ret-test2
 48  --assert i = 1
 49
 50  --test-- "return-5"
 51    i: 0
 52    ret-test3: func [return: [logic!]][
 53      i: 1
 54      if true [return true i: 2]
 55      i: 3
 56      false
 57    ]
 58  --assert ret-test3
 59  --assert i = 1
 60
 61  --test-- "return-6"
 62    i: 0
 63    ret-test97: func [a [logic!] return: [logic!]][
 64      i: 1
 65      if true [return a i: 2]
 66      i: 3
 67      false
 68    ]
 69  --assert ret-test97 true
 70  --assert i = 1
 71
 72  --test-- "return-7"
 73    i: 0
 74    ret-test4: func [return: [logic!]][
 75      i: 1
 76      if false [return false i: 2]
 77      i: 1
 78      true
 79    ]
 80  --assert ret-test4
 81  --assert i = 1
 82
 83  --test-- "return-8"
 84    i: 0
 85    ret-test5: func [return: [logic!]][
 86      i: 1
 87      either true [return 1 < 2 i: 2][i: 3]
 88      i: 4
 89      false
 90    ]
 91  --assert ret-test5
 92  --assert i = 1
 93
 94  --test-- "return-9"
 95    i: 0
 96    ret-test6: func [return: [logic!]][
 97      i: 1
 98      either false [return false][i: 1 return true i: 2]
 99      i: 3
100      false
101    ]
102  --assert ret-test6
103  --assert i = 1
104
105  --test-- "return-10"
106    i: 0
107    ret-test7: func [return: [logic!]][
108      i: 1
109      either 1 < 2 [
110        either 3 < 4 [
111          return true
112          i: 2
113        ][
114          i: 3
115        ]
116      ][
117        i: 4
118      ]
119      i: 5
120      false
121    ]
122  --assert ret-test7
123  --assert i = 1
124
125;; ret-test8 moved to return-test.r
126
127  --test-- "return-11"
128    i: 0
129    ret-test9: func [return: [logic!]][
130      i: 1
131      until [
132        return false
133        true
134      ]
135      i: 2
136      true
137    ]
138  --assert not ret-test9
139  --assert i = 1
140
141  --test-- "return-12"
142    i: 0
143    ret-test10: func [return: [integer!]][
144      i: 1
145      until [
146        if true [return 42]
147        i: 2
148        true
149      ]
150      i: 3
151    ]
152  --assert ret-test10 = 42
153  --assert i = 1
154  
155  --test-- "return-13"
156	ret-test13: func [
157		i [integer!]
158		n [integer!]
159		return: [integer!]
160		/local s
161	][
162		if 0 = i [return i]	
163		i
164	]
165	--assert 0 = ret-test13 0 2
166
167~~~end-file~~~
168