Skip to content

Instantly share code, notes, and snippets.

@adamcameron
adamcameron / results.out
Last active October 16, 2021 16:36
Some testing of Lucee's tag islands :-|
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
<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")
@adamcameron
adamcameron / test.cfm
Last active September 26, 2021 10:33
TDDing a micro test framework using itself to test itself
<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")
@adamcameron
adamcameron / test.cfm
Created September 25, 2021 18:56
Testing ?.
<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
})
@adamcameron
adamcameron / testFramework.cfm
Last active September 25, 2021 18:27
A tiny test framework for when I'm testing code in trycf.com
<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#")
@adamcameron
adamcameron / Application.cfm
Created September 7, 2021 20:54
Version using Application.cfm and cferror
<cferror template="./outputError.cfm" type="request">
@adamcameron
adamcameron / Application.cfc
Last active September 7, 2021 20:56
Demonstrating onError catching compilation errors
component {
function onError(exception) {
writeOutput("Message: #exception.message#<br>")
writeOutput("Type: #exception.type#<br>")
writeOutput("Detail: #exception.detail#<br>")
abort
}
}
@adamcameron
adamcameron / C2.cfc
Last active August 20, 2021 15:48
Demonstrating one cannot have a static final method in Lucee or ColdFusion
// C2.cfc
component {
public static final string function g() {
return getFunctionCalledName();
}
}
@adamcameron
adamcameron / Base.cfc
Created August 17, 2021 20:40
And even more... this time with a sub class
// Base.cfc
component {
writeOutput("Top of pseudo-constructor of #getMetadata(this).name#<br>")
exit;
writeOutput("Bottom of pseudo-constructor of #getMetadata(this).name#<br>")
function init() {
writeOutput("In #getMetadata(this).name#.#getFunctionCalledName()#<br>")
}
}
@adamcameron
adamcameron / Base.cfc
Created August 17, 2021 20:38
More <cfexit> shenanigans
// Base.cfc
component {
writeOutput("Top of pseudo-constructor of #getMetadata(this).name#<br>")
exit;
writeOutput("Bottom of pseudo-constructor of #getMetadata(this).name#<br>")
function init() {
writeOutput("In #getMetadata(this).name#.#getFunctionCalledName()#<br>")
}
}