Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Last active Oct 16, 2021
Embed
What would you like to do?
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
Result: OK
It returns true when the test function is defined as a tag island inline and the expectation is also in the tag island
Result: Expected: [true]; received: []
It returns true when the whole tags island is outside the testing environment, and the test is within the island
Result: OK
It returns true when the whole tags island is outside the testing environment, but the test is outside the island
Result: OK
<cfscript>
// first a quick test rig
function it(text, callback) {
writeOutput("It #text#<br>")
callback()
writeOutput("<hr>")
}
function expect(actual) {
return {
toBe = (expected) => {
var message = actual == expected ? "OK" : "Expected: [#serializeJson(expected)#]; received: [#serializeJson(actual)#]"
writeOutput("Result: #message#")
}
}
}
// now do some tests
it("returns true when the test function is defined as a function statement inline", () => {
function testMeAsStatement(){
return true
}
expect(testMeAsStatement()).toBe(true)
})
it("returns true when the test function is defined as a function expression inline", () => {
var testMeAsStatement = () => {
return true
}
expect(testMeAsStatement()).toBe(true)
})
it("returns true when the test function is defined as a tag island inline", () => {
```
<cffunction name="testMeInLocalIsland">
<cfreturn true>
</cffunction>
```
expect(testMeInLocalIsland()).toBe(true)
})
it("returns true when the test function is defined as a tag island not inline", () => {
expect(testMeInRemoteIsland()).toBe(true)
})
it("returns true when the test function is defined as a tag island inline and the expectation is also in the tag island", () => {
```
<cffunction name="testMeInLocalIslandAlongWithTheExpectation">
<cfreturn true>
</cffunction>
<cfset expect(testMeInLocalIslandAlongWithTheExpectation()).toBe(true)>
```
})
```
<cffunction name="testMeInRemoteIsland">
<cfreturn true>
</cffunction>
```
// outside the test rig environment
```
<cffunction name="testMeOutsideTheTestEnvironment">
<cfreturn true>
</cffunction>
It returns true when the whole tags island is outside the testing environment, and the test is within the island<br>
<cfset result = testMeOutsideTheTestEnvironment()>
<cfset message = result == true ? "OK" : "Expected: [true]; received: [#result#]">
<cfoutput>Result: #message#<hr></cfoutput>
```
```
<cffunction name="testMeOutsideTheTestEnvironment">
<cfreturn true>
</cffunction>
It returns true when the whole tags island is outside the testing environment, but the test is outside the island<br>
```
result = testMeOutsideTheTestEnvironment()
message = result == true ? "OK" : "Expected: [true]; received: [#result#]"
writeOutput("Result: #message#<hr>")
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment