text stringlengths 0 15.7k | source stringlengths 6 112 |
|---|---|
if (count {expectedValue, actualValue} each integer) = 2 then return expectedValue = actualValue | lns3.scpt |
if (count {expectedValue, actualValue} each checkType) ≠ 2 then return false | lns3.scpt |
set {n1, n2} to {expectedValue as real, actualValue as real} | lns3.scpt |
if n1 = 0 then | lns3.scpt |
set d1 to _isEqualDelta * n2 | lns3.scpt |
set d1 to _isEqualDelta * n1 | lns3.scpt |
set d2 to -d1 | lns3.scpt |
if d1 > d2 then set {d1, d2} to {d2, d1} | lns3.scpt |
set d to n2 - n1 | lns3.scpt |
return d1 < d and d < d2 | lns3.scpt |
end numeric equality check | lns3.scpt |
to numeric range check matching types isSameTypeRequired : (true) | lns3.scpt |
set isSameTypeRequired to _support's asBooleanParameter(isSameTypeRequired, "matching types") | lns3.scpt |
script NumericalRangeCheck | lns3.scpt |
if (count {expectedValue} each list) = 0 or (count expectedValue each number) ≠ 2 or (expectedValue's item 1 > expectedValue's item 2) then error "Invalid expected value (numeric equality check requires two-item list of minimum and maximum numbers)." number -1703 from expectedValue | lns3.scpt |
set {expectedMinimum, expectedMaximum} to expectedValue | lns3.scpt |
if isSameTypeRequired then | lns3.scpt |
if expectedMinimum's class is not expectedMaximum's class then error "Invalid expected value (numeric equality check’s ‘matching types’ parameter requires both numbers to be same type)." number -1703 from expectedValue | lns3.scpt |
set checkType to expectedMinimum's class | lns3.scpt |
if (count {actualValue} each checkType) = 0 then return false | lns3.scpt |
return expectedMinimum ≤ actualValue and actualValue ≤ expectedMaximum | lns3.scpt |
_error("numeric range check", eText, eNumber, eFrom, eTo) | lns3.scpt |
end numeric range check | lns3.scpt |
to exact error check using errorAttributeChecks : {} -- compare two «class ܆ëé» (expected/actual error records) for equality, ignoring any placeholder attributes | lns3.scpt |
set errorAttributeChecks to _support's asRecordParameter(errorAttributeChecks, "using") | lns3.scpt |
set defaultErrorAttributeChecks to {errorMessage:_defaultEqualityCheck, errorNumber:_defaultEqualityCheck, fromValue:_defaultEqualityCheck, toType:_defaultEqualityCheck, partialResult:_defaultEqualityCheck} | lns3.scpt |
set checkObjects to errorAttributeChecks & defaultErrorAttributeChecks | lns3.scpt |
if length of checkObjects ≠ length of defaultErrorAttributeChecks then error "Invalid ‘using’ parameter (record contains one or more unrecognized properties)." number -1703 from errorAttributeChecks -- (note: this doesn't bother to check each property's type or that each object has a ‘compareObjects’ handler as any pro... | lns3.scpt |
_error("exact error check", eText, eNumber, eFrom, eTo) | lns3.scpt |
script ExactErrorCheck | lns3.scpt |
to compareObjects(expectedError, actualError) | lns3.scpt |
repeat with aRef in {¬
{expectedError's errorNumber, actualError's errorNumber, errorNumber of checkObjects}, ¬ | lns3.scpt |
{expectedError's errorMessage, actualError's errorMessage, errorMessage of checkObjects}, ¬ | lns3.scpt |
{expectedError's fromValue, actualError's fromValue, fromValue of checkObjects}, ¬ | lns3.scpt |
{expectedError's toType, actualError's toType, toType of checkObjects}, ¬ | lns3.scpt |
{expectedError's partialResult, actualError's partialResult, partialResult of checkObjects} ¬ | lns3.scpt |
set {expectedProperty, actualProperty, checkObject} to contents of aRef | lns3.scpt |
if expectedProperty is not _TestSupport's NoValue then | lns3.scpt |
if checkObject's compareObjects(expectedProperty, actualProperty) is false then return false | lns3.scpt |
end exact error check | lns3.scpt |
property _defaultErrorCheck : exact error check | lns3.scpt |
to _compareAssertResults(checkObject, expectedResult, actualResult, assertName, userNote) | lns3.scpt |
return checkObject's compareObjects(expectedResult, actualResult) | lns3.scpt |
_testReport's addBroken(assertName, "broke due to error in check object", userNote, ¬ | lns3.scpt |
error number _AbortedAssertionError from _AbortedAssertionToken | lns3.scpt |
end _compareAssertResults | lns3.scpt |
to assert test result for actualResult is expectedResult note userNote : ("") using checkObject : (missing value) | lns3.scpt |
if _suiteObject is missing value then error "Cannot use ‘assert test result’ outside of unit tests." number -1708 | lns3.scpt |
set userNote to _support's asTextParameter(userNote, "note") | lns3.scpt |
_testReport's addBroken("assert test result", "received bad parameters", userNote, ¬ | lns3.scpt |
{{"unexpected error", _TestSupport's makeCaughtErrorRecord(eText, eNumber, eFrom, eTo, ePartial)}, {"expected result", expectedResult}}) | lns3.scpt |
set isEqual to _asCheckObjectResult(_compareAssertResults(checkObject, expectedResult, actualResult, "assert test result", userNote)) | lns3.scpt |
set testData to {{"actual result", actualResult}, {"expected result", expectedResult}} | lns3.scpt |
if isEqual then | lns3.scpt |
_testReport's addSuccess("assert test result", userNote, testData) | lns3.scpt |
_testReport's addFailure("assert test result", "received incorrect result", userNote, testData) | lns3.scpt |
end assert test result | lns3.scpt |
to assert test error in callHandlerName : ("") for parameterValue : («class ¡ÑØ!») is expectedError note userNote : ("") using checkObject : (missing value) | lns3.scpt |
if _suiteObject is missing value then error "Cannot use ‘assert test error’ outside of unit tests." number -1708 | lns3.scpt |
set callHandlerName to _support's asTextParameter(callHandlerName, "in") | lns3.scpt |
set expectedError to _support's asRecordParameter(expectedError, "is") | lns3.scpt |
set expectedError to _TestSupport's normalizeExpectedErrorRecord(expectedError) | lns3.scpt |
set checkObject to _asCheckObjectParameter(checkObject, _defaultErrorCheck) | lns3.scpt |
_testReport's addBroken("assert test error", "received bad parameters", userNote, ¬ | lns3.scpt |
if callHandlerName is "" then | lns3.scpt |
set callHandlerName to "call" & (text 5 thru -1 of _testHandlerName) -- if `for` parameter is omitted, automatically call a `call_NAME` handler with the same NAME as the `test_NAME` handler | lns3.scpt |
else if callHandlerName does not start with "call_" then | lns3.scpt |
set callHandlerName to "call_" & callHandlerName | lns3.scpt |
if parameterValue is «class ¡ÑØ!» then | lns3.scpt |
set callObject to _TestSupport's makeCallObject(callHandlerName, 0) | lns3.scpt |
set callObject to _TestSupport's makeCallObject(callHandlerName, 1) | lns3.scpt |
set {actualError, actualResult, isEqual} to {_TestSupport's NoValue, _TestSupport's NoValue, false} -- TO DO: rename isEqual to isSuccess once 'is equal' test code is moved to Check object | lns3.scpt |
set actualResult to callObject's callHandler(_suiteObject, parameterValue) -- note: this may return literal 'no value' due to AS's schlonky design - this will be accounted for below | lns3.scpt |
set actualError to _TestSupport's makeCaughtErrorRecord(eText, eNumber, eFrom, eTo, ePartial) | lns3.scpt |
set isEqual to _asCheckObjectResult(_compareAssertResults(checkObject, expectedError, actualError, "assert test error", userNote)) | lns3.scpt |
if isEqual then -- success | lns3.scpt |
_testReport's addSuccess("assert test error", userNote, {{"actual error", actualError}, {"expected error", expectedError}}) | lns3.scpt |
else -- raised wrong error or didn't raise an error | lns3.scpt |
try -- kludge-around for AS's dumb commands-are-not-expressions-so-do-not-have-to-return-results design | lns3.scpt |
set actualResult to actualResult -- this variable lookup fails if call_NAME returned nothing (i.e. `null`, which AS literally treats as 'no value at all')... | lns3.scpt |
set actualResult to _TestSupport's NoValue -- ... in which case replace it with a 'no value placeholder' object that AS can actually see | lns3.scpt |
if actualError is not _TestSupport's NoValue then set {problemType, testData} to {"received incorrect error", {{"actual error", actualError}, {"expected error", expectedError}}} | lns3.scpt |
if actualResult is not _TestSupport's NoValue then set {problemType, testData} to {"received no error", {{"unexpected result", actualResult}, {"expected error", expectedError}}} | lns3.scpt |
_testReport's addFailure("assert test error", problemType, userNote, testData) | lns3.scpt |
end assert test error | lns3.scpt |
to _genericAssert(assertName, didSucceed, actualResult, userNote) | lns3.scpt |
if _suiteObject is missing value then error "Cannot use ‘" & assertName & "’ outside of unit tests." number -1708 | lns3.scpt |
_testReport's addBroken(assertName, "received bad parameters", userNote, ¬ | lns3.scpt |
if actualResult is «class ¡ÑØ!» then | lns3.scpt |
set testData to {} | lns3.scpt |
set testData to {{"actual result", actualResult}} | lns3.scpt |
if didSucceed then | lns3.scpt |
_testReport's addSuccess(assertName, userNote, testData) | lns3.scpt |
_testReport's addFailure(assertName, "", userNote, testData) | lns3.scpt |
end _genericAssert | lns3.scpt |
to assert test passed for actualResult : («class ¡ÑØ!») note userNote : ("") -- TO DO: optional param for passing expected result? | lns3.scpt |
_genericAssert("assert test passed", true, actualResult, userNote) | lns3.scpt |
end assert test passed | lns3.scpt |
to assert test failed for actualResult : («class ¡ÑØ!») note userNote : ("") -- TO DO: optional param for passing expected result? | lns3.scpt |
_genericAssert("assert test failed", false, actualResult, userNote) | lns3.scpt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.