Skip to content

Instantly share code, notes, and snippets.

@adamcameron
adamcameron / trim.cfm
Created October 29, 2013 12:18
Demonstrates trim trims CF/LR chars
<cfscript>
CR = chr(13);
LF = chr(10);
CRLF = CR&LF;
for (LB in [CR,LF,CRLF,LF & CR & LF]){
original = "#LB#front text#LB#back text#LB#";
trimmed = trim(original);
writeDump(var=[urlEncodedFormat(original), urlEncodedFormat(trimmed)]);
}
@adamcameron
adamcameron / runTests.cfm
Created November 17, 2013 15:02
Code wot runs my tests
<!--- runTests.cfm --->
<cfoutput>
#new mxunit.runner.DirectoryTestSuite().run(
directory = getDirectoryFromPath(getCurrentTemplatePath())
).getResultsOutput("html")#
</cfoutput>
@adamcameron
adamcameron / CustomAssertions.cfc
Created November 21, 2013 14:49
The initial state of my unit test code as at 2013-11-21
// Test.cfc
component extends="mxunit.framework.TestCase" {
public void function beforeTests(){
addAssertDecorator("CustomAssertions");
include "./function.cfm";
}
public void function setup(){
variables.eventObject = createEventObject();
@adamcameron
adamcameron / CustomAssertions.cfc
Created December 1, 2013 14:54
Code for article "Unit Testing / TDD - passing data to on() and trigger()"
// CustomAssertions.cfc
component {
public void function assertStructKeysCorrect(required string keys, required struct struct, string message){
var assertionArgs = {
expected = listSort(keys, "textnocase"),
actual = listSort(structKeyList(struct), "textnocase")
};
if (structKeyExists(arguments, "message")){
assertionArgs.message = message;
@adamcameron
adamcameron / testRig.cfm
Last active December 31, 2015 03:18
See
<cfscript>
testNumbers = [
"0", "0.0", "0.00", "0.000", "0.001",
"0.1", "0.10", "0.100", "0.101",
"0.11", "0.110", "0.111"
];
function formatter(n){
var formattedN = n;
@adamcameron
adamcameron / Junk.cfc
Created December 12, 2013 15:50
Demonstrating that curly brace thing. The code below outputs: in component Hello calling code Hello If it was using closure, it would continue to say "in component". HTH
component {
variables.where = "in component";
{
public function hello() {
writeOutput(variables.where & "<br>");
return "Hello<br>";
}
@adamcameron
adamcameron / Application.cfc
Created December 24, 2013 09:44
Demonstrating issue with makePublic()
// Application.cfc
component {
this.mappings = {
"/testbox" = expandPath("/frameworks/testbox/"),
"/mxunit" = expandPath("/frameworks/testbox/system/testing/compat"),
"/unittests" = expandPath("/shared/git/blogExamples/unittests")
};
}
@adamcameron
adamcameron / Application.cfc
Last active January 1, 2016 07:19
Demonstrating different between an erroring beforeTests() and an erroring setup()
// Application.cfc
component {
this.mappings = {
"/testbox" = expandPath("/frameworks/testbox/"),
"/mxunit" = expandPath("/frameworks/testbox/system/testing/compat"),
"/unittests" = expandPath("/shared/git/blogExamples/unittests")
};
}
@adamcameron
adamcameron / Application.cfc
Created January 3, 2014 14:16
Code for Railo Group post
// Application.cfc
component {
this.name = "testRest06";
function onApplicationStart(){
writeLog(file=this.name, text="#getFunctionCalledName()#() called");
}
function onApplicationEnd(){
@adamcameron
adamcameron / output.txt
Last active January 2, 2016 05:09
Demonstration of bug in CF10's file looping
cffileRead: [abcdefghijklmnopqrstuvwxy*()__+[]\{}|;':",./<>?]
cfloopRead: [abcdefghijklmnopqrstuvwxy*()__+[]\{}|;':",./<>?]
EQ: NO
compare: -1
len: cffileRead: 47; cfloopRead: 48
i char from cffileRead char from cfloopRead
1 a (97)  (65279)
2 b (98) a (97)