-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAssert.brs
63 lines (50 loc) · 1.48 KB
/
Assert.brs
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
' Assertion logic.
' @class
function Assert() as Object
prototype = {}
' Asserts if two values are deeply equal whatever its type might be.
' @param {Dynamic} valueA
' @param {Dynamic} valueB
' @returns {Boolean}
prototype.deepEqual = function (valueA as Dynamic, valueB as Dynamic) as Boolean
if (Type(Box(valueA), 3) <> Type(Box(valueB), 3))
return false
end if
valuesType = Type(valueA)
if (valuesType = "roSGNode")
return (valueA.isSameNode(valueB))
end if
if (valuesType = "roArray")
return m._areArraysDeeplyEqual(valueA, valueB)
end if
if (valuesType = "roAssociativeArray")
return m._areAssocArraysDeeplyEqual(valueA, valueB)
end if
return (valueA = valueB)
end function
' @private
prototype._areArraysDeeplyEqual = function (arrayA as Object, arrayB as Object) as Boolean
if (arrayA.count() <> arrayB.count())
return false
end if
for i = 0 to arrayA.count() - 1
if (NOT m.deepEqual(arrayA[i], arrayB[i]))
return false
end if
end for
return true
end function
' @private
prototype._areAssocArraysDeeplyEqual = function (assocArrayA as Object, assocArrayB as Object) as Boolean
if (assocArrayA.count() <> assocArrayB.count())
return false
end if
for each key in assocArrayA
if (NOT m.deepEqual(assocArrayA[key], assocArrayB[key]))
return false
end if
end for
return true
end function
return prototype
end function