Last active
June 6, 2016 12:55
-
-
Save roryl/08a89aa59430b797cdb4 to your computer and use it in GitHub Desktop.
Local Scopes - Examples showing local scopes in functions
This file contains 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
component { | |
} |
This file contains 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
component { | |
function myFunc(){ | |
var myVar = "foo"; | |
echo(myVar); //outputs "foo" | |
} | |
function otherFunc(){ | |
echo(myVar); //errors for undefined variable | |
} | |
} |
This file contains 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
component { | |
function myFunc(){ | |
var myVar = "foo"; | |
echo(local.myVar); //outputs foo | |
} | |
} |
This file contains 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
component { | |
function myFunc(){ | |
variables.myVar = "foo"; | |
echo(myVar); //outputs "foo" | |
} | |
function otherFunc(){ | |
echo(myVar); //outputs "foo"; | |
echo(variables.myVar); //same as above, outputs "foo" because myVar was in the variables scope which is global to this component | |
} | |
} |
This file contains 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
/** | |
* 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 localScopeTest(){ | |
var test = new component_local(); | |
savecontent variable="out"{ | |
test.myFunc(); | |
} | |
expect(out).toBe("foo"); | |
expect(function(){test.otherfunc()}).toThrow(); | |
} | |
function variablesScopeTest(){ | |
var test = new component_variables(); | |
savecontent variable="out"{ | |
test.myFunc(); | |
} | |
expect(out).toBe("foo"); | |
savecontent variable="out"{ | |
test.otherFunc(); | |
} | |
expect(out).toBe("foofoo"); | |
} | |
function localStructTest(){ | |
var test = new component_local_struct(); | |
savecontent variable="out"{ | |
test.myFunc(); | |
} | |
expect(out).toBe("foo"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment