This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathreturn.livecodescript
More file actions
249 lines (201 loc) · 8.4 KB
/
return.livecodescript
File metadata and controls
249 lines (201 loc) · 8.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
script "CoreEngineReturn"
/*
Copyright (C) 2016 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
--------
private command SetTheResultTo pValue
return pValue
end SetTheResultTo
-------- Test behavior of no return statement
-- Engine behavior is that script handlers reset 'the result' to empty before
-- they execute, so this should be seen outside the handler if there is no
-- return.
private command DoNothingThenNoReturnInCommand
end DoNothingThenNoReturnInCommand
private function DoNothingThenNoReturnInFunction
end DoNothingThenNoReturnInFunction
-- Engine behavior is that 'the result' is not touched if there is no return
-- statement, so the last value 'the result' was set to in the handler should
-- be its value after the handler has finished executing.
private command DoTailThenNoReturnInCommand pValue
SetTheResultTo pValue
end DoTailThenNoReturnInCommand
private function DoTailThenNoReturnInFunction pValue
SetTheResultTo pValue
end DoTailThenNoReturnInFunction
on TestNoReturn
SetTheResultTo "TheResult"
get "TheIt"
DoNothingThenNoReturnInCommand
TestAssert "no return in command leaves it and sets the result to empty", \
it is "TheIt" and \
the result is empty
SetTheResultTo "TheResult"
get "TheIt"
TestAssert "no return in function leaves it, returns empty and sets the result to empty", \
DoNothingThenNoReturnInFunction() is empty and \
it is "TheIt" and \
the result is empty
SetTheResultTo "TheResult"
get "TheIt"
DoTailThenNoReturnInCommand "NewResult"
TestAssert "no return in tail command leaves it and sets the result to the result of the tail", \
it is "TheIt" and \
the result is "NewResult"
SetTheResultTo "TheResult"
get "TheIt"
TestAssert "no return in tail function leaves it, returns the result of the tail and sets the result to the tail", \
DoTailThenNoReturnInFunction("NewResult") is "NewResult" and \
it is "TheIt" and \
the result is "NewResult"
end TestNoReturn
-------- Test behavior of the return statement
private command DoReturnInCommand pValue
return pValue
end DoReturnInCommand
private function DoReturnInFunction pValue
return pValue
end DoReturnInFunction
on TestReturn
SetTheResultTo "TheResult"
get "TheIt"
DoReturnInCommand "NewResult"
TestAssert "return in command leaves it and sets the result", \
it is "TheIt" and \
the result is "NewResult"
local tFu
SetTheResultTo "TheResult"
get "TheIt"
TestAssert "return in function leaves it, sets the result to return value and returns the return value", \
DoReturnInFunction("NewResult") is "NewResult" and \
the result is "NewResult" and \
it is "TheIt"
end TestReturn
-------- Test behavior of the return for value statement
private command DoReturnValueInCommand pValue
return pValue for value
end DoReturnValueInCommand
private function DoReturnValueInFunction pValue
return pValue for value
end DoReturnValueInFunction
on TestReturnValue
SetTheResultTo "TheResult"
get "TheIt"
DoReturnValueInCommand "NewIt"
TestAssert "return value in command sets it and clears the result", \
the result is empty and \
it is "NewIt"
SetTheResultTo "TheResult"
get "TheIt"
TestAssert "return value in function leaves it, clears the result and returns the return value", \
DoReturnValueInFunction("ReturnValue") is "ReturnValue" and \
the result is empty and \
it is "TheIt"
end TestReturnValue
-------- Test behavior of the return for error statement
private command DoReturnErrorInCommand pValue
return pValue for error
end DoReturnErrorInCommand
private function DoReturnErrorInFunction pValue
return pValue for error
end DoReturnErrorInFunction
on TestReturnError
SetTheResultTo "TheResult"
get "TheIt"
DoReturnErrorInCommand "NewResult"
TestAssert "return error in command clears it and sets the result", \
the result is "NewResult" and \
it is empty
SetTheResultTo "TheResult"
get "TheIt"
TestAssert "return error in function leaves it, sets the result to the return value and returns empty", \
DoReturnErrorInFunction("ReturnValue") is empty and \
the result is "ReturnValue" and \
it is "TheIt"
end TestReturnError
-------- Test that nested uses of 'return for' don't affect the return action
-------- of a caller.
private command DoReturnInNestedCommand pValue
DoReturnInCommand pValue
end DoReturnInNestedCommand
private command DoReturnValueInNestedCommand pValue
DoReturnValueInCommand pValue
end DoReturnValueInNestedCommand
private command DoReturnErrorInNestedCommand pValue
DoReturnErrorInCommand pValue
end DoReturnErrorInNestedCommand
private function DoReturnInNestedFunction pValue
get DoReturnInFunction(pValue)
end DoReturnInNestedFunction
private function DoReturnValueInNestedFunction pValue
get DoReturnValueInFunction(pValue)
end DoReturnValueInNestedFunction
private function DoReturnErrorInNestedFunction pValue
get DoReturnErrorInFunction(pValue)
end DoReturnErrorInNestedFunction
-- This checks that the absence of a return clause is not affected by any
-- return clause present in a handler called by the handler with no return
-- clause.
on TestReturnNested
SetTheResultTo "TheResult"
get "TheIt"
DoReturnInNestedCommand "NewResult"
TestAssert "return handler called in no-return handler leaves it and sets the result", \
the result is "NewResult" and \
it is "TheIt"
SetTheResultTo "TheResult"
get "TheIt"
DoReturnValueInNestedCommand "NewResult"
TestAssert "return value handler called in no-return handler leaves it and sets the result to empty", \
the result is empty and \
it is "TheIt"
SetTheResultTo "TheResult"
get "TheIt"
DoReturnErrorInNestedCommand "NewResult"
TestAssert "return error handler called in no-return handler leaves it and sets the result", \
the result is "NewResult" and \
it is "TheIt"
SetTheResultTo "TheResult"
get "TheIt"
TestAssert "return function called in no-return function leaves it, sets the result to the return value and returns the return value", \
DoReturnInNestedFunction("ReturnValue") is "ReturnValue" and \
the result is "ReturnValue" and \
it is "TheIt"
SetTheResultTo "TheResult"
get "TheIt"
TestAssert "return value function called in no-return function leaves it, sets the result to the return value and returns the return value", \
DoReturnValueInNestedFunction("ReturnValue") is empty and \
the result is empty and \
it is "TheIt"
SetTheResultTo "TheResult"
get "TheIt"
TestAssert "return error function called in no-return function leaves it, sets the result to the return value and returns the return value", \
DoReturnErrorInNestedFunction("ReturnValue") is "ReturnValue" and \
the result is "ReturnValue" and \
it is "TheIt"
end TestReturnNested
on TestMessageMessagesResultMode
local tPath
put format("%s/../_trace.livecodescript", the filename of me) into tPath
start using stack tPath
set the traceReturn to true
set the traceStack to the long id of me
DoReturnValueInCommand "foobar"
local tIt, tResult
put it into tIt
put the result into tResult
TestDiagnostic "it" && tIt
TestDiagnostic "result" && tResult
TestAssert "result mode is not clobbered in messageHandled", tIt is "foobar"
set the traceStack to empty
stop using stack tPath
end TestMessageMessagesResultMode