Summary: Functions related to unit testing, and displaying example code.
||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.|
||Add some spaces to the right side of the provided string. For the purpose of displaying a series of strings uniformly.|
||Get the provided string with its first character capitalized.|
Functions related to unit testing, and displaying example code.
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_xpctdCrshCode: The code of the expected crash. If defined, a crash (error) is expected, and its code must equal this,
v_xpctdRtrnValuemay not be provided. If not provided, no crash is expected. If neither
s_xpctdCrshCodenor 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_xpctdCrshCodemust 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_ALRTto 'true' , in response to
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_unitTestIDis defined, this is REQUIRED. Otherwise this is ignored.
testCode(s_code, s_xpctdCrshCd, v_xpctdRtrnValue, s_testName, i_unitTestID, b_redispCrash)
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.lengthis greater than
s_tring + [some spaces]However many spaces it takes to make the overall length equal to
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)
___RPLC___ vfjs_doc_footer ___RPLCZ___