This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // test/unit/services/SecurityFilterService | |
| describe("Tests for SecurityFilterService", () => { | |
| describe("Tests for isAuthorised", () => { | |
| it("will reject a user that is not authorised to access the resource", () => { | |
| service = new SecurityFilterSerivce() // might need mocked dependencies | |
| result = service.isAuthorised("juniorUser", "/email/approve-copy", "patch") | |
| expect result.toBeFalse() | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <cfscript> | |
| // implementation | |
| void function describe(required string label, required function testGroup) { | |
| try { | |
| writeOutput("#label#<br>") | |
| testGroup() | |
| } catch (any e) { | |
| writeOutput("Error: #e.message#<br>") | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <cfscript> | |
| function run() { | |
| describe("some tests", () => { | |
| it("a passing test", () => { | |
| expect(true).toBe(true) | |
| }) | |
| it("a failing test", () => { | |
| expect(true).toBe(false) | |
| }) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <style> | |
| .tinyTest {background-color: black; color:white; font-family:monospace} | |
| .tinyTest div {margin-left: 1em} | |
| .tinyTest .pass {color:green;} | |
| .tinyTest .fail {color:red;} | |
| .tinyTest .error {background-color:red; color:black} | |
| </style> | |
| <cfscript> | |
| tinyTest = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function haystackContainsNeedle($haystack, $needle) { | |
| $intersection = array_intersect_assoc($haystack, $needle); | |
| return $intersection == $needle ? 'true' : 'false'; | |
| } | |
| $haystack = [ | |
| "firstName" => "Adam", | |
| "lastName" => "Cameron", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| It returns true when the test function is defined as a function statement inline | |
| Result: OK | |
| It returns true when the test function is defined as a function expression inline | |
| Result: OK | |
| It returns true when the test function is defined as a tag island inline | |
| Result: Expected: [true]; received: [] | |
| It returns true when the test function is defined as a tag island not inline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <cfscript> | |
| function function createIdSequence(required string prefix){ | |
| var counters[prefix] = counters[prefix] ?: 1 | |
| var generators[prefix] = generators[prefix] ?: () => prefix & counters[prefix]++ | |
| return generators[prefix] | |
| } | |
| getNewSubscriptionID = createIdSequence("SUB") | |
| getNewMandateID = createIdSequence("MND") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <cfscript> | |
| runTest("it uses a function called runTest", ()=>{}) | |
| savecontent variable="testOutput" { | |
| runTest("runTest requires and displays a passed-in message describing the test, followed by a line break", ()=>{}) | |
| } | |
| writeOutput(testOutput) | |
| if (testOutput != "runTest requires and displays a passed-in message describing the test, followed by a line break<br>") { | |
| throw(type="AssertionException", message="runTest did not output the message and line break") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <cfscript> | |
| runTest("default struct deferencing works the same as with dot operator", () => { | |
| var st = {key="value"} | |
| assertEqual(st.key, st?.key) | |
| }) | |
| runTest("null left-hand operand does error with . operator", () => { | |
| assertException(() => { | |
| var result = st.key | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <cfscript> | |
| function runTest(required string label, required function testCase) { | |
| try { | |
| writeOutput("#label#: ") | |
| testCase() | |
| writeOutput("OK") | |
| } catch("AssertionException" e) { | |
| writeOutput("Failure: #e.message#") | |
| } catch(any e) { | |
| writeOutput("Error: #e.message#") |