Summary: Functions related to unit testing, and displaying example code.
Function | Summary |
testCode |
Test the provided(-as-a-string) code, and give a descriptive error message when things don't go the way you planned. Sometimes, things just don't go the way we planned. |
getPadded |
Add some spaces to the right side of the provided string. For the purpose of displaying a series of strings uniformly. |
getInitCap |
Get the provided string with its first character capitalized. |
test_and_xmpl.js
: OverviewFunctions related to unit testing, and displaying example code.
test_and_xmpl
.testCode()
Test the provided(-as-a-string) code, and give a descriptive error message when things don't go the way you planned. Sometimes, things just don't go the way we planned.
This function is useful and flexible, as long as you use utility.crsh()
to exit your code, in the case of a fatal error.
s_code
: The code to test. REQUIRED and must be valid JavaScript (otherwise this function will behave unpredictably).s_xpctdCrshCode
: The code of the expected crash. If defined, a crash (error) is expected, and its code must equal this, v_xpctdRtrnValue
may not be provided. If not provided, no crash is expected. If neither s_xpctdCrshCode
nor this parameter are provided, then the code is expected to do nothing (not return anything or crash, just do nothing).v_xpctdRtrnValue
: The expected value that the provided code is expected to return. If defined, s_xpctdCrshCode
must be undefined. If undefined, no return value is expected. If both code and this parameter are undefined, then the code is expected to do nothing. Note that when this is the exact expected value. If you expect a more complicated object than a primitive value (int, string, boolean, ...), or a long value, consider checking that value outside this function. This function only checks for exact equality.s_testName
: The name of the test. REQUIRED.i_unitTestID
: The id of this test, for display purposes only. If this is just a demonstration (not a single test within a set of unit tests), then provide this as undefined.
When defined, the only condition under which something is displayed, is when an unexpected behavior occurs. For example, you expect a crash of code 'xxx', but the function does nothing, then an "error dialog" is provided with the test name, unit test id, expected behavior ("crash code of 'xxx'"), actual behavior ('*nothing* happened'), and the provided code snippet.
When undefined, the code (along with the test name and unit id) is displayed ('about to test this code...'), followed by one of the 'success dialogs':
[utility.]bCRSH_ALRT
to 'true' , in response to i_unitTestID
being defined.No matter what, if the actual behavior is not the expected behavior, the 'error dialog' is provided in place of the 'success dialog'.
b_redispCrash
: If 'true', then redisplay the crash message, immediately after the standard crsh() dialog. This is triggered naturally, by setting [utility.]bCRSH_DGNSTCS
.to 'true' (see the top of utility.js). When i_unitTestID
is defined, this is REQUIRED. Otherwise this is ignored.
testCode(s_code, s_xpctdCrshCd, v_xpctdRtrnValue, s_testName, i_unitTestID, b_redispCrash)
test_and_xmpl
.getPadded()
Add some spaces to the right side of the provided string. For the purpose of displaying a series of strings uniformly.
s_tring
: The string to pad. If not provided then is considered to be ' ' (a single space).i_padLength
: The desired length to pad to. REQUIRED and must be an integer greater than or equal to zero.s_tring
if s_tring.length
is greater than i_padLength
.s_tring + [some spaces]
However many spaces it takes to make the overall length equal to i_padLength
.getPadded(s_tring, i_padLength)
test_and_xmpl
.getInitCap()
Get the provided string with its first character capitalized.
s_tring
: The string whose first character should be capitalized. REQUIRED and may not be less than two characters in length.s_tring.substring(0, 1).toUpperCase() + s_tring.substring(1, s_tring.length)
getInitCap(s_tring)
___RPLC___ vfjs_doc_footer ___RPLCZ___