Skip to content

Instantly share code, notes, and snippets.

@roryl
Last active June 6, 2016 12:56
Show Gist options
  • Save roryl/19296468d648117f1fb2 to your computer and use it in GitHub Desktop.
Save roryl/19296468d648117f1fb2 to your computer and use it in GitHub Desktop.
Lucee Struct Examples
[submodule "database_session_storage"]
path = database_session_storage
url = https://gist.github.com/roryl/44f730ecd8ba2593b03e45f1189fcf5f
<cfscript>
myStruct = {foo:"one", bar:"two", baz:"three"};
myStruct.insert("key", "value"); //struct now look like {foo:"one", bar:"two", baz:"three", key:"value"};
</cfscript>
<cfscript>
myStruct = {foo:"one", bar:"two", baz:"three"};
echo(myStruct["foo"]); //outputs "one"
</cfscript>
<cfscript>
myStruct = {foo:"one", bar:"two", baz:"three"};
</cfscript>
<cfscript>
myStruct = {};
</cfscript>
<cfscript>
myStruct = {foo:"one",
bar:"two",
baz:{
key:"value"
}
};
</cfscript>
<cfscript>
myStruct = structNew("ordered");
myStruct.insert("foo","one");
myStruct.insert("bar","two");
myStruct.insert("baz","three");
</cfscript>
<cfscript>
myStruct = {foo:"one", bar:"two", baz:"three"};
dump(myStruct);
</cfscript>
<cfscript>
myStruct = {"foo":"one", "bar":"two", "baz":"three"};
dump(myStruct);
</cfscript>
<cfscript>
myStruct = {foo:"one", bar:"two", baz:"three"};
myKey = "foo";
echo(myStruct[myKey]); //outputs "one"
</cfscript>
<cfscript>
myStruct = {foo:"one", bar:"two", baz:"three"};
myStruct.each(function(key, value, structure){
echo(key); //outputs "foo" then "bar" then "baz";
echo(value); //outputs "one", then "two", then "three"
dump(structure) ; //A reference to the whole structure
});
</cfscript>
<cfscript>
myStruct = {foo:"one", bar:"two", baz:"three"};
for(key in myStruct){
echo(key); //outputs "foo" then "bar" then "baz";
echo(myStruct[key]); //outputs "one", then "two", then "three"
}
</cfscript>
<cfscript>
myStruct = {foo:"one", bar:"two", baz:"three"};
echo(myStruct.foo); //outputs "one"
</cfscript>
/**
* My xUnit Test
*/
component extends="testbox.system.BaseSpec"{
/*********************************** LIFE CYCLE Methods ***********************************/
// executes before all test cases
function beforeTests(){
}
// executes after all test cases
function afterTests(){
}
// executes before every test case
function setup( currentMethod ){
}
// executes after every test case
function teardown( currentMethod ){
}
/*********************************** TEST CASES BELOW ***********************************/
// Remember that test cases MUST start or end with the keyword 'test'
function checkAllSyntaxTest(){
var files = directoryList("");
for(file IN files){
if(file CONTAINS ".cfm"){
include template="#getFileFromPath(file)#";
writeDump(file);
writeDump(myStruct);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment