Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Last active October 16, 2021 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcameron/23c101f653b3a045614601259b96e03b to your computer and use it in GitHub Desktop.
Save adamcameron/23c101f653b3a045614601259b96e03b to your computer and use it in GitHub Desktop.
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