rooibos-roku 4.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/lib/framework/BaseTestReporter.bs +27 -0
- package/dist/lib/framework/BaseTestSuite.bs +2131 -0
- package/dist/lib/framework/CommonUtils.bs +732 -0
- package/dist/lib/framework/ConsoleTestReporter.bs +200 -0
- package/dist/lib/framework/Coverage.bs +51 -0
- package/dist/lib/framework/Matchers.bs +28 -0
- package/dist/lib/framework/Rooibos.bs +83 -0
- package/dist/lib/framework/RooibosScene.xml +50 -0
- package/dist/lib/framework/RuntimeConfig.bs +20 -0
- package/dist/lib/framework/Stats.bs +46 -0
- package/dist/lib/framework/Test.bs +109 -0
- package/dist/lib/framework/TestGroup.bs +109 -0
- package/dist/lib/framework/TestResult.bs +74 -0
- package/dist/lib/framework/TestRunner.bs +187 -0
- package/dist/lib/framework/Utils.bs +63 -0
- package/dist/lib/framework/unused/CodeCoverage.brs +35 -0
- package/dist/lib/framework/unused/CodeCoverage.xml +13 -0
- package/dist/lib/framework/unused/CodeCoverageSupport.brs +56 -0
- package/dist/lib/rooibos/Annotation.js +187 -0
- package/dist/lib/rooibos/Annotation.js.map +1 -0
- package/dist/lib/rooibos/CodeCoverageProcessor.js +114 -0
- package/dist/lib/rooibos/CodeCoverageProcessor.js.map +1 -0
- package/dist/lib/rooibos/CodeCoverageProcessor.spec.js +62 -0
- package/dist/lib/rooibos/CodeCoverageProcessor.spec.js.map +1 -0
- package/dist/lib/rooibos/CodeCoverageType.js +11 -0
- package/dist/lib/rooibos/CodeCoverageType.js.map +1 -0
- package/dist/lib/rooibos/FileFactory.js +92 -0
- package/dist/lib/rooibos/FileFactory.js.map +1 -0
- package/dist/lib/rooibos/RawCodeStatement.js +21 -0
- package/dist/lib/rooibos/RawCodeStatement.js.map +1 -0
- package/dist/lib/rooibos/RooibosConfig.js +11 -0
- package/dist/lib/rooibos/RooibosConfig.js.map +1 -0
- package/dist/lib/rooibos/RooibosSession.js +151 -0
- package/dist/lib/rooibos/RooibosSession.js.map +1 -0
- package/dist/lib/rooibos/RooibosSessionInfo.js +181 -0
- package/dist/lib/rooibos/RooibosSessionInfo.js.map +1 -0
- package/dist/lib/rooibos/TestCase.js +65 -0
- package/dist/lib/rooibos/TestCase.js.map +1 -0
- package/dist/lib/rooibos/TestGroup.js +86 -0
- package/dist/lib/rooibos/TestGroup.js.map +1 -0
- package/dist/lib/rooibos/TestSuite.js +118 -0
- package/dist/lib/rooibos/TestSuite.js.map +1 -0
- package/dist/lib/rooibos/TestSuiteBuilder.js +192 -0
- package/dist/lib/rooibos/TestSuiteBuilder.js.map +1 -0
- package/dist/lib/rooibos/TestSuiteBuilder.spec.js +1126 -0
- package/dist/lib/rooibos/TestSuiteBuilder.spec.js.map +1 -0
- package/dist/lib/rooibos/Utils.js +173 -0
- package/dist/lib/rooibos/Utils.js.map +1 -0
- package/dist/lib/utils/Diagnostics.js +116 -0
- package/dist/lib/utils/Diagnostics.js.map +1 -0
- package/dist/lib/utils/testHelpers.spec.js +24 -0
- package/dist/lib/utils/testHelpers.spec.js.map +1 -0
- package/dist/plugin.js +116 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +110 -0
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
namespace rooibos.Common
|
|
2
|
+
' /**
|
|
3
|
+
' * @module CommonUtils
|
|
4
|
+
' */
|
|
5
|
+
' /******************
|
|
6
|
+
' Common utility functions
|
|
7
|
+
' /******************
|
|
8
|
+
|
|
9
|
+
' /**
|
|
10
|
+
' * @name IsXmlElement
|
|
11
|
+
' * @function
|
|
12
|
+
' * @description check if value contains XMLElement interface
|
|
13
|
+
' * @memberof module:CommonUtils
|
|
14
|
+
' * @param {Dynamic} value - value to check
|
|
15
|
+
' * @returns {Boolean} - true if value contains XMLElement interface, else return false
|
|
16
|
+
' */
|
|
17
|
+
function isXmlElement(value) as boolean
|
|
18
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifXMLElement") <> invalid
|
|
19
|
+
end function
|
|
20
|
+
|
|
21
|
+
' /**
|
|
22
|
+
' * @name IsFunction
|
|
23
|
+
' * @function
|
|
24
|
+
' * @description check if value contains Function interface
|
|
25
|
+
' * @memberof module:CommonUtils
|
|
26
|
+
' * @param {Dynamic} value - value to check
|
|
27
|
+
' * @returns {Boolean} - true if value contains Function interface, else return false
|
|
28
|
+
' */
|
|
29
|
+
function isFunction(value) as boolean
|
|
30
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifFunction") <> invalid
|
|
31
|
+
end function
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
' /**
|
|
35
|
+
' * @name Rooibos.Common.getFunction
|
|
36
|
+
' * @function
|
|
37
|
+
' * @description looks up the function by name, for the function map
|
|
38
|
+
' * @memberof module:CommonUtils
|
|
39
|
+
' * @param {filename} string - name of the file where the function was found
|
|
40
|
+
' * @param {String} functionName - name of the function to locate
|
|
41
|
+
' * @returns {Function} - function pointer or invalid
|
|
42
|
+
' */
|
|
43
|
+
function getFunction(filename, functionName) as object
|
|
44
|
+
if not Rooibos.Common.isNotEmptyString(functionName) then return invalid
|
|
45
|
+
if not Rooibos.Common.isNotEmptyString(filename) then return invalid
|
|
46
|
+
'bs:disable-next-line
|
|
47
|
+
mapFunction = RBSFM_getFunctionsForFile(filename)
|
|
48
|
+
if mapFunction <> invalid
|
|
49
|
+
map = mapFunction()
|
|
50
|
+
if type(map) = "roAssociativeArray"
|
|
51
|
+
functionPointer = map[functionName]
|
|
52
|
+
return functionPointer
|
|
53
|
+
else
|
|
54
|
+
return invalid
|
|
55
|
+
end if
|
|
56
|
+
end if
|
|
57
|
+
return invalid
|
|
58
|
+
|
|
59
|
+
end function
|
|
60
|
+
|
|
61
|
+
' /**
|
|
62
|
+
' * @name Rooibos.Common.getFunctionBruteforce
|
|
63
|
+
' * @function
|
|
64
|
+
' * @description looks up the function by name, from any function map
|
|
65
|
+
' * in future
|
|
66
|
+
' * @memberof module:CommonUtils
|
|
67
|
+
' * @param {filename} string - name of the file where the function was found
|
|
68
|
+
' * @param {String} functionName - name of the function to locate
|
|
69
|
+
' * @returns {Function} - function pointer or invalid
|
|
70
|
+
' */
|
|
71
|
+
function getFunctionBruteForce(functionName) as object
|
|
72
|
+
if not Rooibos.Common.isNotEmptyString(functionName) then return invalid
|
|
73
|
+
'bs:disable-next-line
|
|
74
|
+
filenames = RBSFM_getFilenames()
|
|
75
|
+
for i = 0 to filenames.count() - 1
|
|
76
|
+
filename = filenames[i]
|
|
77
|
+
'bs:disable-next-line
|
|
78
|
+
mapFunction = RBSFM_getFunctionsForFile(filename)
|
|
79
|
+
if mapFunction <> invalid
|
|
80
|
+
map = mapFunction()
|
|
81
|
+
if type(map) = "roAssociativeArray"
|
|
82
|
+
functionPointer = map[functionName]
|
|
83
|
+
if functionPointer <> invalid
|
|
84
|
+
return functionPointer
|
|
85
|
+
end if
|
|
86
|
+
end if
|
|
87
|
+
end if
|
|
88
|
+
end for
|
|
89
|
+
return invalid
|
|
90
|
+
|
|
91
|
+
end function
|
|
92
|
+
|
|
93
|
+
' /**
|
|
94
|
+
' * @name IsBoolean
|
|
95
|
+
' * @function
|
|
96
|
+
' * @description check if value contains Boolean interface
|
|
97
|
+
' * @memberof module:CommonUtils
|
|
98
|
+
' * @param {Dynamic} value - value to check
|
|
99
|
+
' * @returns {Boolean} - true if value contains Boolean interface, else return false
|
|
100
|
+
' */
|
|
101
|
+
function isBoolean(value) as boolean
|
|
102
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifBoolean") <> invalid
|
|
103
|
+
end function
|
|
104
|
+
|
|
105
|
+
' /**
|
|
106
|
+
' * @name IsInteger
|
|
107
|
+
' * @function
|
|
108
|
+
' * @description check if value type equals Integer
|
|
109
|
+
' * @memberof module:CommonUtils
|
|
110
|
+
' * @param {Dynamic} value - value to check
|
|
111
|
+
' * @returns {Boolean} - true if value type equals Integer, else return false
|
|
112
|
+
' */
|
|
113
|
+
function isInteger(value) as boolean
|
|
114
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifInt") <> invalid and (Type(value) = "roInt" or Type(value) = "roInteger" or Type(value) = "Integer")
|
|
115
|
+
end function
|
|
116
|
+
|
|
117
|
+
' /**
|
|
118
|
+
' * @name IsFloat
|
|
119
|
+
' * @function
|
|
120
|
+
' * @description check if value contains Float interface
|
|
121
|
+
' * @memberof module:CommonUtils
|
|
122
|
+
' * @param {Dynamic} value - value to check
|
|
123
|
+
' * @returns {Boolean} - true if value contains Float interface, else return false
|
|
124
|
+
' */
|
|
125
|
+
function isFloat(value) as boolean
|
|
126
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifFloat") <> invalid
|
|
127
|
+
end function
|
|
128
|
+
|
|
129
|
+
' /**
|
|
130
|
+
' * @name IsDouble
|
|
131
|
+
' * @function
|
|
132
|
+
' * @description check if value contains Double interface
|
|
133
|
+
' * @memberof module:CommonUtils
|
|
134
|
+
' * @param {Dynamic} value - value to check
|
|
135
|
+
' * @returns {Boolean} - true if value contains Double interface, else return false
|
|
136
|
+
' */
|
|
137
|
+
function isDouble(value) as boolean
|
|
138
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifDouble") <> invalid
|
|
139
|
+
end function
|
|
140
|
+
|
|
141
|
+
' /**
|
|
142
|
+
' * @name IsLongInteger
|
|
143
|
+
' * @function
|
|
144
|
+
' * @description check if value contains LongInteger interface
|
|
145
|
+
' * @memberof module:CommonUtils
|
|
146
|
+
' * @param {Dynamic} value - value to check
|
|
147
|
+
' * @returns {Boolean} - true if value contains LongInteger interface, else return false
|
|
148
|
+
' */
|
|
149
|
+
function isLongInteger(value) as boolean
|
|
150
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifLongInt") <> invalid
|
|
151
|
+
end function
|
|
152
|
+
|
|
153
|
+
' /**
|
|
154
|
+
' * @name IsNumber
|
|
155
|
+
' * @function
|
|
156
|
+
' * @description check if value contains LongInteger or Integer or Double or Float interface
|
|
157
|
+
' * @memberof module:CommonUtils
|
|
158
|
+
' * @param {Dynamic} value - value to check
|
|
159
|
+
' * @returns {Boolean} - true if value is number, else return false
|
|
160
|
+
' */
|
|
161
|
+
function isNumber(value) as boolean
|
|
162
|
+
return Rooibos.Common.isLongInteger(value) or Rooibos.Common.isDouble(value) or Rooibos.Common.isInteger(value) or Rooibos.Common.isFloat(value)
|
|
163
|
+
end function
|
|
164
|
+
|
|
165
|
+
' /**
|
|
166
|
+
' * @name IsList
|
|
167
|
+
' * @function
|
|
168
|
+
' * @description check if value contains List interface
|
|
169
|
+
' * @memberof module:CommonUtils
|
|
170
|
+
' * @param {Dynamic} value - value to check
|
|
171
|
+
' * @returns {Boolean} - true if value contains List interface, else return false
|
|
172
|
+
' */
|
|
173
|
+
function isList(value) as boolean
|
|
174
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifList") <> invalid
|
|
175
|
+
end function
|
|
176
|
+
|
|
177
|
+
' /**
|
|
178
|
+
' * @name IsArray
|
|
179
|
+
' * @function
|
|
180
|
+
' * @description check if value contains Array interface
|
|
181
|
+
' * @memberof module:CommonUtils
|
|
182
|
+
' * @param {Dynamic} value - value to check
|
|
183
|
+
' * @returns {Boolean} - true if value contains Array interface, else return false
|
|
184
|
+
' */
|
|
185
|
+
function isArray(value) as boolean
|
|
186
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifArray") <> invalid
|
|
187
|
+
end function
|
|
188
|
+
|
|
189
|
+
' /**
|
|
190
|
+
' * @name IsAssociativeArray
|
|
191
|
+
' * @function
|
|
192
|
+
' * @description check if value contains AssociativeArray interface
|
|
193
|
+
' * @memberof module:CommonUtils
|
|
194
|
+
' * @param {Dynamic} value - value to check
|
|
195
|
+
' * @returns {Boolean} - true if value contains AssociativeArray interface, else return false
|
|
196
|
+
' */
|
|
197
|
+
function isAssociativeArray(value) as boolean
|
|
198
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifAssociativeArray") <> invalid
|
|
199
|
+
end function
|
|
200
|
+
|
|
201
|
+
' /**
|
|
202
|
+
' * @name IsSGNode
|
|
203
|
+
' * @function
|
|
204
|
+
' * @description check if value contains SGNodeChildren interface
|
|
205
|
+
' * @memberof module:CommonUtils
|
|
206
|
+
' * @param {Dynamic} value - value to check
|
|
207
|
+
' * @returns {Boolean} - true if value contains SGNodeChildren interface, else return false
|
|
208
|
+
' */
|
|
209
|
+
function isSGNode(value) as boolean
|
|
210
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifSGNodeChildren") <> invalid
|
|
211
|
+
end function
|
|
212
|
+
|
|
213
|
+
' /**
|
|
214
|
+
' * @name IsString
|
|
215
|
+
' * @function
|
|
216
|
+
' * @description check if value contains String interface
|
|
217
|
+
' * @memberof module:CommonUtils
|
|
218
|
+
' * @param {Dynamic} value - value to check
|
|
219
|
+
' * @returns {Boolean} - true if value contains String interface, else return false
|
|
220
|
+
' */
|
|
221
|
+
function isString(value) as boolean
|
|
222
|
+
return Rooibos.Common.isValid(value) and GetInterface(value, "ifString") <> invalid
|
|
223
|
+
end function
|
|
224
|
+
|
|
225
|
+
' /**
|
|
226
|
+
' * @name IsNotEmptyString
|
|
227
|
+
' * @function
|
|
228
|
+
' * @description check if value contains String interface and length more 0
|
|
229
|
+
' * @memberof module:CommonUtils
|
|
230
|
+
' * @param {Dynamic} value - value to check
|
|
231
|
+
' * @returns {Boolean} - true if value contains String interface and length more 0, else return false
|
|
232
|
+
' */
|
|
233
|
+
function isNotEmptyString(value) as boolean
|
|
234
|
+
return Rooibos.Common.isString(value) and len(value) > 0
|
|
235
|
+
end function
|
|
236
|
+
|
|
237
|
+
' /**
|
|
238
|
+
' * @name IsDateTime
|
|
239
|
+
' * @function
|
|
240
|
+
' * @description check if value contains DateTime interface
|
|
241
|
+
' * @memberof module:CommonUtils
|
|
242
|
+
' * @param {Dynamic} value - value to check
|
|
243
|
+
' * @returns {Boolean} - true if value contains DateTime interface, else return false
|
|
244
|
+
' */
|
|
245
|
+
function isDateTime(value) as boolean
|
|
246
|
+
return Rooibos.Common.isValid(value) and (GetInterface(value, "ifDateTime") <> invalid or Type(value) = "roDateTime")
|
|
247
|
+
end function
|
|
248
|
+
|
|
249
|
+
' /**
|
|
250
|
+
' * @name IsValid
|
|
251
|
+
' * @function
|
|
252
|
+
' * @description check if value initialized and not equal invalid
|
|
253
|
+
' * @memberof module:CommonUtils
|
|
254
|
+
' * @param {Dynamic} value - value to check
|
|
255
|
+
' * @returns {Boolean} - true if value initialized and not equal invalid, else return false
|
|
256
|
+
' */
|
|
257
|
+
function isValid(value) as boolean
|
|
258
|
+
return not Rooibos.Common.isUndefined(value) and value <> invalid
|
|
259
|
+
end function
|
|
260
|
+
|
|
261
|
+
function isUndefined(value) as boolean
|
|
262
|
+
return type(value) = "" or Type(value) = "<uninitialized>"
|
|
263
|
+
end function
|
|
264
|
+
|
|
265
|
+
' /**
|
|
266
|
+
' * @name ValidStr
|
|
267
|
+
' * @function
|
|
268
|
+
' * @description return value if his contains String interface else return empty string
|
|
269
|
+
' * @memberof module:CommonUtils
|
|
270
|
+
' * @param {Dynamic} value - value to check
|
|
271
|
+
' * @returns {String} - value if his contains String interface else return empty string
|
|
272
|
+
' */
|
|
273
|
+
function validStr(obj) as string
|
|
274
|
+
if obj <> invalid and GetInterface(obj, "ifString") <> invalid
|
|
275
|
+
return obj
|
|
276
|
+
else
|
|
277
|
+
return ""
|
|
278
|
+
end if
|
|
279
|
+
end function
|
|
280
|
+
|
|
281
|
+
' /**
|
|
282
|
+
' * @name AsString
|
|
283
|
+
' * @function
|
|
284
|
+
' * @description convert input to String if this possible, else return empty string
|
|
285
|
+
' * @memberof module:CommonUtils
|
|
286
|
+
' * @param {Dynamic} input - value to check
|
|
287
|
+
' * @returns {String} - converted string
|
|
288
|
+
' */
|
|
289
|
+
function asString(input) as string
|
|
290
|
+
if Rooibos.Common.isValid(input) = false
|
|
291
|
+
return "Invalid"
|
|
292
|
+
else if Rooibos.Common.isString(input)
|
|
293
|
+
return input
|
|
294
|
+
else if Rooibos.Common.isInteger(input) or Rooibos.Common.isLongInteger(input) or Rooibos.Common.isBoolean(input)
|
|
295
|
+
return input.ToStr()
|
|
296
|
+
else if Rooibos.Common.isFloat(input) or Rooibos.Common.isDouble(input)
|
|
297
|
+
return Str(input).Trim()
|
|
298
|
+
else if type(input) = "roSGNode"
|
|
299
|
+
return "Node(" + input.subType() + ")"
|
|
300
|
+
else if type(input) = "roAssociativeArray"
|
|
301
|
+
isFirst = true
|
|
302
|
+
text = "{"
|
|
303
|
+
if not isFirst
|
|
304
|
+
text = text + ","
|
|
305
|
+
isFirst = false
|
|
306
|
+
end if
|
|
307
|
+
for each key in input
|
|
308
|
+
if rooibos.Common.canSafelyIterateAAKey(input, key)
|
|
309
|
+
text = text + key + ":" + Rooibos.Common.asString(input[key])
|
|
310
|
+
end if
|
|
311
|
+
end for
|
|
312
|
+
text = text + "}"
|
|
313
|
+
return text
|
|
314
|
+
else if Rooibos.Common.isArray(input)
|
|
315
|
+
text = "["
|
|
316
|
+
join = ""
|
|
317
|
+
maxLen = 500
|
|
318
|
+
for each v in input
|
|
319
|
+
if len(text) < maxLen
|
|
320
|
+
text += join + rooibos.Common.asString(v)
|
|
321
|
+
join = ", "
|
|
322
|
+
end if
|
|
323
|
+
end for
|
|
324
|
+
if len(text) > maxLen
|
|
325
|
+
text = left(text, maxLen - 3) + "..."
|
|
326
|
+
end if
|
|
327
|
+
text = text + "]"
|
|
328
|
+
return text
|
|
329
|
+
else if Rooibos.Common.isFunction(input)
|
|
330
|
+
return input.toStr()
|
|
331
|
+
else
|
|
332
|
+
return ""
|
|
333
|
+
end if
|
|
334
|
+
end function
|
|
335
|
+
|
|
336
|
+
' /**
|
|
337
|
+
' * @name AsInteger
|
|
338
|
+
' * @function
|
|
339
|
+
' * @description convert input to Integer if this possible, else return 0
|
|
340
|
+
' * @memberof module:CommonUtils
|
|
341
|
+
' * @param {Dynamic} input - value to check
|
|
342
|
+
' * @returns {Integer} - converted Integer
|
|
343
|
+
' */
|
|
344
|
+
function asInteger(input) as integer
|
|
345
|
+
if Rooibos.Common.isValid(input) = false
|
|
346
|
+
return 0
|
|
347
|
+
else if Rooibos.Common.isString(input)
|
|
348
|
+
return input.ToInt()
|
|
349
|
+
else if Rooibos.Common.isInteger(input)
|
|
350
|
+
return input
|
|
351
|
+
else if Rooibos.Common.isFloat(input) or Rooibos.Common.isDouble(input) or Rooibos.Common.isLongInteger(input)
|
|
352
|
+
return Int(input)
|
|
353
|
+
else
|
|
354
|
+
return 0
|
|
355
|
+
end if
|
|
356
|
+
end function
|
|
357
|
+
|
|
358
|
+
' /**
|
|
359
|
+
' * @name AsLongInteger
|
|
360
|
+
' * @function
|
|
361
|
+
' * @description convert input to LongInteger if this possible, else return 0
|
|
362
|
+
' * @memberof module:CommonUtils
|
|
363
|
+
' * @param {Dynamic} input - value to check
|
|
364
|
+
' * @returns {Integer} - converted LongInteger
|
|
365
|
+
' */
|
|
366
|
+
function asLongInteger(input) as longinteger
|
|
367
|
+
if Rooibos.Common.isValid(input) = false
|
|
368
|
+
return 0
|
|
369
|
+
else if Rooibos.Common.isString(input)
|
|
370
|
+
return Rooibos.Common.asInteger(input)
|
|
371
|
+
else if Rooibos.Common.isLongInteger(input) or Rooibos.Common.isFloat(input) or Rooibos.Common.isDouble(input) or Rooibos.Common.isInteger(input)
|
|
372
|
+
return input
|
|
373
|
+
else
|
|
374
|
+
return 0
|
|
375
|
+
end if
|
|
376
|
+
end function
|
|
377
|
+
|
|
378
|
+
' /**
|
|
379
|
+
' * @name AsFloat
|
|
380
|
+
' * @function
|
|
381
|
+
' * @description convert input to Float if this possible, else return 0.0
|
|
382
|
+
' * @memberof module:CommonUtils
|
|
383
|
+
' * @param {Dynamic} input - value to check
|
|
384
|
+
' * @returns {Float} - converted Float
|
|
385
|
+
' */
|
|
386
|
+
function asFloat(input) as float
|
|
387
|
+
if Rooibos.Common.isValid(input) = false
|
|
388
|
+
return 0.0
|
|
389
|
+
else if Rooibos.Common.isString(input)
|
|
390
|
+
return input.ToFloat()
|
|
391
|
+
else if Rooibos.Common.isInteger(input)
|
|
392
|
+
return (input / 1)
|
|
393
|
+
else if Rooibos.Common.isFloat(input) or Rooibos.Common.isDouble(input) or Rooibos.Common.isLongInteger(input)
|
|
394
|
+
return input
|
|
395
|
+
else
|
|
396
|
+
return 0.0
|
|
397
|
+
end if
|
|
398
|
+
end function
|
|
399
|
+
|
|
400
|
+
' /**
|
|
401
|
+
' * @name AsDouble
|
|
402
|
+
' * @function
|
|
403
|
+
' * @description convert input to Double if this possible, else return 0.0
|
|
404
|
+
' * @memberof module:CommonUtils
|
|
405
|
+
' * @param {Dynamic} input - value to check
|
|
406
|
+
' * @returns {Float} - converted Double
|
|
407
|
+
' */
|
|
408
|
+
function asDouble(input) as double
|
|
409
|
+
if Rooibos.Common.isValid(input) = false
|
|
410
|
+
return 0.0
|
|
411
|
+
else if Rooibos.Common.isString(input)
|
|
412
|
+
return Rooibos.Common.asFloat(input)
|
|
413
|
+
else if Rooibos.Common.isInteger(input) or Rooibos.Common.isLongInteger(input) or Rooibos.Common.isFloat(input) or Rooibos.Common.isDouble(input)
|
|
414
|
+
return input
|
|
415
|
+
else
|
|
416
|
+
return 0.0
|
|
417
|
+
end if
|
|
418
|
+
end function
|
|
419
|
+
|
|
420
|
+
' /**
|
|
421
|
+
' * @name AsBoolean
|
|
422
|
+
' * @function
|
|
423
|
+
' * @description convert input to Boolean if this possible, else return False
|
|
424
|
+
' * @memberof module:CommonUtils
|
|
425
|
+
' * @param {Dynamic} input - value to check
|
|
426
|
+
' * @returns {Boolean} - converted boolean
|
|
427
|
+
' */
|
|
428
|
+
function asBoolean(input) as boolean
|
|
429
|
+
if Rooibos.Common.isValid(input) = false
|
|
430
|
+
return false
|
|
431
|
+
else if Rooibos.Common.isString(input)
|
|
432
|
+
return LCase(input) = "true"
|
|
433
|
+
else if Rooibos.Common.isInteger(input) or Rooibos.Common.isFloat(input)
|
|
434
|
+
return input <> 0
|
|
435
|
+
else if Rooibos.Common.isBoolean(input)
|
|
436
|
+
return input
|
|
437
|
+
else
|
|
438
|
+
return false
|
|
439
|
+
end if
|
|
440
|
+
end function
|
|
441
|
+
|
|
442
|
+
' /**
|
|
443
|
+
' * @name AsArray
|
|
444
|
+
' * @function
|
|
445
|
+
' * @description if type of value equals array return value, else return array with one element [value]
|
|
446
|
+
' * @memberof module:CommonUtils
|
|
447
|
+
' * @param {Dynamic} value - value to check
|
|
448
|
+
' * @returns {Array} - converted array
|
|
449
|
+
' */
|
|
450
|
+
function asArray(value) as object
|
|
451
|
+
if Rooibos.Common.isValid(value)
|
|
452
|
+
if not Rooibos.Common.isArray(value)
|
|
453
|
+
return [value]
|
|
454
|
+
else
|
|
455
|
+
return value
|
|
456
|
+
end if
|
|
457
|
+
end if
|
|
458
|
+
return []
|
|
459
|
+
end function
|
|
460
|
+
|
|
461
|
+
'=====================
|
|
462
|
+
' Strings
|
|
463
|
+
'=====================
|
|
464
|
+
|
|
465
|
+
' /**
|
|
466
|
+
' * @name IsNullOrEmpty
|
|
467
|
+
' * @function
|
|
468
|
+
' * @description check if value is invalid or empty
|
|
469
|
+
' * @memberof module:CommonUtils
|
|
470
|
+
' * @param {Dynamic} value - value to check
|
|
471
|
+
' * @returns {Boolean} - true if value is null or empty string, else return false
|
|
472
|
+
' */
|
|
473
|
+
function isNullOrEmpty(value) as boolean
|
|
474
|
+
if Rooibos.Common.isString(value)
|
|
475
|
+
return Len(value) = 0
|
|
476
|
+
else
|
|
477
|
+
return not Rooibos.Common.isValid(value)
|
|
478
|
+
end if
|
|
479
|
+
end function
|
|
480
|
+
|
|
481
|
+
'=====================
|
|
482
|
+
' Arrays
|
|
483
|
+
'=====================
|
|
484
|
+
|
|
485
|
+
' /**
|
|
486
|
+
' * @name FindElementIndexInArray
|
|
487
|
+
' * @function
|
|
488
|
+
' * @description find an element index in array
|
|
489
|
+
' * @memberof module:CommonUtils
|
|
490
|
+
' * @param {Dynamic} array - array to search
|
|
491
|
+
' * @param {Dynamic} value - value to check
|
|
492
|
+
' * @param {Dynamic} compareAttribute - attribue to use for comparisons
|
|
493
|
+
' * @param {Boolean} caseSensitive - indicates if comparisons are case sensitive
|
|
494
|
+
' * @returns {Integer} - element index if array contains a value, else return -1
|
|
495
|
+
' */
|
|
496
|
+
function findElementIndexInArray(array, value, compareAttribute = invalid, caseSensitive = false) as integer
|
|
497
|
+
if Rooibos.Common.isArray(array)
|
|
498
|
+
for i = 0 to Rooibos.Common.asArray(array).Count() - 1
|
|
499
|
+
compareValue = array[i]
|
|
500
|
+
|
|
501
|
+
if compareAttribute <> invalid and Rooibos.Common.isAssociativeArray(compareValue)
|
|
502
|
+
compareValue = compareValue.lookupCI(compareAttribute)
|
|
503
|
+
end if
|
|
504
|
+
|
|
505
|
+
if Rooibos.Common.eqValues(compareValue, value)
|
|
506
|
+
return i
|
|
507
|
+
end if
|
|
508
|
+
|
|
509
|
+
item = array[i]
|
|
510
|
+
next
|
|
511
|
+
end if
|
|
512
|
+
return -1
|
|
513
|
+
end function
|
|
514
|
+
|
|
515
|
+
' /**
|
|
516
|
+
' * @name ArrayContains
|
|
517
|
+
' * @function
|
|
518
|
+
' * @description check if array contains specified value
|
|
519
|
+
' * @memberof module:CommonUtils
|
|
520
|
+
' * @param {Dynamic} array - array to search in
|
|
521
|
+
' * @param {Dynamic} value - value to check
|
|
522
|
+
' * @param {Dynamic} compareAttribute - attribute to compare on
|
|
523
|
+
' * @returns {Boolean} - true if array contains a value, else return false
|
|
524
|
+
' */
|
|
525
|
+
function arrayContains(array, value, compareAttribute = invalid) as boolean
|
|
526
|
+
return (Rooibos.Common.findElementIndexInArray(array, value, compareAttribute) > -1)
|
|
527
|
+
end function
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
'=====================
|
|
531
|
+
' NODES
|
|
532
|
+
'=====================
|
|
533
|
+
|
|
534
|
+
' /**
|
|
535
|
+
' * @name FindElementIndexInNode
|
|
536
|
+
' * @function
|
|
537
|
+
' * @description find an element index in node
|
|
538
|
+
' * @memberof module:CommonUtils
|
|
539
|
+
' * @param {Dynamic} node - node to search in
|
|
540
|
+
' * @param {Dynamic} value - child to search for
|
|
541
|
+
' * @returns {Integer} - element index if node contains a value, else return -1
|
|
542
|
+
' */
|
|
543
|
+
function findElementIndexInNode(node, value) as integer
|
|
544
|
+
if type(node) = "roSGNode"
|
|
545
|
+
for i = 0 to node.getChildCount() - 1
|
|
546
|
+
compareValue = node.getChild(i)
|
|
547
|
+
if type(compareValue) = "roSGNode" and compareValue.isSameNode(value)
|
|
548
|
+
return i
|
|
549
|
+
end if
|
|
550
|
+
next
|
|
551
|
+
end if
|
|
552
|
+
return -1
|
|
553
|
+
end function
|
|
554
|
+
|
|
555
|
+
' /**
|
|
556
|
+
' * @name NodeContains
|
|
557
|
+
' * @description check if node contains specified child
|
|
558
|
+
' * @memberof module:CommonUtils
|
|
559
|
+
' * @param {Dynamic} node - the node to check on
|
|
560
|
+
' * @param {Dynamic} value - child to look for
|
|
561
|
+
' * @returns {Boolean} - true if node contains a value, else return false
|
|
562
|
+
' */
|
|
563
|
+
function nodeContains(node, value) as boolean
|
|
564
|
+
return (Rooibos.Common.findElementIndexInNode(node, value) > -1)
|
|
565
|
+
end function
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
' /**
|
|
569
|
+
' * @memberof module:CommonUtils
|
|
570
|
+
' * @name EqValues
|
|
571
|
+
' * @function
|
|
572
|
+
' * @instance
|
|
573
|
+
' * @description Compare two arbtrary values to eachother.
|
|
574
|
+
' * @param {Dynamic} Value1 - first item to compare
|
|
575
|
+
' * @param {Dynamic} Value2 - second item to compare
|
|
576
|
+
' * @returns {boolean} - True if values are equal or False in other case.
|
|
577
|
+
' */
|
|
578
|
+
function eqValues(Value1, Value2) as dynamic
|
|
579
|
+
' Workaraund for bug with string boxing, and box everything else
|
|
580
|
+
val1Type = type(Value1)
|
|
581
|
+
val2Type = type(Value2)
|
|
582
|
+
if val1Type = "<uninitialized>" or val2Type = "<uninitialized>" or val1Type = "" or val2Type = ""
|
|
583
|
+
? "ERROR!!!! - undefined value passed"
|
|
584
|
+
return false
|
|
585
|
+
end if
|
|
586
|
+
|
|
587
|
+
if val1Type = "roString" or val1Type = "String"
|
|
588
|
+
Value1 = Rooibos.Common.asString(Value1)
|
|
589
|
+
else
|
|
590
|
+
Value1 = box(Value1)
|
|
591
|
+
end if
|
|
592
|
+
|
|
593
|
+
if val2Type = "roString" or val2Type = "String"
|
|
594
|
+
Value2 = Rooibos.Common.asString(Value2)
|
|
595
|
+
else
|
|
596
|
+
Value2 = box(Value2)
|
|
597
|
+
end if
|
|
598
|
+
'update types after boxing
|
|
599
|
+
val1Type = type(Value1)
|
|
600
|
+
val2Type = type(Value2)
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
'Upcast int to float, if other is float
|
|
604
|
+
if val1Type = "roFloat" and val2Type = "roInt"
|
|
605
|
+
Value2 = box(Cdbl(Value2))
|
|
606
|
+
else if val2Type = "roFloat" and val1Type = "roInt"
|
|
607
|
+
Value1 = box(Cdbl(Value1))
|
|
608
|
+
end if
|
|
609
|
+
|
|
610
|
+
if val1Type <> val2Type
|
|
611
|
+
return false
|
|
612
|
+
else
|
|
613
|
+
valtype = val1Type
|
|
614
|
+
|
|
615
|
+
if valtype = "roList"
|
|
616
|
+
return Rooibos.Common.eqArray(Value1, Value2)
|
|
617
|
+
else if valtype = "roAssociativeArray"
|
|
618
|
+
return Rooibos.Common.eqAssocArray(Value1, Value2)
|
|
619
|
+
else if valtype = "roArray"
|
|
620
|
+
return Rooibos.Common.eqArray(Value1, Value2)
|
|
621
|
+
else if valtype = "roSGNode"
|
|
622
|
+
if val2Type <> "roSGNode"
|
|
623
|
+
return false
|
|
624
|
+
else
|
|
625
|
+
return Value1.isSameNode(Value2)
|
|
626
|
+
end if
|
|
627
|
+
else
|
|
628
|
+
'If you crashed on this line, then you're trying to compare
|
|
629
|
+
'2 things which can't be compared - check what value1 and value2
|
|
630
|
+
'are in your debug log
|
|
631
|
+
return Value1 = Value2
|
|
632
|
+
end if
|
|
633
|
+
end if
|
|
634
|
+
end function
|
|
635
|
+
|
|
636
|
+
' /**
|
|
637
|
+
' * @memberof module:CommonUtils
|
|
638
|
+
' * @name EqAssocArray
|
|
639
|
+
' * @function
|
|
640
|
+
' * @instance
|
|
641
|
+
' * @description Compare to roAssociativeArray objects for equality.
|
|
642
|
+
' * @param {Dynamic} Value1 - first associative array
|
|
643
|
+
' * @param {Dynamic} Value2 - second associative array
|
|
644
|
+
' * @returns {boolean} - True if arrays are equal or False in other case.
|
|
645
|
+
' */
|
|
646
|
+
function eqAssocArray(Value1, Value2) as dynamic
|
|
647
|
+
l1 = Value1.Count()
|
|
648
|
+
l2 = Value2.Count()
|
|
649
|
+
|
|
650
|
+
if not l1 = l2
|
|
651
|
+
return false
|
|
652
|
+
else
|
|
653
|
+
for each k in Value1
|
|
654
|
+
if not Value2.DoesExist(k)
|
|
655
|
+
return false
|
|
656
|
+
else
|
|
657
|
+
if rooibos.common.canSafelyIterateAAKey(Value1, k) and rooibos.common.canSafelyIterateAAKey(Value2, k)
|
|
658
|
+
v1 = Value1[k]
|
|
659
|
+
v2 = Value2[k]
|
|
660
|
+
if not Rooibos.Common.eqValues(v1, v2)
|
|
661
|
+
return false
|
|
662
|
+
end if
|
|
663
|
+
end if
|
|
664
|
+
end if
|
|
665
|
+
end for
|
|
666
|
+
return true
|
|
667
|
+
end if
|
|
668
|
+
end function
|
|
669
|
+
|
|
670
|
+
function canSafelyIterateAAKey(aa, key) as boolean
|
|
671
|
+
if lcase(key) = "__rooibosskipfields" or key = "__mocks" or key = "__stubs" 'fix infinite loop/box crash when doing equals on an aa with a mock
|
|
672
|
+
return false
|
|
673
|
+
else if aa.__rooibosSkipFields <> invalid and aa.__rooibosSkipFields.doesExist(key)
|
|
674
|
+
return false
|
|
675
|
+
end if
|
|
676
|
+
|
|
677
|
+
return true
|
|
678
|
+
end function
|
|
679
|
+
|
|
680
|
+
' /**
|
|
681
|
+
' * @memberof module:CommonUtils
|
|
682
|
+
' * @name EqArray
|
|
683
|
+
' * @function
|
|
684
|
+
' * @instance
|
|
685
|
+
' * @description Compare to roArray objects for equality.
|
|
686
|
+
' * @param {Dynamic} Value1 - first array
|
|
687
|
+
' * @param {Dynamic} Value2 - second array
|
|
688
|
+
' * @returns {boolean} - True if arrays are equal or False in other case.
|
|
689
|
+
' */
|
|
690
|
+
function eqArray(Value1, Value2) as dynamic
|
|
691
|
+
if not (Rooibos.Common.isArray(Value1)) or not Rooibos.Common.isArray(Value2) then return false
|
|
692
|
+
|
|
693
|
+
l1 = Value1.Count()
|
|
694
|
+
l2 = Value2.Count()
|
|
695
|
+
|
|
696
|
+
if not l1 = l2
|
|
697
|
+
return false
|
|
698
|
+
else
|
|
699
|
+
for i = 0 to l1 - 1
|
|
700
|
+
v1 = Value1[i]
|
|
701
|
+
v2 = Value2[i]
|
|
702
|
+
if not Rooibos.Common.eqValues(v1, v2) then
|
|
703
|
+
return false
|
|
704
|
+
end if
|
|
705
|
+
end for
|
|
706
|
+
return true
|
|
707
|
+
end if
|
|
708
|
+
end function
|
|
709
|
+
|
|
710
|
+
' /**
|
|
711
|
+
' * @member fillText
|
|
712
|
+
' * @memberof module:CommonUtils
|
|
713
|
+
' * @instance
|
|
714
|
+
' * @description Fills text with count of fillChars
|
|
715
|
+
' * @param {string} text - text to fill
|
|
716
|
+
' * @param {string} fillChar - char to fill with
|
|
717
|
+
' * @param {integer} numChars - target length
|
|
718
|
+
' * @returns {string} filled string
|
|
719
|
+
' */
|
|
720
|
+
function fillText(text as string, fillChar = " ", numChars = 40) as string
|
|
721
|
+
if len(text) >= numChars
|
|
722
|
+
text = left(text, numChars - 5) + "..." + fillChar + fillChar
|
|
723
|
+
else
|
|
724
|
+
numToFill = numChars - len(text) - 1
|
|
725
|
+
for i = 0 to numToFill
|
|
726
|
+
text = text + fillChar
|
|
727
|
+
end for
|
|
728
|
+
end if
|
|
729
|
+
return text
|
|
730
|
+
end function
|
|
731
|
+
|
|
732
|
+
end namespace
|