CommonUtils.brs

  1. ' /**
  2. ' * @module CommonUtils
  3. ' */
  4. ' /******************
  5. ' Common utility functions
  6. ' /******************
  7. ' /**
  8. ' * @name IsXmlElement
  9. ' * @function
  10. ' * @description check if value contains XMLElement interface
  11. ' * @memberof module:CommonUtils
  12. ' * @param {Dynamic} value - value to check
  13. ' * @returns {Boolean} - true if value contains XMLElement interface, else return false
  14. ' */
  15. function Rooibos_Common_isXmlElement(value) as boolean
  16. return Rooibos_Common_isValid(value) and GetInterface(value, "ifXMLElement") <> invalid
  17. end function
  18. ' /**
  19. ' * @name IsFunction
  20. ' * @function
  21. ' * @description check if value contains Function interface
  22. ' * @memberof module:CommonUtils
  23. ' * @param {Dynamic} value - value to check
  24. ' * @returns {Boolean} - true if value contains Function interface, else return false
  25. ' */
  26. function Rooibos_Common_isFunction(value) as boolean
  27. return Rooibos_Common_isValid(value) and GetInterface(value, "ifFunction") <> invalid
  28. end function
  29. ' /**
  30. ' * @name Rooibos.Common.getFunction
  31. ' * @function
  32. ' * @description looks up the function by name, for the function map
  33. ' * @memberof module:CommonUtils
  34. ' * @param {filename} string - name of the file where the function was found
  35. ' * @param {String} functionName - name of the function to locate
  36. ' * @returns {Function} - function pointer or invalid
  37. ' */
  38. function Rooibos_Common_getFunction(filename, functionName) as object
  39. if (not Rooibos_Common_isNotEmptyString(functionName)) then
  40. return invalid
  41. end if
  42. if (not Rooibos_Common_isNotEmptyString(filename)) then
  43. return invalid
  44. end if
  45. 'bs:disable-next-line
  46. mapFunction = RBSFM_getFunctionsForFile(filename)
  47. if mapFunction <> invalid then
  48. map = mapFunction()
  49. if (type(map) = "roAssociativeArray") then
  50. functionPointer = map[functionName]
  51. return functionPointer
  52. else
  53. return invalid
  54. end if
  55. end if
  56. return invalid
  57. end function
  58. ' /**
  59. ' * @name Rooibos.Common.getFunctionBruteforce
  60. ' * @function
  61. ' * @description looks up the function by name, from any function map
  62. ' * in future
  63. ' * @memberof module:CommonUtils
  64. ' * @param {filename} string - name of the file where the function was found
  65. ' * @param {String} functionName - name of the function to locate
  66. ' * @returns {Function} - function pointer or invalid
  67. ' */
  68. function Rooibos_Common_getFunctionBruteForce(functionName) as object
  69. if (not Rooibos_Common_isNotEmptyString(functionName)) then
  70. return invalid
  71. end if
  72. 'bs:disable-next-line
  73. filenames = RBSFM_getFilenames()
  74. for i = 0 to filenames.count() - 1
  75. filename = filenames[i]
  76. 'bs:disable-next-line
  77. mapFunction = RBSFM_getFunctionsForFile(filename)
  78. if mapFunction <> invalid then
  79. map = mapFunction()
  80. if (type(map) = "roAssociativeArray") then
  81. functionPointer = map[functionName]
  82. if functionPointer <> invalid then
  83. return functionPointer
  84. end if
  85. end if
  86. end if
  87. end for
  88. return invalid
  89. end function
  90. ' /**
  91. ' * @name IsBoolean
  92. ' * @function
  93. ' * @description check if value contains Boolean interface
  94. ' * @memberof module:CommonUtils
  95. ' * @param {Dynamic} value - value to check
  96. ' * @returns {Boolean} - true if value contains Boolean interface, else return false
  97. ' */
  98. function Rooibos_Common_isBoolean(value) as boolean
  99. return Rooibos_Common_isValid(value) and GetInterface(value, "ifBoolean") <> invalid
  100. end function
  101. ' /**
  102. ' * @name IsInteger
  103. ' * @function
  104. ' * @description check if value type equals Integer
  105. ' * @memberof module:CommonUtils
  106. ' * @param {Dynamic} value - value to check
  107. ' * @returns {Boolean} - true if value type equals Integer, else return false
  108. ' */
  109. function Rooibos_Common_isInteger(value) as boolean
  110. return Rooibos_Common_isValid(value) and GetInterface(value, "ifInt") <> invalid and (Type(value) = "roInt" or Type(value) = "roInteger" or Type(value) = "Integer")
  111. end function
  112. ' /**
  113. ' * @name IsFloat
  114. ' * @function
  115. ' * @description check if value contains Float interface
  116. ' * @memberof module:CommonUtils
  117. ' * @param {Dynamic} value - value to check
  118. ' * @returns {Boolean} - true if value contains Float interface, else return false
  119. ' */
  120. function Rooibos_Common_isFloat(value) as boolean
  121. return Rooibos_Common_isValid(value) and GetInterface(value, "ifFloat") <> invalid
  122. end function
  123. ' /**
  124. ' * @name IsDouble
  125. ' * @function
  126. ' * @description check if value contains Double interface
  127. ' * @memberof module:CommonUtils
  128. ' * @param {Dynamic} value - value to check
  129. ' * @returns {Boolean} - true if value contains Double interface, else return false
  130. ' */
  131. function Rooibos_Common_isDouble(value) as boolean
  132. return Rooibos_Common_isValid(value) and GetInterface(value, "ifDouble") <> invalid
  133. end function
  134. ' /**
  135. ' * @name IsLongInteger
  136. ' * @function
  137. ' * @description check if value contains LongInteger interface
  138. ' * @memberof module:CommonUtils
  139. ' * @param {Dynamic} value - value to check
  140. ' * @returns {Boolean} - true if value contains LongInteger interface, else return false
  141. ' */
  142. function Rooibos_Common_isLongInteger(value) as boolean
  143. return Rooibos_Common_isValid(value) and GetInterface(value, "ifLongInt") <> invalid
  144. end function
  145. ' /**
  146. ' * @name IsNumber
  147. ' * @function
  148. ' * @description check if value contains LongInteger or Integer or Double or Float interface
  149. ' * @memberof module:CommonUtils
  150. ' * @param {Dynamic} value - value to check
  151. ' * @returns {Boolean} - true if value is number, else return false
  152. ' */
  153. function Rooibos_Common_isNumber(value) as boolean
  154. return Rooibos_Common_isLongInteger(value) or Rooibos_Common_isDouble(value) or Rooibos_Common_isInteger(value) or Rooibos_Common_isFloat(value)
  155. end function
  156. ' /**
  157. ' * @name IsList
  158. ' * @function
  159. ' * @description check if value contains List interface
  160. ' * @memberof module:CommonUtils
  161. ' * @param {Dynamic} value - value to check
  162. ' * @returns {Boolean} - true if value contains List interface, else return false
  163. ' */
  164. function Rooibos_Common_isList(value) as boolean
  165. return Rooibos_Common_isValid(value) and GetInterface(value, "ifList") <> invalid
  166. end function
  167. ' /**
  168. ' * @name IsArray
  169. ' * @function
  170. ' * @description check if value contains Array interface
  171. ' * @memberof module:CommonUtils
  172. ' * @param {Dynamic} value - value to check
  173. ' * @returns {Boolean} - true if value contains Array interface, else return false
  174. ' */
  175. function Rooibos_Common_isArray(value) as boolean
  176. return Rooibos_Common_isValid(value) and GetInterface(value, "ifArray") <> invalid
  177. end function
  178. ' /**
  179. ' * @name IsAssociativeArray
  180. ' * @function
  181. ' * @description check if value contains AssociativeArray interface
  182. ' * @memberof module:CommonUtils
  183. ' * @param {Dynamic} value - value to check
  184. ' * @returns {Boolean} - true if value contains AssociativeArray interface, else return false
  185. ' */
  186. function Rooibos_Common_isAssociativeArray(value) as boolean
  187. return Rooibos_Common_isValid(value) and GetInterface(value, "ifAssociativeArray") <> invalid
  188. end function
  189. ' /**
  190. ' * @name IsSGNode
  191. ' * @function
  192. ' * @description check if value contains SGNodeChildren interface
  193. ' * @memberof module:CommonUtils
  194. ' * @param {Dynamic} value - value to check
  195. ' * @returns {Boolean} - true if value contains SGNodeChildren interface, else return false
  196. ' */
  197. function Rooibos_Common_isSGNode(value) as boolean
  198. return Rooibos_Common_isValid(value) and GetInterface(value, "ifSGNodeChildren") <> invalid
  199. end function
  200. ' /**
  201. ' * @name IsString
  202. ' * @function
  203. ' * @description check if value contains String interface
  204. ' * @memberof module:CommonUtils
  205. ' * @param {Dynamic} value - value to check
  206. ' * @returns {Boolean} - true if value contains String interface, else return false
  207. ' */
  208. function Rooibos_Common_isString(value) as boolean
  209. return Rooibos_Common_isValid(value) and GetInterface(value, "ifString") <> invalid
  210. end function
  211. ' /**
  212. ' * @name IsNotEmptyString
  213. ' * @function
  214. ' * @description check if value contains String interface and length more 0
  215. ' * @memberof module:CommonUtils
  216. ' * @param {Dynamic} value - value to check
  217. ' * @returns {Boolean} - true if value contains String interface and length more 0, else return false
  218. ' */
  219. function Rooibos_Common_isNotEmptyString(value) as boolean
  220. return Rooibos_Common_isString(value) and len(value) > 0
  221. end function
  222. ' /**
  223. ' * @name IsDateTime
  224. ' * @function
  225. ' * @description check if value contains DateTime interface
  226. ' * @memberof module:CommonUtils
  227. ' * @param {Dynamic} value - value to check
  228. ' * @returns {Boolean} - true if value contains DateTime interface, else return false
  229. ' */
  230. function Rooibos_Common_isDateTime(value) as boolean
  231. return Rooibos_Common_isValid(value) and (GetInterface(value, "ifDateTime") <> invalid or Type(value) = "roDateTime")
  232. end function
  233. ' /**
  234. ' * @name IsValid
  235. ' * @function
  236. ' * @description check if value initialized and not equal invalid
  237. ' * @memberof module:CommonUtils
  238. ' * @param {Dynamic} value - value to check
  239. ' * @returns {Boolean} - true if value initialized and not equal invalid, else return false
  240. ' */
  241. function Rooibos_Common_isValid(value) as boolean
  242. return not Rooibos_Common_isUndefined(value) and value <> invalid
  243. end function
  244. function Rooibos_Common_isUndefined(value) as boolean
  245. return type(value) = "" or Type(value) = "<uninitialized>"
  246. end function
  247. ' /**
  248. ' * @name ValidStr
  249. ' * @function
  250. ' * @description return value if his contains String interface else return empty string
  251. ' * @memberof module:CommonUtils
  252. ' * @param {Dynamic} value - value to check
  253. ' * @returns {String} - value if his contains String interface else return empty string
  254. ' */
  255. function Rooibos_Common_validStr(obj) as string
  256. if obj <> invalid and GetInterface(obj, "ifString") <> invalid then
  257. return obj
  258. else
  259. return ""
  260. end if
  261. end function
  262. ' /**
  263. ' * @name AsString
  264. ' * @function
  265. ' * @description convert input to String if this possible, else return empty string
  266. ' * @memberof module:CommonUtils
  267. ' * @param {Dynamic} input - value to check
  268. ' * @returns {String} - converted string
  269. ' */
  270. function Rooibos_Common_asString(input) as string
  271. if Rooibos_Common_isValid(input) = false then
  272. return "Invalid"
  273. else if Rooibos_Common_isString(input) then
  274. return input
  275. else if Rooibos_Common_isInteger(input) or Rooibos_Common_isLongInteger(input) or Rooibos_Common_isBoolean(input) then
  276. return input.ToStr()
  277. else if Rooibos_Common_isFloat(input) or Rooibos_Common_isDouble(input) then
  278. return Str(input).Trim()
  279. else if type(input) = "roSGNode" then
  280. return "Node(" + input.subType() + ")"
  281. else if type(input) = "roAssociativeArray" then
  282. isFirst = true
  283. text = "{"
  284. if (not isFirst) then
  285. text = text + ","
  286. isFirst = false
  287. end if
  288. for each key in input
  289. if key <> "__mocks" and key <> "__stubs" then
  290. text = text + key + ":" + Rooibos_Common_asString(input[key])
  291. end if
  292. end for
  293. text = text + "}"
  294. return text
  295. else if Rooibos_Common_isFunction(input) then
  296. return input.toStr()
  297. else
  298. return ""
  299. end if
  300. end function
  301. ' /**
  302. ' * @name AsInteger
  303. ' * @function
  304. ' * @description convert input to Integer if this possible, else return 0
  305. ' * @memberof module:CommonUtils
  306. ' * @param {Dynamic} input - value to check
  307. ' * @returns {Integer} - converted Integer
  308. ' */
  309. function Rooibos_Common_asInteger(input) as integer
  310. if Rooibos_Common_isValid(input) = false then
  311. return 0
  312. else if Rooibos_Common_isString(input) then
  313. return input.ToInt()
  314. else if Rooibos_Common_isInteger(input) then
  315. return input
  316. else if Rooibos_Common_isFloat(input) or Rooibos_Common_isDouble(input) or Rooibos_Common_isLongInteger(input) then
  317. return Int(input)
  318. else
  319. return 0
  320. end if
  321. end function
  322. ' /**
  323. ' * @name AsLongInteger
  324. ' * @function
  325. ' * @description convert input to LongInteger if this possible, else return 0
  326. ' * @memberof module:CommonUtils
  327. ' * @param {Dynamic} input - value to check
  328. ' * @returns {Integer} - converted LongInteger
  329. ' */
  330. function Rooibos_Common_asLongInteger(input) as longinteger
  331. if Rooibos_Common_isValid(input) = false then
  332. return 0
  333. else if Rooibos_Common_isString(input) then
  334. return Rooibos_Common_asInteger(input)
  335. else if Rooibos_Common_isLongInteger(input) or Rooibos_Common_isFloat(input) or Rooibos_Common_isDouble(input) or Rooibos_Common_isInteger(input) then
  336. return input
  337. else
  338. return 0
  339. end if
  340. end function
  341. ' /**
  342. ' * @name AsFloat
  343. ' * @function
  344. ' * @description convert input to Float if this possible, else return 0.0
  345. ' * @memberof module:CommonUtils
  346. ' * @param {Dynamic} input - value to check
  347. ' * @returns {Float} - converted Float
  348. ' */
  349. function Rooibos_Common_asFloat(input) as float
  350. if Rooibos_Common_isValid(input) = false then
  351. return 0
  352. else if Rooibos_Common_isString(input) then
  353. return input.ToFloat()
  354. else if Rooibos_Common_isInteger(input) then
  355. return (input / 1)
  356. else if Rooibos_Common_isFloat(input) or Rooibos_Common_isDouble(input) or Rooibos_Common_isLongInteger(input) then
  357. return input
  358. else
  359. return 0
  360. end if
  361. end function
  362. ' /**
  363. ' * @name AsDouble
  364. ' * @function
  365. ' * @description convert input to Double if this possible, else return 0.0
  366. ' * @memberof module:CommonUtils
  367. ' * @param {Dynamic} input - value to check
  368. ' * @returns {Float} - converted Double
  369. ' */
  370. function Rooibos_Common_asDouble(input) as double
  371. if Rooibos_Common_isValid(input) = false then
  372. return 0
  373. else if Rooibos_Common_isString(input) then
  374. return Rooibos_Common_asFloat(input)
  375. else if Rooibos_Common_isInteger(input) or Rooibos_Common_isLongInteger(input) or Rooibos_Common_isFloat(input) or Rooibos_Common_isDouble(input) then
  376. return input
  377. else
  378. return 0
  379. end if
  380. end function
  381. ' /**
  382. ' * @name AsBoolean
  383. ' * @function
  384. ' * @description convert input to Boolean if this possible, else return False
  385. ' * @memberof module:CommonUtils
  386. ' * @param {Dynamic} input - value to check
  387. ' * @returns {Boolean} - converted boolean
  388. ' */
  389. function Rooibos_Common_asBoolean(input) as boolean
  390. if Rooibos_Common_isValid(input) = false then
  391. return false
  392. else if Rooibos_Common_isString(input) then
  393. return LCase(input) = "true"
  394. else if Rooibos_Common_isInteger(input) or Rooibos_Common_isFloat(input) then
  395. return input <> 0
  396. else if Rooibos_Common_isBoolean(input) then
  397. return input
  398. else
  399. return false
  400. end if
  401. end function
  402. ' /**
  403. ' * @name AsArray
  404. ' * @function
  405. ' * @description if type of value equals array return value, else return array with one element [value]
  406. ' * @memberof module:CommonUtils
  407. ' * @param {Dynamic} value - value to check
  408. ' * @returns {Array} - converted array
  409. ' */
  410. function Rooibos_Common_asArray(value) as object
  411. if Rooibos_Common_isValid(value) then
  412. if not Rooibos_Common_isArray(value) then
  413. return [
  414. value
  415. ]
  416. else
  417. return value
  418. end if
  419. end if
  420. return []
  421. end function
  422. '=====================
  423. ' Strings
  424. '=====================
  425. ' /**
  426. ' * @name IsNullOrEmpty
  427. ' * @function
  428. ' * @description check if value is invalid or empty
  429. ' * @memberof module:CommonUtils
  430. ' * @param {Dynamic} value - value to check
  431. ' * @returns {Boolean} - true if value is null or empty string, else return false
  432. ' */
  433. function Rooibos_Common_isNullOrEmpty(value) as boolean
  434. if Rooibos_Common_isString(value) then
  435. return Len(value) = 0
  436. else
  437. return not Rooibos_Common_isValid(value)
  438. end if
  439. end function
  440. '=====================
  441. ' Arrays
  442. '=====================
  443. ' /**
  444. ' * @name FindElementIndexInArray
  445. ' * @function
  446. ' * @description find an element index in array
  447. ' * @memberof module:CommonUtils
  448. ' * @param {Dynamic} array - array to search
  449. ' * @param {Dynamic} value - value to check
  450. ' * @param {Dynamic} compareAttribute - attribue to use for comparisons
  451. ' * @param {Boolean} caseSensitive - indicates if comparisons are case sensitive
  452. ' * @returns {Integer} - element index if array contains a value, else return -1
  453. ' */
  454. function Rooibos_Common_findElementIndexInArray(array, value, compareAttribute = invalid, caseSensitive = false) as integer
  455. if Rooibos_Common_isArray(array) then
  456. for i = 0 to Rooibos_Common_asArray(array).Count() - 1
  457. compareValue = array[i]
  458. if compareAttribute <> invalid and Rooibos_Common_isAssociativeArray(compareValue) then
  459. compareValue = compareValue.lookupCI(compareAttribute)
  460. end if
  461. if Rooibos_Common_eqValues(compareValue, value) then
  462. return i
  463. end if
  464. item = array[i]
  465. end for
  466. end if
  467. return - 1
  468. end function
  469. ' /**
  470. ' * @name ArrayContains
  471. ' * @function
  472. ' * @description check if array contains specified value
  473. ' * @memberof module:CommonUtils
  474. ' * @param {Dynamic} array - array to search in
  475. ' * @param {Dynamic} value - value to check
  476. ' * @param {Dynamic} compareAttribute - attribute to compare on
  477. ' * @returns {Boolean} - true if array contains a value, else return false
  478. ' */
  479. function Rooibos_Common_arrayContains(array, value, compareAttribute = invalid) as boolean
  480. return (Rooibos_Common_findElementIndexInArray(array, value, compareAttribute) > - 1)
  481. end function
  482. '=====================
  483. ' NODES
  484. '=====================
  485. ' /**
  486. ' * @name FindElementIndexInNode
  487. ' * @function
  488. ' * @description find an element index in node
  489. ' * @memberof module:CommonUtils
  490. ' * @param {Dynamic} node - node to search in
  491. ' * @param {Dynamic} value - child to search for
  492. ' * @returns {Integer} - element index if node contains a value, else return -1
  493. ' */
  494. function Rooibos_Common_findElementIndexInNode(node, value) as integer
  495. if type(node) = "roSGNode" then
  496. for i = 0 to node.getChildCount() - 1
  497. compareValue = node.getChild(i)
  498. if type(compareValue) = "roSGNode" and compareValue.isSameNode(value) then
  499. return i
  500. end if
  501. end for
  502. end if
  503. return - 1
  504. end function
  505. ' /**
  506. ' * @name NodeContains
  507. ' * @description check if node contains specified child
  508. ' * @memberof module:CommonUtils
  509. ' * @param {Dynamic} node - the node to check on
  510. ' * @param {Dynamic} value - child to look for
  511. ' * @returns {Boolean} - true if node contains a value, else return false
  512. ' */
  513. function Rooibos_Common_nodeContains(node, value) as boolean
  514. return (Rooibos_Common_findElementIndexInNode(node, value) > - 1)
  515. end function
  516. ' /**
  517. ' * @memberof module:CommonUtils
  518. ' * @name EqValues
  519. ' * @function
  520. ' * @instance
  521. ' * @description Compare two arbtrary values to eachother.
  522. ' * @param {Dynamic} Vallue1 - first item to compare
  523. ' * @param {Dynamic} Vallue2 - second item to compare
  524. ' * @returns {boolean} - True if values are equal or False in other case.
  525. ' */
  526. function Rooibos_Common_eqValues(Value1, Value2) as dynamic
  527. ' Workaraund for bug with string boxing, and box everything else
  528. val1Type = type(Value1)
  529. val2Type = type(Value2)
  530. if val1Type = "<uninitialized>" or val2Type = "<uninitialized>" or val1Type = "" or val2Type = "" then
  531. print "ERROR!!!! - undefined value passed"
  532. return false
  533. end if
  534. if val1Type = "roString" or val1Type = "String" then
  535. Value1 = Rooibos_Common_asString(Value1)
  536. else
  537. Value1 = box(Value1)
  538. end if
  539. if val2Type = "roString" or val2Type = "String" then
  540. Value2 = Rooibos_Common_asString(Value2)
  541. else
  542. Value2 = box(Value2)
  543. end if
  544. 'update types after boxing
  545. val1Type = type(Value1)
  546. val2Type = type(Value2)
  547. 'Upcast int to float, if other is float
  548. if val1Type = "roFloat" and val2Type = "roInt" then
  549. Value2 = box(Cdbl(Value2))
  550. else if val2Type = "roFloat" and val1Type = "roInt" then
  551. Value1 = box(Cdbl(Value1))
  552. end if
  553. if val1Type <> val2Type then
  554. return false
  555. else
  556. valtype = val1Type
  557. if valtype = "roList" then
  558. return Rooibos_Common_eqArray(Value1, Value2)
  559. else if valtype = "roAssociativeArray" then
  560. return Rooibos_Common_eqAssocArray(Value1, Value2)
  561. else if valtype = "roArray" then
  562. return Rooibos_Common_eqArray(Value1, Value2)
  563. else if (valtype = "roSGNode") then
  564. if (val2Type <> "roSGNode") then
  565. return false
  566. else
  567. return Value1.isSameNode(Value2)
  568. end if
  569. else 'If you crashed on this line, then you're trying to compare
  570. '2 things which can't be compared - check what value1 and value2
  571. 'are in your debug log
  572. return Value1 = Value2
  573. end if
  574. end if
  575. end function
  576. ' /**
  577. ' * @memberof module:CommonUtils
  578. ' * @name EqAssocArray
  579. ' * @function
  580. ' * @instance
  581. ' * @description Compare to roAssociativeArray objects for equality.
  582. ' * @param {Dynamic} Vallue1 - first associative array
  583. ' * @param {Dynamic} Vallue2 - second associative array
  584. ' * @returns {boolean} - True if arrays are equal or False in other case.
  585. ' */
  586. function Rooibos_Common_eqAssocArray(Value1, Value2) as dynamic
  587. l1 = Value1.Count()
  588. l2 = Value2.Count()
  589. if not l1 = l2 then
  590. return false
  591. else
  592. for each k in Value1
  593. if k <> "__mocks" and k <> "__stubs" then 'fix infinite loop/box crash when doing equals on an aa with a mock
  594. if not Value2.DoesExist(k) then
  595. return false
  596. else
  597. v1 = Value1[k]
  598. v2 = Value2[k]
  599. if not Rooibos_Common_eqValues(v1, v2) then
  600. return false
  601. end if
  602. end if
  603. end if
  604. end for
  605. return true
  606. end if
  607. end function
  608. ' /**
  609. ' * @memberof module:CommonUtils
  610. ' * @name EqArray
  611. ' * @function
  612. ' * @instance
  613. ' * @description Compare to roArray objects for equality.
  614. ' * @param {Dynamic} Vallue1 - first array
  615. ' * @param {Dynamic} Vallue2 - second array
  616. ' * @returns {boolean} - True if arrays are equal or False in other case.
  617. ' */
  618. function Rooibos_Common_eqArray(Value1, Value2) as dynamic
  619. if not (Rooibos_Common_isArray(Value1)) or not Rooibos_Common_isArray(Value2) then
  620. return false
  621. end if
  622. l1 = Value1.Count()
  623. l2 = Value2.Count()
  624. if not l1 = l2 then
  625. return false
  626. else
  627. for i = 0 to l1 - 1
  628. v1 = Value1[i]
  629. v2 = Value2[i]
  630. if not Rooibos_Common_eqValues(v1, v2) then
  631. return false
  632. end if
  633. end for
  634. return true
  635. end if
  636. end function
  637. ' /**
  638. ' * @member fillText
  639. ' * @memberof module:CommonUtils
  640. ' * @instance
  641. ' * @description Fills text with count of fillChars
  642. ' * @param {string} text - text to fill
  643. ' * @param {string} fillChar - char to fill with
  644. ' * @param {integer} numChars - target length
  645. ' * @returns {string} filled string
  646. ' */
  647. function Rooibos_Common_fillText(text as string, fillChar = " ", numChars = 40) as string
  648. if (len(text) >= numChars) then
  649. text = left(text, numChars - 5) + "..." + fillChar + fillChar
  650. else
  651. numToFill = numChars - len(text) - 1
  652. for i = 0 to numToFill
  653. text = text + fillChar
  654. end for
  655. end if
  656. return text
  657. end function
  658. 'Static, becuase the result might be created across node boundaries, therefore stripping methods
  659. function Rooibos_Common_getAssertLine(testCase, index)
  660. if (testCase.assertLineNumberMap.doesExist(stri(index).trim())) then
  661. return testCase.assertLineNumberMap[stri(index).trim()]
  662. else if (testCase.assertLineNumberMap.doesExist(stri(index + 1000).trim())) then 'this is where we store line numbers for our
  663. return testCase.assertLineNumberMap[stri(index + 1000).trim()]
  664. return testCase.lineNumber
  665. end if
  666. end function